/*-1* SPDX-License-Identifier: BSD-2-Clause2*3* Copyright (c) 2023 George V. Neville-Neil4*5* Redistribution and use in source and binary forms, with or without6* modification, are permitted provided that the following conditions7* are met:8* 1. Redistributions of source code must retain the above copyright9* notice, this list of conditions and the following disclaimer.10* 2. Redistributions in binary form must reproduce the above copyright11* notice, this list of conditions and the following disclaimer in the12* documentation and/or other materials provided with the distribution.13*14* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND15* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE16* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE17* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE18* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL19* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS20* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)21* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT22* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY23* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF24* SUCH DAMAGE.25*26*/2728/*29* SKEL Loadable Kernel Module for the FreeBSD Operating System30*31* The SKEL module is meant to act as a skeleton for creating new32* kernel modules.33*34* This module can be loaded and unloaded from * FreeBSD and is for35* use in teaching as well.36*37*/3839#include <sys/param.h>40#include <sys/kernel.h>41#include <sys/systm.h>42#include <sys/module.h>4344/*45* Every module can have a module specific piece of code that is46* executed whenever the module is loaded or unloaded. The following47* is a trivial example that prints a message on the console whenever48* the module is loaded or unloaded.49*/5051static int52skel_mod_event(module_t mod, int type, void *data)53{5455switch (type) {56case MOD_LOAD:57printf("SKEL module loading.\n");58return (0);59case MOD_UNLOAD:60printf("SKEL module unloading.\n");61return (0);62}63return (EOPNOTSUPP);64}6566/*67* Modules can have associated data and the module data also contains68* an entry for the function called by the kernel on load and unload.69*/7071static moduledata_t skel_mod = {72"skel",73skel_mod_event,74NULL,75};7677/*78* Each module is declared with its name and module data. The79* ordering arguments at the end put this module into the device80* driver class, which is sufficient for our needs. The complete list81* of modules types and ording can be found in sys/kernel.h82*/8384DECLARE_MODULE(skel, skel_mod, SI_SUB_DRIVERS, SI_ORDER_MIDDLE);85868788