1: /*
   2:  * Attach the passed device:
   3:  *	Patch the interrupt vector
   4:  *	Call the device attach routine
   5:  */
   6: 
   7: #include    <stdio.h>
   8: #include    <a.out.h>
   9: #include    <sys/autoconfig.h>
  10: #include    <sys/psw.h>
  11: #include    "dtab.h"
  12: #include    "ivec.h"
  13: 
  14: struct  done_s {
  15:     char    *d_name;        /* Device name */
  16:     int d_unit;         /* Current unit for wildcarding */
  17:     struct  done_s *d_next;
  18: };
  19: 
  20: struct  done_s  *done = NULL;       /* List of things done */
  21: extern  int debug;
  22: extern  int errno;
  23: int vec_set[NVECTOR], num_vec;
  24: 
  25: attach(dp)
  26: struct dtab_s *dp;
  27: {
  28:     int unit, addr;
  29:     int ret;
  30:     register struct handler_s *sp;
  31: 
  32:     if ((unit = find_unit(dp)) == -1) {
  33:         prdev(dp);
  34:         printf(" unit already in use\n");
  35:         return;
  36:     }
  37: 
  38:     /* First attach the device */
  39:     errno = 0;
  40:     if (debug)
  41:         printf("attach: ucall %o(PS_BR0, %o, %o)\n",
  42:             dp->dt_attach->n_value,
  43:             dp->dt_addr, unit);
  44:     else if ((ret = ucall(PS_BR0, dp->dt_attach->n_value, dp->dt_addr, unit)) == 0
  45:         || ret == -1) {
  46:         prdev(dp);
  47:         if (ret == -1 && errno) {
  48:             perror("ucall");
  49:             exit(AC_SINGLE);
  50:         }
  51:         printf(" attach failed\n");
  52:         return;
  53:     }
  54: 
  55:     /* Then fill the interrupt vector */
  56:     addr = dp->dt_vector;
  57:     for (sp = dp->dt_handlers; sp != NULL; sp = sp->s_next) {
  58:         if (sp->s_nl->n_value == 0) {
  59:             prdev(dp);
  60:             printf(" no address found for %s\n", sp->s_str);
  61:             exit(AC_SINGLE);
  62:         }
  63:         write_vec(addr, sp->s_nl->n_value, pry(dp) + unit);
  64:         if (num_vec == NVECTOR-1) {
  65:             printf("Too many vectors to configure\n");
  66:             exit(AC_SINGLE);
  67:         } else
  68:             vec_set[num_vec++] = addr;
  69:         addr += IVSIZE;
  70:     }
  71:     prdev(dp);
  72:     printf(" attached\n");
  73: }
  74: 
  75: have_set(vec)
  76: {
  77:     int i;
  78: 
  79:     for (i = 0; i < num_vec; i++)
  80:         if (vec_set[i] == vec)
  81:             return(1);
  82:     return(0);
  83: }
  84: pry(dp)
  85: struct dtab_s *dp;
  86: {
  87:     switch(dp->dt_br) {
  88:         case 4: return PS_BR4;
  89:         case 5: return PS_BR5;
  90:         case 6: return PS_BR6;
  91:         case 7: return PS_BR7;
  92:         default:
  93:             prdev(dp);
  94:             printf(": br%d is not supported.  Assuming 7\n", dp->dt_br);
  95:     }
  96:     return PS_BR7;
  97: }
  98: 
  99: write_vec(addr, value, pri)
 100: {
 101:     stuff(value, addr);
 102:     stuff(pri, addr + sizeof (int));
 103: }
 104: 
 105: /*
 106:  * find_unit -- Add this device to the list of devices if it isn't already
 107:  * in the list somewhere.  If it has an explicit unit number then use that
 108:  * else fill in the wildcard with next biggest number
 109:  */
 110: 
 111: find_unit(dp)
 112: struct dtab_s *dp;
 113: {
 114:     struct done_s *dn = NULL;
 115:     int found, want_unit;
 116: 
 117:     found = 0;
 118:     if (done == NULL) {
 119:         dn = malloc(sizeof *dn);
 120:         done = dn;
 121:         dn->d_next = NULL;
 122:     } else {
 123:         dn = done;
 124:         while (1) {
 125:             if (strcmp(dn->d_name, dp->dt_name) == 0) {
 126:                 found = 1;
 127:                 break;
 128:             }
 129:             if (dn->d_next == NULL)
 130:                 break;
 131:             dn = dn->d_next;
 132:         }
 133:         if (! found) {
 134:             dn->d_next = malloc(sizeof *dn);
 135:             dn = dn->d_next;
 136:             dn->d_next = NULL;
 137:         }
 138:     }
 139: 
 140:     if (! found) {
 141:         dn->d_name = dp->dt_name;
 142:         if ((dn->d_unit = dp->dt_unit - 1) < -1)
 143:             dn->d_unit = -1;
 144:     }
 145: 
 146:     /* Fill in wildcards */
 147:     if ((want_unit = dp->dt_unit) == -1)
 148:         want_unit = dn->d_unit + 1;
 149:     else if (want_unit <= dn->d_unit)
 150:         return -1;
 151:     return dn->d_unit = dp->dt_unit = want_unit;
 152: }
 153: 
 154: /*
 155:  *  Call the device-attach routine with a 0 addr
 156:  *  to indicate that the device isn't present
 157:  *  (needed for devices that might be root devices
 158:  *  and thus must have addr/vector initialized).
 159:  *  Only done if the unit number was not a wildcard.
 160:  */
 161: detach(dp)
 162: struct dtab_s *dp;
 163: {
 164:     int unit;
 165: 
 166:     if ((unit = dp->dt_unit) == -1)
 167:         return;
 168:     if (debug)
 169:         printf("detach: ucall %o(PS_BR0, %o, %o)\n", dp->dt_attach->n_value,
 170:             0, unit);
 171:     else
 172:         ucall(PS_BR0, dp->dt_attach->n_value, 0, unit);
 173: }

Defined functions

attach defined in line 25; used 2 times
find_unit defined in line 111; used 1 times
  • in line 32
have_set defined in line 75; used 1 times
pry defined in line 84; used 1 times
  • in line 63
write_vec defined in line 99; used 1 times
  • in line 63

Defined variables

done defined in line 20; used 3 times
num_vec defined in line 23; used 3 times
vec_set defined in line 23; used 2 times

Defined struct's

done_s defined in line 14; used 6 times
Last modified: 1983-10-16
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 977
Valid CSS Valid XHTML 1.0 Strict