|
|
1.1 root 1: /*
2: * @(#)devio.c 1.1 86/02/03 Copyright (c) 1985 by Sun Microsystems, Inc.
3: */
4:
5: /*
6: * Device interface code for standalone I/O system.
7: *
8: * Most simply indirect thru the table to call the "right" routine.
9: */
1.1.1.2 ! root 10: #include <sys/param.h>
! 11: #include <sys/inode.h>
1.1 root 12: #include "saio.h"
13:
14: /*
15: * Strategy -- handles I/O in large blocks for drivers.
16: * (This routine is private to this file.)
17: *
18: * If a devread() or devwrite() is attempted which is larger
19: * than the max I/O size for this device, break it up into a
20: * series of max-sized operations.
21: *
22: * Devices which do not declare a max size get the whole thing.
23: */
24: static int
1.1.1.2 ! root 25: strategy(iob, rw)
! 26: struct iob *iob;
1.1 root 27: int rw;
28: {
1.1.1.2 ! root 29: register struct saioreq *sip = &iob->i_si;
1.1 root 30: register char *ma;
31: register unsigned cc;
32: register daddr_t bn;
33: register int errs;
34: register unsigned maxsize;
35: register struct devinfo *dp;
36:
37: if (rw == READ && (sip->si_flgs & F_EOF)) {
38: sip->si_flgs &= ~F_EOF;
39: return (0);
40: }
41: ma = sip->si_ma; /* Save for later */
42: bn = sip->si_bn;
43: cc = sip->si_cc;
44:
45: dp = sip->si_boottab->b_devinfo;
46: if (dp && (maxsize = dp->d_maxiobytes) != 0 &&
1.1.1.2 ! root 47: ((maxsize & (BUFSIZE - 1)) == 0))
1.1 root 48: ;
49: else
50: maxsize = 0x7FFFFFFF;
51: errs = 0;
52: while (sip->si_cc > 0) {
53: if (sip->si_cc > maxsize)
54: sip->si_cc = maxsize;
55: errs = (*sip->si_boottab->b_strategy)(sip, rw);
56: /* short read is expected for 1/2" tape */
57: if (errs <= 0) /* error or EOF */
58: break;
59: sip->si_ma += errs;
1.1.1.2 ! root 60: sip->si_bn += errs / 512;
1.1 root 61: sip->si_cc = cc - (sip->si_ma - ma);
62: }
63: if (errs == 0)
64: sip->si_flgs |= F_EOF;
65: if (errs >= 0)
66: errs = sip->si_ma - ma; /* Add the part we did before */
67: if (errs == 0)
68: sip->si_flgs &= ~F_EOF;
69: sip->si_ma = ma; /* Restore */
70: sip->si_bn = bn;
71: sip->si_cc = cc;
72: return errs;
73: }
74:
75: int
1.1.1.2 ! root 76: devread(iob)
! 77: struct iob *iob;
1.1 root 78: {
79:
1.1.1.2 ! root 80: return(strategy(iob, READ));
1.1 root 81: }
82:
83: int
1.1.1.2 ! root 84: devwrite(iob)
! 85: struct iob *iob;
1.1 root 86: {
87:
1.1.1.2 ! root 88: return(strategy(iob, WRITE));
1.1 root 89: }
90:
91: int
1.1.1.2 ! root 92: devopen(iob)
! 93: struct iob *iob;
1.1 root 94: {
1.1.1.2 ! root 95: register struct saioreq *sip = &iob->i_si;
1.1 root 96: register struct devinfo *dp;
97: register char *a;
98: register int result;
99:
100: sip->si_flgs &= ~F_EOF;
101: sip->si_devaddr = sip->si_devdata = sip->si_dmaaddr = (char *)0;
102: dp = sip->si_boottab->b_devinfo;
103: if (dp) {
104: /* Map controller number into controller address */
105: if (sip->si_ctlr < dp->d_stdcount) {
106: sip->si_ctlr = (int)((dp->d_stdaddrs)[sip->si_ctlr]);
107: }
108: /* Map in device itself */
109: if (dp->d_devbytes) {
110: a = devalloc(dp->d_devtype, sip->si_ctlr,
111: dp->d_devbytes);
112: if (!a)
113: goto bad;
114: sip->si_devaddr = a;
115: }
116: if (dp->d_dmabytes) {
117: a = resalloc(RES_DMAMEM, dp->d_dmabytes);
118: if (!a)
119: goto bad;
120: sip->si_dmaaddr = a;
121: }
122: if (dp->d_localbytes) {
123: a = resalloc(RES_MAINMEM, dp->d_localbytes);
124: if (!a)
125: goto bad;
126: sip->si_devdata = a;
127: }
128: }
129:
130: result = (sip->si_boottab->b_open)(sip);
131: if (result != -1)
132: return result;
133: bad:
134: return -1; /* Indicate failure */
135: }
136:
1.1.1.2 ! root 137: devclose(iob)
! 138: struct iob *iob;
1.1 root 139: {
1.1.1.2 ! root 140: struct saioreq *sip = &iob->i_si;
1.1 root 141:
142: sip->si_flgs &= ~F_EOF;
143: (sip->si_boottab->b_close)(sip);
144: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.