|
|
1.1 root 1: #define _DDI_DKI 1
2: #define _SYSV3 1
3:
4: /*
5: * This file contains supplementary definitions used to deal with or aid the
6: * implementation of the automatically generated device configuration code
7: * in the "conf.c" file.
8: *
9: * Note that we are in the _SYSV3 world because we touch <sys/uproc.h>
10: */
11: /*
12: *-IMPORTS:
13: * <common/ccompat.h>
14: * __USE_PROTO__
15: * __ARGS ()
16: * <common/xdebug.h>
17: * __LOCAL__
18: * <sys/debug.h>
19: * ASSERT ()
20: * <sys/types.h>
21: * cred_t
22: * n_dev_t
23: * o_dev_t
24: * makedevice ()
25: * <sys/cmn_err.h>
26: * CE_PANIC
27: * cmn_err ()
28: * <sys/file.h>
29: * FREAD
30: * FWRITE
31: * FNDELAY
32: * FNONBLOCK
33: * FEXCL
34: * <sys/open.h>
35: * OTYP_BLK
36: * OTYP_CHR
37: * OTYP_LYR
38: * <sys/uio.h>
39: * iovec_t
40: * uio_t
41: * <stddef.h>
42: * NULL
43: * <sys/errno.h>
44: * ENXIO
45: */
46:
47: #include <common/ccompat.h>
48: #include <common/xdebug.h>
49: #include <kernel/strmlib.h>
50: #include <sys/debug.h>
51: #include <sys/types.h>
52: #include <sys/cmn_err.h>
53: #include <sys/file.h>
54: #include <sys/open.h>
55: #include <sys/uio.h>
56: #include <sys/errno.h>
57: #include <stddef.h>
58:
59: #include <kernel/confinfo.h>
60:
61:
62: /*
63: * These are Coherent header files! Treat with all the caution you would
64: * normally use for handling toxic waste!
65: *
66: * <sys/io.h>
67: * IO
68: * <sys/stat.h>
69: * major ()
70: * minor ()
71: * <sys/uproc.h>
72: * u.u_uid
73: * u.u_gid
74: * <sys/con.h>
75: * DFBLK
76: *
77: * The following values which used to be in Coherent <sys/inode.h> have been
78: * moved here so we can use them. <sys/inode.h> is too much of a mess.
79: *
80: * <sys/file.h>
81: * IPR
82: * IPW
83: * IPNDLY
84: * IPEXCL
85: *
86: * Note that the actual magic u area variable 'u' is extern'ed in
87: * <sys/coherent.h>.
88: */
89:
90: #include <sys/io.h>
91: #include <sys/stat.h>
92:
93: #if __COHERENT__
94:
95: #define __KERNEL__ 2
96: #include <sys/uproc.h>
97: #undef __KERNEL__
98:
99: extern UPROC u;
100:
101: #define SETUERROR(e) u.u_error = (e)
102:
103: #else
104:
105: #define SETUERROR(e) ASSERT (e == 0 || "Hit error" == NULL)
106:
107: #endif
108:
109:
110: /*
111: * This function initialises a cred_t structure from Coherent's internal data
112: * structures. This function would normally be local, but it is also called
113: * upon by code in "drv_ddi.c" to implement the drv_getparm () and
114: * drv_setparm () utilities.
115: */
116:
117: #if __USE_PROTO__
118: cred_t * (MAKE_CRED) (cred_t * credp)
119: #else
120: cred_t *
121: MAKE_CRED __ARGS ((credp))
122: cred_t * credp;
123: #endif
124: {
125: credp->cr_ref = 1;
126: credp->cr_ngroups = 0; /* no supplementary groups */
127:
128: #ifdef __MSDOS__
129: credp->cr_uid = credp->cr_ruid = credp->cr_suid = 0;
130: credp->cr_gid = credp->cr_rgid = credp->cr_sgid = 0;
131: #else
132: credp->cr_uid = u.u_uid;
133: credp->cr_gid = u.u_gid;
134: credp->cr_ruid = u.u_ruid;
135: credp->cr_rgid = u.u_rgid;
136: credp->cr_suid = u.u_euid; /* u.u_euid is saved effective uid */
137: credp->cr_sgid = u.u_egid; /* u.u_egid is saved effective gid */
138: #endif
139: return credp;
140: }
141:
142:
143: /*
144: * This local function is called to build a "uio_t" structure from Coherent's
145: * UIO structure.
146: */
147:
148: #if __USE_PROTO__
149: __LOCAL__ uio_t * (MAKE_UIO) (uio_t * uiop, iovec_t * iovp, int mode, IO * iop)
150: #else
151: __LOCAL__ uio_t *
152: MAKE_UIO __ARGS ((uiop, iovp, mode, iop))
153: uio_t * uiop;
154: iovec_t * iovp;
155: int mode;
156: IO * iop;
157: #endif
158: {
159: uiop->uio_iov = iovp;
160: uiop->uio_iovcnt = 1;
161: uiop->uio_offset = iop->io_seek;
162: uiop->uio_segflg = iop->io_seg == IOSYS ? UIO_SYSSPACE : UIO_USERSPACE;
163: uiop->uio_fmode = mode | ((iop->io_flag & IONDLY) != 0 ? FNDELAY : 0);
164: uiop->uio_resid = iop->io_ioc;
165:
166: #ifdef _I386
167: iovp->iov_base = iop->io.vbase;
168: #else
169: iovp->iov_base = iop->io_base;
170: #endif
171: iovp->iov_len = iop->io_ioc;
172:
173: return uiop;
174: }
175:
176:
177: /*
178: * This function is used to copy back the information from a "uio_t" structure
179: * into a Coherent IO structure.
180: */
181:
182: #if __USE_PROTO__
183: __LOCAL__ void (DESTROY_UIO) (uio_t * uiop, IO * iop)
184: #else
185: __LOCAL__ void
186: DESTROY_UIO __ARGS ((uiop, iop))
187: uio_t * uiop;
188: IO * iop;
189: #endif
190: {
191: ASSERT (uiop->uio_iov != NULL);
192: ASSERT (uiop->uio_iov->iov_len == uiop->uio_resid);
193:
194: iop->io_ioc = uiop->uio_resid;
195: iop->io_seek = uiop->uio_offset;
196: #ifdef _I386
197: iop->io.vbase = uiop->uio_iov->iov_base;
198: #else
199: iop->io_base = uiop->uio_iov->iov_base;
200: #endif
201: }
202:
203:
204: /*
205: * This function is called upon by the machine-generated code in "conf.c" to
206: * forward a Coherent device open request to a System V device.
207: */
208:
209: #if __USE_PROTO__
210: int (_forward_open) (o_dev_t dev, int mode, int flags, ddi_open_t funcp)
211: #else
212: int
213: _forward_open __ARGS ((dev, mode, flags, funcp))
214: o_dev_t dev;
215: int mode;
216: int flags;
217: ddi_open_t funcp;
218: #endif
219: {
220: n_dev_t newdev = makedevice (major (dev), minor (dev));
221: cred_t cred;
222: int newmode;
223: int ret;
224:
225: newmode = 0;
226:
227: /*
228: * These are the flags documented by the Coherent driver kit. In
229: * actual fact, there are more (corresponding to the DDI/DKI flags)
230: * that are passed down from the system file table's flag entry. The
231: * fact that the others are not documented probably reflects the fact
232: * that calls to dread () either pass only IPR or IPW directly, while
233: * the existence of the other flags can only be discovered by tracing
234: * many layers of calls.
235: */
236:
237: if ((mode & IPR) != 0)
238: newmode |= FREAD;
239: if ((mode & IPW) != 0)
240: newmode |= FWRITE;
241:
242: /*
243: * And the other flags. There is no equivalent for FNONBLOCK.
244: */
245:
246: if ((mode & IPEXCL) != 0)
247: newmode |= FEXCL;
248: if ((mode & IPNDLY) != 0)
249: newmode |= FNDELAY;
250:
251: flags = (flags & DFBLK) != 0 ? OTYP_BLK : OTYP_CHR;
252:
253: ret = (* funcp) (& newdev, newmode, flags, MAKE_CRED (& cred));
254:
255: SETUERROR (ret);
256: return ret;
257: }
258:
259:
260: /*
261: * This function is called upon by the machine-generated code in "conf.c" to
262: * forward a Coherent device close request to a System V device.
263: */
264:
265: #if __USE_PROTO__
266: int (_forward_close) (o_dev_t dev, int mode, int flags, ddi_close_t funcp)
267: #else
268: int
269: _forward_close __ARGS ((dev, mode, flags, funcp))
270: o_dev_t dev;
271: int mode;
272: int flags;
273: ddi_close_t funcp;
274: #endif
275: {
276: n_dev_t newdev = makedevice (major (dev), minor (dev));
277: cred_t cred;
278: int newmode;
279: int ret;
280:
281: newmode = 0;
282:
283: /*
284: * These are the flags documented by the Coherent driver kit. In
285: * actual fact, there are more (corresponding to the DDI/DKI flags)
286: * that are passed down from the system file table's flag entry. The
287: * fact that the others are not documented probably reflects the fact
288: * that calls to dread () either pass only IPR or IPW directly, while
289: * the existence of the other flags can only be discovered by tracing
290: * many layers of calls.
291: */
292:
293: if ((mode & IPR) != 0)
294: newmode |= FREAD;
295: if ((mode & IPW) != 0)
296: newmode |= FWRITE;
297:
298: /*
299: * And the other flags. There is no equivalent for FNONBLOCK.
300: */
301:
302: if ((mode & IPEXCL) != 0)
303: newmode |= FEXCL;
304: if ((mode & IPNDLY) != 0)
305: newmode |= FNDELAY;
306:
307: flags = (flags & DFBLK) != 0 ? OTYP_BLK : OTYP_CHR;
308:
309: ret = (* funcp) (newdev, newmode, flags, MAKE_CRED (& cred));
310:
311: SETUERROR (ret);
312: return ret;
313: }
314:
315:
316: /*
317: * This function is called upon by the machine-generated code in "conf.c" to
318: * forward a Coherent device read request to a System V device.
319: */
320:
321: #if __USE_PROTO__
322: int (_forward_read) (o_dev_t dev, IO * iop, ddi_read_t funcp)
323: #else
324: int
325: _forward_read __ARGS ((dev, iop, funcp))
326: o_dev_t dev;
327: IO * iop;
328: ddi_read_t funcp;
329: #endif
330: {
331: n_dev_t newdev = makedevice (major (dev), minor (dev));
332: cred_t cred;
333: iovec_t iov;
334: uio_t uio;
335: int ret;
336:
337: ret = (* funcp) (newdev, MAKE_UIO (& uio, & iov, FREAD, iop),
338: MAKE_CRED (& cred));
339: DESTROY_UIO (& uio, iop);
340: SETUERROR (ret);
341: return ret;
342: }
343:
344:
345: /*
346: * This function is called upon by the machine-generated code in "conf.c" to
347: * forward a Coherent device write request to a System V device.
348: */
349:
350: #if __USE_PROTO__
351: int (_forward_write) (o_dev_t dev, IO * iop, ddi_write_t funcp)
352: #else
353: int
354: _forward_write __ARGS ((dev, iop, funcp))
355: o_dev_t dev;
356: IO * iop;
357: ddi_write_t funcp;
358: #endif
359: {
360: n_dev_t newdev = makedevice (major (dev), minor (dev));
361: cred_t cred;
362: iovec_t iov;
363: uio_t uio;
364: int ret;
365:
366: ret = (* funcp) (newdev, MAKE_UIO (& uio, & iov, FWRITE, iop),
367: MAKE_CRED (& cred));
368: DESTROY_UIO (& uio, iop);
369: SETUERROR (ret);
370: return ret;
371: }
372:
373:
374: /*
375: * This function is called upon by the machine-generated code in "conf.c" to
376: * forward a Coherent device ioctl request to a System V device.
377: */
378:
379: #if __USE_PROTO__
380: int (_forward_ioctl) (o_dev_t dev, int cmd, _VOID * arg, int mode,
381: ddi_ioctl_t funcp)
382: #else
383: int
384: _forward_ioctl __ARGS ((dev, cmd, arg, mode, funcp))
385: o_dev_t dev;
386: int cmd;
387: _VOID * arg;
388: int mode;
389: ddi_ioctl_t funcp;
390: #endif
391: {
392: n_dev_t newdev = makedevice (major (dev), minor (dev));
393: cred_t cred;
394: int rval;
395: int newmode;
396: int ret;
397:
398: newmode = 0;
399:
400: /*
401: * These are the flags documented by the Coherent driver kit. In
402: * actual fact, there are more (corresponding to the DDI/DKI flags)
403: * that are passed down from the system file table's flag entry. The
404: * fact that the others are not documented probably reflects the fact
405: * that calls to dread () either pass only IPR or IPW directly, while
406: * the existence of the other flags can only be discovered by tracing
407: * many layers of calls.
408: */
409:
410: if ((mode & IPR) != 0)
411: newmode |= FREAD;
412: if ((mode & IPW) != 0)
413: newmode |= FWRITE;
414:
415: /*
416: * And the other flags. There is no equivalent for FNONBLOCK.
417: */
418:
419: if ((mode & IPEXCL) != 0)
420: newmode |= FEXCL;
421: if ((mode & IPNDLY) != 0)
422: newmode |= FNDELAY;
423:
424: ret = (* funcp) (newdev, cmd, arg, mode, MAKE_CRED (& cred), & rval);
425:
426: SETUERROR (ret);
427: return rval;
428: }
429:
430:
431:
432: #if 0
433: /*
434: * This function is called upon by the machine-generated code in "conf.c" to
435: * forward a Coherent device block request to a System V device.
436: */
437:
438: #if __USE_PROTO__
439: int (_forward_strategy) (BUF * buf, ddi_strategy_t funcp)
440: #else
441: int
442: _forward_strategy __ARGS ((buf, funcp))
443: BUF * buf;
444: ddi_strategy_t funcp;
445: #endif
446: {
447: cmn_err (CE_PANIC, "DDI/DKI block drivers not yet supported");
448: }
449: #endif
450:
451:
452: /*
453: * This function is called upon by the machine-generated code in "conf.c" to
454: * forward a Coherent device poll request to a System V device.
455: */
456:
457: #if __USE_PROTO__
458: int (_forward_poll) (o_dev_t dev, int events, int msec, ddi_chpoll_t funcp)
459: #else
460: int
461: _forward_poll __ARGS ((dev, events, msec, funcp))
462: o_dev_t dev;
463: int events;
464: int msec;
465: ddi_chpoll_t funcp;
466: #endif
467: {
468: int ret;
469:
470: cmn_err (CE_PANIC, "DDI/DKI polling not yet supported");
471:
472: /* ret = (* funcp) (newdev, events, msec == 0, & revents, pollhead) */
473:
474: return 0;
475: }
476:
477:
478: /*
479: * Forward Coh open request to actual STREAMS driver-request-processing code.
480: */
481:
482: #if __USE_PROTO__
483: int (_streams_open) (o_dev_t dev, int mode, int __NOTUSED (flags),
484: struct streamtab * stabp)
485: #else
486: int
487: _streams_open __ARGS ((dev, mode, flags, stabp))
488: o_dev_t dev;
489: int mode;
490: int flags;
491: struct streamtab
492: * stabp;
493: #endif
494: {
495: n_dev_t newdev = makedevice (major (dev), minor (dev));
496: n_dev_t olddev = newdev;
497: cred_t cred;
498: int newmode;
499: int ret;
500:
501: newmode = 0;
502:
503: if ((mode & IPR) != 0)
504: newmode |= FREAD;
505: if ((mode & IPW) != 0)
506: newmode |= FWRITE;
507: if ((mode & IPEXCL) != 0)
508: newmode |= FEXCL;
509: if ((mode & IPNDLY) != 0)
510: newmode |= FNDELAY;
511:
512: ret = STREAMS_OPEN (& newdev, stabp, newmode, MAKE_CRED (& cred));
513:
514: if (olddev != newdev)
515: cmn_err (CE_PANIC, "No cloning permitted through the Coherent driver system");
516:
517: SETUERROR (ret);
518: return ret;
519: }
520:
521:
522: /*
523: * Forward Coh close request to actual STREAMS driver-request-processing code.
524: */
525:
526: #if __USE_PROTO__
527: int (_streams_close) (o_dev_t dev, int mode, int __NOTUSED (flags),
528: struct streamtab * __NOTUSED (stabp))
529: #else
530: int
531: _streams_close __ARGS ((dev, mode, flags, stabp))
532: o_dev_t dev;
533: int mode;
534: int flags;
535: struct streamtab
536: * stabp;
537: #endif
538: {
539: shead_t * sheadp;
540: cred_t cred;
541: int newmode;
542: int ret;
543:
544: if ((sheadp = SHEAD_FIND (makedevice (major (dev), minor (dev)),
545: DEV_SLIST)) == NULL) {
546: SETUERROR (ENXIO);
547: return -1;
548: }
549:
550: newmode = 0;
551:
552: if ((mode & IPR) != 0)
553: newmode |= FREAD;
554: if ((mode & IPW) != 0)
555: newmode |= FWRITE;
556: if ((mode & IPEXCL) != 0)
557: newmode |= FEXCL;
558: if ((mode & IPNDLY) != 0)
559: newmode |= FNDELAY;
560:
561: ret = STREAMS_CLOSE (sheadp, newmode, MAKE_CRED (& cred));
562:
563: SETUERROR (ret);
564: return ret;
565: }
566:
567:
568: /*
569: * Forward Coh read request to actual STREAMS driver-request-processing code.
570: */
571:
572: #if __USE_PROTO__
573: int (_streams_read) (o_dev_t dev, IO * iop,
574: struct streamtab * __NOTUSED (stabp))
575: #else
576: int
577: _streams_read __ARGS ((dev, iop, stabp))
578: o_dev_t dev;
579: IO * iop;
580: struct streamtab
581: * stabp;
582: #endif
583: {
584: iovec_t iov;
585: uio_t uio;
586: int ret;
587: shead_t * sheadp;
588:
589: if ((sheadp = SHEAD_FIND (makedevice (major (dev), minor (dev)),
590: DEV_SLIST)) == NULL) {
591: SETUERROR (ENXIO);
592: return -1;
593: }
594:
595: ret = STREAMS_READ (sheadp, MAKE_UIO (& uio, & iov, FREAD, iop));
596:
597: DESTROY_UIO (& uio, iop);
598: SETUERROR (ret);
599: return ret;
600: }
601:
602:
603: /*
604: * Forward Coh write request to actual STREAMS driver-request-processing code.
605: */
606:
607: #if __USE_PROTO__
608: int (_streams_write) (o_dev_t dev, IO * iop,
609: struct streamtab * __NOTUSED (stabp))
610: #else
611: int
612: _streams_write __ARGS ((dev, iop, stabp))
613: o_dev_t dev;
614: IO * iop;
615: struct streamtab
616: * stabp;
617: #endif
618: {
619: iovec_t iov;
620: uio_t uio;
621: int ret;
622: shead_t * sheadp;
623:
624: if ((sheadp = SHEAD_FIND (makedevice (major (dev), minor (dev)),
625: DEV_SLIST)) == NULL) {
626: SETUERROR (ENXIO);
627: return -1;
628: }
629:
630: ret = STREAMS_WRITE (sheadp, MAKE_UIO (& uio, & iov, FWRITE, iop));
631:
632: DESTROY_UIO (& uio, iop);
633: SETUERROR (ret);
634: return ret;
635: }
636:
637:
638: /*
639: * Forward Coh ioctl request to actual STREAMS driver-request-processing code.
640: */
641:
642: #if __USE_PROTO__
643: int (_streams_ioctl) (o_dev_t dev, int cmd, _VOID * arg, int mode,
644: struct streamtab * __NOTUSED (stabp))
645: #else
646: int
647: _streams_ioctl __ARGS ((dev, cmd, arg, mode, stabp))
648: o_dev_t dev;
649: int cmd;
650: _VOID * arg;
651: int mode;
652: struct streamtab
653: * stabp;
654: #endif
655: {
656: cred_t cred;
657: int rval;
658: int newmode;
659: int ret;
660: shead_t * sheadp;
661:
662: if ((sheadp = SHEAD_FIND (makedevice (major (dev), minor (dev)),
663: DEV_SLIST)) == NULL) {
664: SETUERROR (ENXIO);
665: return -1;
666: }
667:
668: newmode = 0;
669:
670: if ((mode & IPR) != 0)
671: newmode |= FREAD;
672: if ((mode & IPW) != 0)
673: newmode |= FWRITE;
674: if ((mode & IPEXCL) != 0)
675: newmode |= FEXCL;
676: if ((mode & IPNDLY) != 0)
677: newmode |= FNDELAY;
678:
679: ret = STREAMS_IOCTL (sheadp, cmd, arg, newmode, MAKE_CRED (& cred),
680: & rval);
681:
682: SETUERROR (ret);
683: return rval;
684:
685: }
686:
687:
688: /*
689: * Forward Coh poll request to actual STRAAMS driver-request-processing code.
690: */
691:
692: #if __USE_PROTO__
693: int (_streams_chpoll) (o_dev_t dev, int events, int msec,
694: struct streamtab * stabp)
695: #else
696: int
697: _streams_chpoll __ARGS ((dev, events, msec, stabp))
698: o_dev_t dev;
699: int events;
700: int msec;
701: struct streamtab
702: * stabp;
703: #endif
704: {
705: int ret;
706:
707: cmn_err (CE_PANIC, "DDI/DKI polling not yet supported");
708:
709: /* ret = (* funcp) (newdev, events, msec == 0, & revents, pollhead) */
710: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.