Advertisement
cr1901

NetBSD Driver Template?

Jun 23rd, 2014
298
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 5.65 KB | None | 0 0
  1. /*  $NetBSD: pcd.c,v 0.01 2014/06/23 05:20:28 wjones Exp $  */
  2.  
  3. /*
  4.  * Copyright (c) 2014 William D. Jones.  All rights reserved.
  5.  *
  6.  * Redistribution and use in source and binary forms, with or without
  7.  * modification, are permitted provided that the following conditions
  8.  * are met:
  9.  * 1. Redistributions of source code must retain the above copyright
  10.  *    notice, this list of conditions and the following disclaimer.
  11.  * 2. Redistributions in binary form must reproduce the above copyright
  12.  *    notice, this list of conditions and the following disclaimer in the
  13.  *    documentation and/or other materials provided with the distribution.
  14.  * 3. All advertising materials mentioning features or use of this software
  15.  *    must display the following acknowledgement:
  16.  *  This product includes software developed by Charles M. Hannum.
  17.  * 4. The name of the author may not be used to endorse or promote products
  18.  *    derived from this software without specific prior written permission.
  19.  *
  20.  * Copyright 2014 by William D. Jones (data part)
  21.  * All rights reserved.
  22.  *
  23.  * Redistribution and use in source and binary forms, with or without
  24.  * modification, are permitted provided that the following conditions
  25.  * are met:
  26.  * 1. Redistributions of source code must retain the above copyright
  27.  *    notice, this list of conditions and the following disclaimer.
  28.  * 2. Redistributions in binary form must reproduce the above copyright
  29.  *    notice, this list of conditions and the following disclaimer in the
  30.  *    documentation and/or other materials provided with the distribution.
  31.  * 3. All advertising materials mentioning features or use of this software
  32.  *    must display the following acknowledgement:
  33.  *  This software was developed by Holger Veit and Brian Moore
  34.  *      for use with "386BSD" and similar operating systems.
  35.  *    "Similar operating systems" includes mainly non-profit oriented
  36.  *    systems for research and education, including but not restricted to
  37.  *    "NetBSD", "FreeBSD", "Mach" (by CMU).
  38.  * 4. Neither the name of the developer(s) nor the name "386BSD"
  39.  *    may be used to endorse or promote products derived from this
  40.  *    software without specific prior written permission.
  41.  *
  42.  * THIS SOFTWARE IS PROVIDED BY THE DEVELOPER(S) ``AS IS'' AND ANY
  43.  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  44.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  45.  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE DEVELOPER(S) BE
  46.  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
  47.  * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
  48.  * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
  49.  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  50.  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  51.  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  52.  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  53.  */
  54.  
  55. #include <sys/cdefs.h>
  56. __KERNEL_RCSID(0, "$NetBSD: pcd.c,v 0.9 2014/06/23 05:20:28 wjones Exp $");
  57.  
  58. #include <sys/param.h>
  59. #include <sys/systm.h>
  60. #include <sys/kernel.h>
  61. #include <sys/errno.h>
  62. #include <sys/device.h>
  63. #include <sys/malloc.h>
  64. #include <sys/uio.h>
  65. #include <sys/proc.h>
  66. #include <sys/ioctl.h>
  67. #include <sys/conf.h>
  68.  
  69. #include <sys/bus.h>
  70.  
  71.  
  72. static int pcd_match(device_t parent, cfdata_t match, void *aux);
  73. static void pcd_attach(device_t parent, device_t self, void *aux);
  74. static int pcd_activate(device_t self, enum devact act);
  75.  
  76. struct pcd_softc {
  77.              device_t sc_dev;                /* generic device info */
  78.              /* device-specific state */
  79. };
  80.  
  81. //CFATTACH_DECL does not work, per ftp://ftp.netbsd.org/pub/NetBSD/misc/ddwg/NetBSD-driver_writing-1.0.1e.pdf
  82. CFATTACH_DECL_NEW(pcd, sizeof(struct pcd_softc), pcd_match, pcd_attach, NULL, pcd_activate);
  83.  
  84. dev_type_open(pcdopen);
  85. dev_type_close(pcdclose);
  86. dev_type_read(pcdread);
  87. dev_type_write(pcdwrite);
  88. dev_type_ioctl(pcdioctl);
  89. dev_type_strategy(pcdstrategy);
  90. dev_type_dump(pcddump);
  91. dev_type_size(pcdsize);      
  92.  
  93. //Need to include more than just the 3 header files that driver(9) specifies.
  94. const struct bdevsw pcd_bdevsw = {
  95.     .d_open = pcdopen,
  96.     .d_close = pcdclose,
  97.     .d_strategy = pcdstrategy,
  98.     .d_ioctl = pcdioctl,
  99.     .d_dump = pcddump,
  100.     .d_psize = pcdsize,
  101.     .d_flag = D_DISK
  102. };
  103.  
  104. const struct cdevsw pcd_cdevsw = {
  105.     .d_open = pcdopen,
  106.     .d_close = pcdclose,
  107.     .d_read = pcdread,
  108.     .d_write = pcdwrite,
  109.     .d_ioctl = pcdioctl,
  110.     .d_stop = nostop,
  111.     .d_tty = notty,
  112.     .d_poll = nopoll,
  113.     .d_mmap = nommap,
  114.     .d_kqfilter = nokqfilter,
  115.     .d_flag = D_DISK
  116. };
  117.  
  118. /* driver(9) says return EOPNOTSUPP if activation is not supported. */
  119. int
  120. pcd_activate(device_t self, enum devact act)
  121. {
  122.     return EOPNOTSUPP;
  123. }
  124.  
  125. int
  126. pcd_match(device_t parent, cfdata_t match, void *aux)
  127. {
  128.     return 0;
  129. }
  130.  
  131. void
  132. pcd_attach(device_t parent, device_t self, void *aux)
  133. {
  134.     //struct isa_attach_args *ia = aux;
  135.     return;
  136. }
  137.  
  138.  
  139. /* I can't find the man page which discusses the paramater variable naming
  140. convention, so I'm just using what I see every other driver do! */
  141. int
  142. pcdopen(dev_t dev, int flags, int mode, struct lwp *l)
  143. {
  144.     return 0;
  145. }
  146.  
  147. int
  148. pcdclose(dev_t dev, int flags, int mode, struct lwp *l)
  149. {
  150.     return 0;
  151. }
  152.  
  153. int
  154. pcdread(dev_t dev, struct uio *uio, int flags)
  155. {
  156.     return 0;  
  157. }
  158.  
  159. int
  160. pcdwrite(dev_t dev, struct uio *uio, int flags)
  161. {
  162.     return 0;
  163. }
  164.  
  165. int
  166. pcdioctl(dev_t dev, u_long cmd, void *addr, int flag, struct lwp *l)
  167. {
  168.     return 0;
  169. }
  170.  
  171. void
  172. pcdstrategy(struct buf *bp)
  173. {
  174.     return;
  175. }
  176.  
  177. int
  178. pcddump(dev_t dev, daddr_t blkno, void *va, size_t size)
  179. {
  180.     return 0;
  181. }
  182.  
  183. int
  184. pcdsize(dev_t dev)
  185. {
  186.     return 0;
  187. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement