|
|
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 = 0; ! 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: regs->csr = 0; /* initialize csr */ ! 105: ! 106: if(camdebug){ ! 107: printf(" csr initialized: %o at addr %o\n", regs->csr,®s->csr); ! 108: printf(" exit camopen \n"); ! 109: } ! 110: } ! 111: ! 112: camclose() ! 113: { ! 114: /* not used */ ! 115: } ! 116: ! 117: camread() ! 118: { ! 119: /* not used */ ! 120: } ! 121: ! 122: camwrite() ! 123: { ! 124: /* not used */ ! 125: } ! 126: ! 127: camioctl(dev, cmd, usr_buf) ! 128: caddr_t usr_buf; ! 129: { ! 130: extern int copyin(), copyout(); ! 131: struct module_info buffer1; ! 132: struct reg_info buffer2; ! 133: ! 134: unsigned *Dev_addr(), datalo, datahi; ! 135: unsigned short *device; ! 136: char *cdevice; ! 137: ! 138: if(camdebug) { ! 139: printf(" starting camioctl \n"); ! 140: printf(" dev= %o cmd= %d usr_buf= %o at addr %o \n", ! 141: dev,cmd,usr_buf,&usr_buf); ! 142: } ! 143: ! 144: ! 145: switch(cmd) { ! 146: ! 147: case CAMREAD: ! 148: case CAMWRITE: ! 149: case CAMSET: ! 150: ! 151: if(camdebug) { ! 152: printf(" 1st copyin in driver \n"); ! 153: printf(" usr_buf %o \n",usr_buf); ! 154: } ! 155: ! 156: if(copyin(usr_buf, (caddr_t)&buffer1, sizeof(buffer1))) ! 157: u.u_error = EFAULT; ! 158: ! 159: device = ®s->na[buffer1.N][buffer1.A]; ! 160: ! 161: if(camdebug) { ! 162: printf(" address of device: %o \n",device); ! 163: } ! 164: ! 165: if(camdebug) { ! 166: printf(" camioctldriver: %d %d", buffer1.N,buffer1.A);} ! 167: ! 168: switch(cmd) { ! 169: ! 170: case CAMREAD: ! 171: /* Turn off no read bit, set f-bits, lv others unchanged */ ! 172: if(camdebug){ ! 173: printf("started CAMREAD \n"); ! 174: } ! 175: regs->csr = (regs->csr & ~04007) | (buffer1.F & 07); ! 176: if(camdebug){ ! 177: printf("set regs->csr = %o \n",regs->csr); ! 178: } ! 179: ! 180: datalo = regs->na[buffer1.N][buffer1.A]; ! 181: ! 182: if(camdebug){ ! 183: printf("in camread(driver) datalo=%o \n",datalo); ! 184: } ! 185: datahi = regs->datahi; ! 186: buffer1.data = (long)datahi << 16;/*left shift 16 bits*/ ! 187: buffer1.data += (long) datalo; ! 188: break; ! 189: ! 190: case CAMWRITE: ! 191: if(camdebug){ ! 192: printf(" camwrite(driver) start \n"); ! 193: printf(" contents of buffer1:\n"); ! 194: printf("buffer1.F %o\n",buffer1.F); ! 195: printf("buffer1.N %d\n",buffer1.N); ! 196: printf("buffer1.A %d\n",buffer1.A); ! 197: printf("buffer1.data %o\n",buffer1.data); ! 198: printf("buffer1.Q %o\n",buffer1.Q); ! 199: } ! 200: /* Turn off no read bit, set f-bits, lv others unchanged */ ! 201: regs->csr = (regs->csr & ~04007) | (buffer1.F & 07); ! 202: ! 203: if(camdebug){ ! 204: printf("camwrite set regs->csr = %o \n",regs->csr); ! 205: printf("put the buffer into the registers \n"); ! 206: printf("buffer1.data %o at %o", ! 207: buffer1.data,&buffer1.data); ! 208: } ! 209: regs->datahi = (buffer1.data >> 16); ! 210: /*rightshift 16 bits*/ ! 211: ! 212: if(camdebug){ ! 213: printf(" datahi= %o \n", regs->datahi); ! 214: printf(" writing to address %o \n", device); ! 215: } ! 216: ! 217: regs->na[buffer1.N][buffer1.A] = buffer1.data & 0177777; ! 218: ! 219: if(camdebug){ ! 220: printf(" written to address %o\n",device); ! 221: } ! 222: break; ! 223: ! 224: case CAMSET: ! 225: regs->csr &= ~04000; /* turn on "no-read" bit */ ! 226: cdevice = (char*)device; /* Cntrl ops need "MOVB"*/ ! 227: *cdevice = buffer1.F; ! 228: if(camdebug){ ! 229: printf(" cdevice= %o at address= %o \n",cdevice,&cdevice); ! 230: } ! 231: regs->csr &= ~04000; /* turn off no read bit */ ! 232: buffer1.Q = (regs->csr & 0200) >> 7; ! 233: break; ! 234: } ! 235: ! 236: buffer1.Q = (regs->csr & 0200) >> 7; ! 237: if(copyout((caddr_t)&buffer1, usr_buf, sizeof(buffer1))) ! 238: u.u_error = EFAULT; ! 239: ! 240: break; ! 241: ! 242: case CSRREAD: ! 243: case LAMLOREAD: ! 244: case LAMHIREAD: ! 245: case VCTREAD: ! 246: ! 247: switch(cmd) { ! 248: ! 249: case CSRREAD: buffer2.reg = regs->csr; ! 250: break; ! 251: ! 252: case LAMLOREAD: buffer2.reg = regs->lamlo; ! 253: break; ! 254: ! 255: case LAMHIREAD: buffer2.reg = regs->lamhi; ! 256: break; ! 257: ! 258: case VCTREAD: buffer2.reg = regs->int0; ! 259: break; ! 260: } ! 261: ! 262: if(copyout((caddr_t)&buffer2, usr_buf, sizeof(buffer2))) ! 263: u.u_error = EFAULT; ! 264: break; ! 265: ! 266: case CSRWRITE: ! 267: if(copyin(usr_buf, (caddr_t)&buffer2, sizeof(buffer2))) ! 268: u.u_error = EFAULT; ! 269: ! 270: regs->csr = buffer2.reg; ! 271: break; ! 272: } ! 273: } ! 274: ! 275: cam0int() ! 276: { ! 277: /* not used */ ! 278: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.