|
|
1.1 ! root 1: /*#include "../h/param.h"*/ ! 2: /*#include "../h/dir.h"*/ ! 3: /*#include "../h/user.h"*/ ! 4: /*#include "../h/conf.h"*/ ! 5: /*#include "../h/seg.h"*/ ! 6: ! 7: #include <sys/param.h> ! 8: #include <sys/dir.h> ! 9: #include <sys/user.h> ! 10: #include <sys/ubaddr.h> ! 11: #include <sys/buf.h> ! 12: #include <sys/conf.h> ! 13: #include <sys/pte.h> ! 14: #include <sys/proc.h> ! 15: /*#include <sys/seg.h>*/ ! 16: ! 17: #include <sys/camac.h> ! 18: ! 19: int camopen(), camclose(), camread(), camwrite(), camioctl(); ! 20: ! 21: extern struct ubaddr camaddr[]; /* defined in conf..*/ ! 22: extern int camcnt; ! 23: extern caddr_t camcaddr[]; ! 24: ! 25: struct cdevsw camcdev = cdinit(camopen, camclose, camread, camwrite, camioctl); ! 26: ! 27: /*#define BASE 0766000 */ /* start addr of Camac registers for VAX*/ ! 28: /*#define BASE 0166000 old LSI start addr */ ! 29: /* ! 30: * camac registers ! 31: */ ! 32: ! 33: int camdebug = 1; ! 34: ! 35: /* the following is to make shure that the driver occupies ! 36: a contiguous space in memory for all valid camac addresses ! 37: 01400 equals 768 addresses or 384 word addresses ! 38: the base address is then the one chosen for the camac controller ! 39: usually 0766000 (the csr is at N(24)A(0), which is BASE+01400) ! 40: */ ! 41: ! 42: struct camregs { ! 43: unsigned short na[24][16]; ! 44: unsigned short csr; ! 45: unsigned short datahi; ! 46: unsigned short lamlo; ! 47: unsigned short lamhi; ! 48: unsigned short reg4; ! 49: unsigned short reg5; ! 50: unsigned short reg6; ! 51: unsigned short int0; ! 52: }; ! 53: struct camregs *regs; ! 54: ! 55: unsigned long *intvector; ! 56: unsigned short *BASE; ! 57: ! 58: camopen(d,f) ! 59: { ! 60: register int dev; ! 61: ! 62: if(camdebug){ printf(" started camopen \n");} ! 63: ! 64: if((dev = minor(d)) >= camcnt) { ! 65: u.u_error = ENODEV; ! 66: return; ! 67: } ! 68: ! 69: /* get the addresses for regs...*/ ! 70: /* if((regs = (struct camregs *)ubaddr(&camaddr[dev])) == 0 ! 71: || ubbadaddr(camaddr[dev].ubno, (caddr_t)regs, sizeof(u_short))) { ! 72: printf("cam%d absent\n", dev); ! 73: u.u_error = ENODEV; ! 74: return; ! 75: }*/ ! 76: ! 77: /* get the address from the configuration */ ! 78: /* the following will assign the range of contiguous addresses ! 79: for the physical I/O bus addresses */ ! 80: ! 81: regs = (struct camregs *) ubaddr(&camaddr[dev]); ! 82: ! 83: if(camdebug){ ! 84: printf("address: value(csr):%o %o %o %o \n", ! 85: ®s->csr,®s->datahi,®s->lamlo,®s->lamhi); ! 86: } ! 87: /* ! 88: the PDP/11 does it absolut, BASE=0766000 ! 89: */ ! 90: /* regs = (struct camregs *) (BASE + 01400);*/ ! 91: ! 92: BASE = (®s->na[0][0]);/* calculate the BASE relative to CSR */ ! 93: ! 94: if(camdebug){ ! 95: printf(" BASE: %o \n",BASE); ! 96: } ! 97: ! 98: if(camdebug){ ! 99: printf("BASE as calculated:%o \n",BASE); ! 100: printf("should be :20016750000\n"); ! 101: } ! 102: ! 103: /* ! 104: BASE = 020016750000; ! 105: */ ! 106: ! 107: /* intvector = (unsigned *) (BASE + 01416);*/ ! 108: ! 109: ! 110: regs->csr = 0; /* initialize csr */ ! 111: ! 112: if(camdebug){ ! 113: printf(" csr initialized: %o at addr %o\n", regs->csr,®s->csr); ! 114: printf(" exit camopen \n"); ! 115: } ! 116: } ! 117: ! 118: camclose() ! 119: { ! 120: /* not used */ ! 121: } ! 122: ! 123: camread() ! 124: { ! 125: /* not used */ ! 126: } ! 127: ! 128: camwrite() ! 129: { ! 130: /* not used */ ! 131: } ! 132: ! 133: camioctl(dev, cmd, usr_buf) ! 134: caddr_t usr_buf; ! 135: { ! 136: extern int copyin(), copyout(); ! 137: struct module_info buffer1; ! 138: struct reg_info buffer2; ! 139: ! 140: unsigned *Dev_addr(), datalo, datahi; ! 141: unsigned short *device; ! 142: char *cdevice; ! 143: ! 144: if(camdebug) { ! 145: printf(" starting camioctl \n"); ! 146: printf(" dev= %o cmd= %d usr_buf= %o at addr %o \n", ! 147: dev,cmd,usr_buf,&usr_buf); ! 148: } ! 149: ! 150: ! 151: switch(cmd) { ! 152: ! 153: case CAMREAD: ! 154: case CAMWRITE: ! 155: case CAMSET: ! 156: ! 157: if(camdebug) { ! 158: printf(" 1st copyin in driver \n"); ! 159: printf(" usr_buf %o \n",usr_buf); ! 160: } ! 161: ! 162: if(copyin(usr_buf, (caddr_t)&buffer1, sizeof(buffer1))) ! 163: u.u_error = EFAULT; ! 164: ! 165: device = ®s->na[buffer1.N][buffer1.A]; ! 166: ! 167: if(camdebug) { ! 168: printf(" address of device: %o \n",device); ! 169: } ! 170: ! 171: if(camdebug) { ! 172: printf(" camioctldriver: %d %d", buffer1.N,buffer1.A);} ! 173: ! 174: switch(cmd) { ! 175: ! 176: case CAMREAD: ! 177: /* Turn off no read bit, set f-bits, lv others unchanged */ ! 178: if(camdebug){ ! 179: printf("started CAMREAD \n"); ! 180: } ! 181: regs->csr = (regs->csr & ~04007) | (buffer1.F & 07); ! 182: if(camdebug){ ! 183: printf("set regs->csr = %o \n",regs->csr); ! 184: } ! 185: ! 186: datalo = regs->na[buffer1.N][buffer1.A]; ! 187: /* datalo = *device; */ ! 188: ! 189: if(camdebug){ ! 190: printf("in camread(driver) datalo=%o \n",datalo); ! 191: } ! 192: datahi = regs->datahi; ! 193: buffer1.data = (long)datahi << 16;/*left shift 16 bits*/ ! 194: buffer1.data += (long) datalo; ! 195: break; ! 196: ! 197: case CAMWRITE: ! 198: if(camdebug){ ! 199: printf(" camwrite(driver) start \n"); ! 200: printf(" contents of buffer1:\n"); ! 201: printf("buffer1.F %o\n",buffer1.F); ! 202: printf("buffer1.N %d\n",buffer1.N); ! 203: printf("buffer1.A %d\n",buffer1.A); ! 204: printf("buffer1.data %o\n",buffer1.data); ! 205: printf("buffer1.Q %o\n",buffer1.Q); ! 206: } ! 207: /* Turn off no read bit, set f-bits, lv others unchanged */ ! 208: regs->csr = (regs->csr & ~04007) | (buffer1.F & 07); ! 209: ! 210: if(camdebug){ ! 211: printf("camwrite set regs->csr = %o \n",regs->csr); ! 212: printf("put the buffer into the registers \n"); ! 213: printf("buffer1.data %o at %o", ! 214: buffer1.data,&buffer1.data); ! 215: } ! 216: regs->datahi = (buffer1.data >> 16); ! 217: /*rightshift 16 bits*/ ! 218: ! 219: if(camdebug){ ! 220: printf(" datahi= %o \n", regs->datahi); ! 221: printf(" writing to address %o \n", device); ! 222: } ! 223: ! 224: /* indirect write to the address computed for *device */ ! 225: ! 226: /* *device = buffer1.data & 0177777;*//*mask for 16 bits*/ ! 227: regs->na[buffer1.N][buffer1.A] = buffer1.data & 0177777; ! 228: ! 229: if(camdebug){ ! 230: printf(" written to address %o\n",device); ! 231: } ! 232: break; ! 233: ! 234: case CAMSET: ! 235: regs->csr &= ~04000; /* turn on "no-read" bit */ ! 236: cdevice = (char*)device; /* Cntrl ops need "MOVB"*/ ! 237: *cdevice = buffer1.F; ! 238: if(camdebug){ ! 239: printf(" cdevice= %o at address= %o \n",cdevice,&cdevice); ! 240: } ! 241: regs->csr &= ~04000; /* turn off no read bit */ ! 242: buffer1.Q = (regs->csr & 0200) >> 7; ! 243: break; ! 244: } ! 245: ! 246: buffer1.Q = (regs->csr & 0200) >> 7; ! 247: if(copyout((caddr_t)&buffer1, usr_buf, sizeof(buffer1))) ! 248: u.u_error = EFAULT; ! 249: ! 250: break; ! 251: ! 252: case CSRREAD: ! 253: case LAMLOREAD: ! 254: case LAMHIREAD: ! 255: case VCTREAD: ! 256: ! 257: switch(cmd) { ! 258: ! 259: case CSRREAD: buffer2.reg = regs->csr; ! 260: break; ! 261: ! 262: case LAMLOREAD: buffer2.reg = regs->lamlo; ! 263: break; ! 264: ! 265: case LAMHIREAD: buffer2.reg = regs->lamhi; ! 266: break; ! 267: ! 268: case VCTREAD: buffer2.reg = regs->int0; ! 269: break; ! 270: } ! 271: ! 272: if(copyout((caddr_t)&buffer2, usr_buf, sizeof(buffer2))) ! 273: u.u_error = EFAULT; ! 274: break; ! 275: ! 276: case CSRWRITE: ! 277: if(copyin(usr_buf, (caddr_t)&buffer2, sizeof(buffer2))) ! 278: u.u_error = EFAULT; ! 279: ! 280: regs->csr = buffer2.reg; ! 281: break; ! 282: } ! 283: } ! 284: ! 285: cam0int() ! 286: { ! 287: /* not used */ ! 288: } ! 289: ! 290: unsigned * ! 291: Dev_addr(N,A) ! 292: int N,A; ! 293: { ! 294: unsigned long addr; ! 295: ! 296: addr = (unsigned)(BASE + N * 040 + A * 02); ! 297: if(camdebug){ ! 298: printf("\nBASE:%o, N=%d, A=%d",BASE,N,A); ! 299: printf("\nDev_addr(%d,%d)=%o \n",N,A,addr); ! 300: } ! 301: ! 302: return((unsigned *)addr); ! 303: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.