summaryrefslogtreecommitdiff
path: root/tutorials/drivers
diff options
context:
space:
mode:
Diffstat (limited to 'tutorials/drivers')
-rw-r--r--tutorials/drivers/myossdev0/.config25
-rw-r--r--tutorials/drivers/myossdev0/.devices18
-rw-r--r--tutorials/drivers/myossdev0/.params11
-rw-r--r--tutorials/drivers/myossdev0/README8
-rw-r--r--tutorials/drivers/myossdev0/myossdev.c143
-rw-r--r--tutorials/drivers/myossdev0/myossdev.h39
6 files changed, 244 insertions, 0 deletions
diff --git a/tutorials/drivers/myossdev0/.config b/tutorials/drivers/myossdev0/.config
new file mode 100644
index 0000000..57d63df
--- /dev/null
+++ b/tutorials/drivers/myossdev0/.config
@@ -0,0 +1,25 @@
+#
+# The .config file is optional. All drivers will inherit the config
+# settings of the parent environment. The default device driver settings are
+# suitable for PCI devices that work under any operating system and any
+# processor architecture.
+#
+# Let's assume this sample driver is for a sound chip that is only used
+# on PC motherboards. Since it's known that it will not be present in
+# machines having Sparc or PPC processor it doesn't make any sense to
+# ship the driver in OSS packages for other processor architectures.
+# The platform=i86pc does the trick. i86pc means systems based on the
+# IA32 (AKA x86, i386..i686) architecture and it's 64 bit variants such as
+#x86_64 (AMD64, EMT64).
+#
+platform=i86pc
+#
+#
+# It is also possible to make the driver available only for a given operating
+# system for example if it depends on some kernel services not available
+# anywhere else. This can be done using the targetos keyword. For example
+# targetos=Linux and/or targetos=Solaris.
+#
+# If the driver is known to be incompatible with certain operating system
+# it's possible to exclude it using the forfetos keyword. For example
+# forgetos=Linux.
diff --git a/tutorials/drivers/myossdev0/.devices b/tutorials/drivers/myossdev0/.devices
new file mode 100644
index 0000000..4f21f1c
--- /dev/null
+++ b/tutorials/drivers/myossdev0/.devices
@@ -0,0 +1,18 @@
+#
+# Devices supported by the myossdev driver
+#
+# The lines beginning with '#' in column 1 are comments. Using '#' in any
+# other column is not permitted. Also empty lines are illegal.
+#
+# The pci666,777 entry refers to the primary PCI vendor/device ID with
+# vendor=0x666 and device=0x777. All devices with this ID will be mapped
+# to this driver.
+myossdev pci666,777 Generic Acme Laboratories Evil Audio device
+#
+# PCI subdevice IDs can be used to identify specific models of given device.
+# In most cases this is unnecessary but it makes it possible to show more
+# meaningful device names in possible configuration utilities. For example
+# pcs666,111 means PCI device with subvendor ID of 0x666 and subdevice ID
+# of 111.
+myossdev pcs666,111 Acme Laboratories Evil Audio basic
+myossdev pcs666,999 Acme Laboratories Evil Audio Super Deluxe Turbo
diff --git a/tutorials/drivers/myossdev0/.params b/tutorials/drivers/myossdev0/.params
new file mode 100644
index 0000000..6ee68b3
--- /dev/null
+++ b/tutorials/drivers/myossdev0/.params
@@ -0,0 +1,11 @@
+/*
+ * The initial comment is optional and gives information common to all config
+ * options.
+ */
+int myossdev_verbose = 0;
+/*
+ * Setting myossdev0_verbose to 1 enables various debugging messages
+ * displayed by the driver. This option can be used when debugging problems
+ * with the device.
+ */
+
diff --git a/tutorials/drivers/myossdev0/README b/tutorials/drivers/myossdev0/README
new file mode 100644
index 0000000..69b5c95
--- /dev/null
+++ b/tutorials/drivers/myossdev0/README
@@ -0,0 +1,8 @@
+This is the step 0 of the sample OSS driver project. This driver
+has support for loading/unloading (attach/detach) and nothing else.
+More features will be added in the subsequent steps.
+
+To compile this driver it must be copied to a directory with
+proper name. So you need to create kernel/drv/myossdev (inside the OSS
+source tree) and copy contents of this directory to it. Then follow the
+instructions for compiling and installing OSS.
diff --git a/tutorials/drivers/myossdev0/myossdev.c b/tutorials/drivers/myossdev0/myossdev.c
new file mode 100644
index 0000000..fbe5ce5
--- /dev/null
+++ b/tutorials/drivers/myossdev0/myossdev.c
@@ -0,0 +1,143 @@
+/*
+ * Purpose: Driver for the ACME Laboratories Evil Audio family of sound cards
+ * Description:
+ * This description section contains general information about the driver
+ * and the name and contact information of author and maintainer of the code.
+ *
+ * _NO_ copyright statement must be given in the comments since all drivers
+ * to be included in the OSS source tree must be compatible with the copying
+ * policy of the rest of OSS.
+ */
+
+/*
+ * Create a #define for the copying conditions. This define must be
+ * as above. Only the name of the copyright owner and the year(s) can be
+ * changed. This definition will be replaced by the actual OSS copyright
+ * statement by the build tools.
+ */
+/*
+ *
+ * This file is part of Open Sound System.
+ *
+ * Copyright (C) 4Front Technologies 1996-2008.
+ *
+ * This this source file is released under GPL v2 license (no other versions).
+ * See the COPYING file included in the main directory of this source
+ * distribution for the license terms and conditions.
+ *
+ */
+
+/*
+ * The _cfg.h file for the driver must be included before anything else
+ * by all OS drivers. This configuration file will be automatically generated
+ * based on the configuration files and operating system requirements.
+ */
+#include "myossdev_cfg.h"
+
+/*
+ * If the driver is split to multiple C source files then you should create
+ * a common header file for the driver and include it here.
+ */
+
+#include "myossdev.h"
+
+/*
+ * Drivers for PCI devices need to include <oss_pci.h>. Other drivers should
+ * not include it.
+ */
+#include <oss_pci.h>
+
+
+/*
+ * The attach routine for the device. This routine will be called once for
+ * each device instance found from the system. The osdev parameter is a handle
+ * to the device that will be needed by many subsequent OSS core functions.
+ */
+int
+myossdev_attach (oss_device_t * osdev)
+{
+ myossdev_devc_t *devc;
+
+ /*
+ * Some debugging printout. All OSS drivers must use cmn_err() instead
+ * of printf(), printk() or something else to print debugging and error
+ * messages.
+ *
+ * The cmn_err() call can be oput inside a DDB() macro. In this way the
+ * message will only be printed if OSS was started with detect_trace=1
+ * configuration option.
+ */
+ DDB (cmn_err (CE_CONT, "myossdev_attach called\n"));
+
+ /*
+ * First create the devc structure and initialize it to zeroes.
+ * The PMALLOC macro will allocate memory that will be automatically
+ * released when OSS gets unloaded. This kind of memory should be used
+ * for structures that will stay in use until the driver is unloaded.
+ */
+
+ if ((devc = PMALLOC (osdev, sizeof (*devc))) == NULL)
+ {
+ cmn_err (CE_WARN, "Cannot allocate devc\n");
+ return 0; /* Failure */
+ }
+
+ memset (devc, 0, sizeof (*devc));
+
+ /*
+ * Drivers must initialize osdev to have a link to the devc structure.
+ * Without this link the driver cannot be unloaded.
+ */
+ osdev->devc = devc;
+
+ /*
+ * Init the devc fields and create the mutex. Register the device.
+ */
+
+ devc->osdev = osdev;
+ MUTEX_INIT (devc->osdev, devc->mutex);
+ oss_register_device (osdev, "ACME Labs Evil Audio");
+
+ /*
+ * This is all for now. More will follow in the next episode.
+ */
+
+ return 1; /* Success */
+}
+
+/*
+ * Device detach routine. Note that this routine will be called once for
+ * each instance.
+ */
+
+int
+myossdev_detach (oss_device_t * osdev)
+{
+ myossdev_devc_t *devc = osdev->devc;
+ int err;
+
+ DDB (cmn_err (CE_CONT, "myossdev_detach called\n"));
+
+/*
+ * Check if the device is not busy.
+ */
+ if ((err = oss_disable_device (osdev)) < 0)
+ {
+ cmn_err (CE_WARN, "Cannot detach %s\n", osdev->nick);
+ return 0;
+ }
+
+ /*
+ * Uninitialize the instance variables. Do not try to free any
+ * memory allocated with PMALLOC().
+ */
+
+ MUTEX_CLEANUP (devc->mutex); /* Mutexes must be cleared */
+
+ /*
+ * Finally mark the device as inactive
+ */
+ oss_unregister_device (osdev);
+
+ return 1; /* Ok */
+}
diff --git a/tutorials/drivers/myossdev0/myossdev.h b/tutorials/drivers/myossdev0/myossdev.h
new file mode 100644
index 0000000..8c631fb
--- /dev/null
+++ b/tutorials/drivers/myossdev0/myossdev.h
@@ -0,0 +1,39 @@
+/*
+ * Purpose: Common definitions for the ACME Labs Evil Audio driver.
+ *
+ * The intial comment usually doesn't contain much information.
+ */
+
+/*
+ * As in the C sources you need to include a placeholder define for the
+ * copyright notice. To avoid getting multiple define warnings for the COPYING
+ * macro the header files should use macro name like COPYING2..COPYING9.
+ */
+
+/*
+ *
+ * This file is part of Open Sound System.
+ *
+ * Copyright (C) 4Front Technologies 1996-2008.
+ *
+ * This this source file is released under GPL v2 license (no other versions).
+ * See the COPYING file included in the main directory of this source
+ * distribution for the license terms and conditions.
+ *
+ */
+
+/*
+ * Each device instance should have a per-device data structure that contains
+ * variables common to all sub-devices of the card. By convenntion this
+ * structure is called devc. Driver designers may use different terminology.
+ * However use of devc is highly recomended in all OSS drivers because it
+ * will make maintenance of the code easier.
+ */
+
+typedef struct _myossdev_devc_t *myoss_devc_t;
+
+struct _myossdev_devc_t
+{
+ oss_device_t *osdev; /* A handle to the device given by the OSS core. */
+ oss_mutex_t *mutex; /* A lock/mutex variable for the device */
+};