1 /* 2 * Copyright (c) 1982, 1986 Regents of the University of California. 3 * All rights reserved. 4 * 5 * %sccs.include.redist.c% 6 * 7 * @(#)ubavar.h 7.7 (Berkeley) 06/28/90 8 */ 9 10 /* 11 * This file contains definitions related to the kernel structures 12 * for dealing with the unibus adapters. 13 * 14 * Each uba has a uba_hd structure. 15 * Each unibus controller which is not a device has a uba_ctlr structure. 16 * Each unibus device has a uba_device structure. 17 */ 18 19 #ifndef LOCORE 20 /* 21 * Per-uba structure. 22 * 23 * This structure holds the interrupt vector for the uba, 24 * and its address in physical and virtual space. At boot time 25 * we determine the devices attached to the uba's and their 26 * interrupt vectors, filling in uh_vec. We free the map 27 * register and bdp resources of the uba into the structures 28 * defined here. 29 * 30 * During normal operation, resources are allocated and returned 31 * to the structures here. We watch the number of passive releases 32 * on each uba, and if the number is excessive may reset the uba. 33 * 34 * When uba resources are needed and not available, or if a device 35 * which can tolerate no other uba activity (rk07) gets on the bus, 36 * then device drivers may have to wait to get to the bus and are 37 * queued here. It is also possible for processes to block in 38 * the unibus driver in resource wait (mrwant, bdpwant); these 39 * wait states are also recorded here. 40 */ 41 struct uba_hd { 42 int uh_type; /* type of adaptor */ 43 struct uba_regs *uh_uba; /* virt addr of uba adaptor regs */ 44 struct uba_regs *uh_physuba; /* phys addr of uba adaptor regs */ 45 struct pte *uh_mr; /* start of page map */ 46 int uh_memsize; /* size of uba memory, pages */ 47 caddr_t uh_mem; /* start of uba memory address space */ 48 caddr_t uh_iopage; /* start of uba io page */ 49 int (**uh_vec)(); /* interrupt vector */ 50 struct uba_device *uh_actf; /* head of queue to transfer */ 51 struct uba_device *uh_actl; /* tail of queue to transfer */ 52 short uh_mrwant; /* someone is waiting for map reg */ 53 short uh_bdpwant; /* someone awaits bdp's */ 54 int uh_bdpfree; /* free bdp's */ 55 int uh_hangcnt; /* number of ticks hung */ 56 int uh_zvcnt; /* number of recent 0 vectors */ 57 long uh_zvtime; /* time over which zvcnt accumulated */ 58 int uh_zvtotal; /* total number of 0 vectors */ 59 int uh_errcnt; /* number of errors */ 60 int uh_lastiv; /* last free interrupt vector */ 61 short uh_users; /* transient bdp use count */ 62 short uh_xclu; /* an rk07 is using this uba! */ 63 int uh_lastmem; /* limit of any unibus memory */ 64 #define UAMSIZ 100 65 struct map *uh_map; /* register free map */ 66 }; 67 68 /* given a pointer to uba_regs, find DWBUA registers */ 69 /* this should be replaced with a union in uba_hd */ 70 #define BUA(uba) ((struct dwbua_regs *)(uba)) 71 72 /* 73 * Per-controller structure. 74 * (E.g. one for each disk and tape controller, and other things 75 * which use and release buffered data paths.) 76 * 77 * If a controller has devices attached, then there are 78 * cross-referenced uba_drive structures. 79 * This structure is the one which is queued in unibus resource wait, 80 * and saves the information about unibus resources which are used. 81 * The queue of devices waiting to transfer is also attached here. 82 */ 83 struct uba_ctlr { 84 struct uba_driver *um_driver; 85 short um_ctlr; /* controller index in driver */ 86 short um_ubanum; /* the uba it is on */ 87 short um_alive; /* controller exists */ 88 int (**um_intr)(); /* interrupt handler(s) */ 89 caddr_t um_addr; /* address of device in i/o space */ 90 struct uba_hd *um_hd; 91 /* the driver saves the prototype command here for use in its go routine */ 92 int um_cmd; /* communication to dgo() */ 93 int um_ubinfo; /* save unibus registers, etc */ 94 int um_bdp; /* for controllers that hang on to bdp's */ 95 struct buf um_tab; /* queue of devices for this controller */ 96 }; 97 98 /* 99 * Per ``device'' structure. 100 * (A controller has devices or uses and releases buffered data paths). 101 * (Everything else is a ``device''.) 102 * 103 * If a controller has many drives attached, then there will 104 * be several uba_device structures associated with a single uba_ctlr 105 * structure. 106 * 107 * This structure contains all the information necessary to run 108 * a unibus device such as a dz or a dh. It also contains information 109 * for slaves of unibus controllers as to which device on the slave 110 * this is. A flags field here can also be given in the system specification 111 * and is used to tell which dz lines are hard wired or other device 112 * specific parameters. 113 */ 114 struct uba_device { 115 struct uba_driver *ui_driver; 116 short ui_unit; /* unit number on the system */ 117 short ui_ctlr; /* mass ctlr number; -1 if none */ 118 short ui_ubanum; /* the uba it is on */ 119 short ui_slave; /* slave on controller */ 120 int (**ui_intr)(); /* interrupt handler(s) */ 121 caddr_t ui_addr; /* address of device in i/o space */ 122 short ui_dk; /* if init 1 set to number for iostat */ 123 int ui_flags; /* parameter from system specification */ 124 short ui_alive; /* device exists */ 125 short ui_type; /* driver specific type information */ 126 caddr_t ui_physaddr; /* phys addr, for standalone (dump) code */ 127 /* this is the forward link in a list of devices on a controller */ 128 struct uba_device *ui_forw; 129 /* if the device is connected to a controller, this is the controller */ 130 struct uba_ctlr *ui_mi; 131 struct uba_hd *ui_hd; 132 }; 133 134 /* 135 * Per-driver structure. 136 * 137 * Each unibus driver defines entries for a set of routines 138 * as well as an array of types which are acceptable to it. 139 * These are used at boot time by the configuration program. 140 */ 141 struct uba_driver { 142 int (*ud_probe)(); /* see if a driver is really there */ 143 int (*ud_slave)(); /* see if a slave is there */ 144 int (*ud_attach)(); /* setup driver for a slave */ 145 int (*ud_dgo)(); /* fill csr/ba to start transfer */ 146 u_short *ud_addr; /* device csr addresses */ 147 char *ud_dname; /* name of a device */ 148 struct uba_device **ud_dinfo; /* backpointers to ubdinit structs */ 149 char *ud_mname; /* name of a controller */ 150 struct uba_ctlr **ud_minfo; /* backpointers to ubminit structs */ 151 short ud_xclu; /* want exclusive use of bdp's */ 152 short ud_keepbdp; /* hang on to bdp's once allocated */ 153 int (*ud_ubamem)(); /* see if dedicated memory is present */ 154 }; 155 #endif 156 157 /* 158 * Flags to UBA map/bdp allocation routines 159 */ 160 #define UBA_NEEDBDP 0x01 /* transfer needs a bdp */ 161 #define UBA_CANTWAIT 0x02 /* don't block me */ 162 #define UBA_NEED16 0x04 /* need 16 bit addresses only */ 163 #define UBA_HAVEBDP 0x08 /* use bdp specified in high bits */ 164 165 /* 166 * Macros to bust return word from map allocation routines. 167 * SHOULD USE STRUCTURE TO STORE UBA RESOURCE ALLOCATION: 168 */ 169 #ifdef notyet 170 struct ubinfo { 171 long ub_addr; /* unibus address: mr + boff */ 172 int ub_nmr; /* number of registers, 0 if empty */ 173 int ub_bdp; /* bdp number, 0 if none */ 174 }; 175 #define UBAI_MR(i) (((i) >> 9) & 0x7ff) /* starting map register */ 176 #define UBAI_BOFF(i) ((i)&0x1ff) /* page offset */ 177 #else 178 #define UBAI_BDP(i) ((int)(((unsigned)(i)) >> 28)) 179 #define BDPMASK 0xf0000000 180 #define UBAI_NMR(i) ((int)((i) >> 20) & 0xff) /* max 255 (=127.5K) */ 181 #define UBA_MAXNMR 255 182 #define UBAI_MR(i) ((int)((i) >> 9) & 0x7ff) /* max 2047 */ 183 #define UBA_MAXMR 2047 184 #define UBAI_BOFF(i) ((int)((i) & 0x1ff)) 185 #define UBAI_ADDR(i) ((int)((i) & 0xfffff)) /* uba addr (boff+mr) */ 186 #define UBAI_INFO(off, mr, nmr, bdp) \ 187 (((bdp) << 28) | ((nmr) << 20) | ((mr) << 9) | (off)) 188 #endif 189 190 #ifndef LOCORE 191 #ifdef KERNEL 192 #define ubago(ui) ubaqueue(ui, 0) 193 194 /* 195 * UBA related kernel variables 196 */ 197 int numuba; /* number of uba's */ 198 struct uba_hd uba_hd[]; 199 200 /* 201 * Ubminit and ubdinit initialize the mass storage controller and 202 * device tables specifying possible devices. 203 */ 204 extern struct uba_ctlr ubminit[]; 205 extern struct uba_device ubdinit[]; 206 207 /* 208 * UNIBUS device address space is mapped by UMEMmap 209 * into virtual address umem[][]. 210 * The IO page is mapped to the last 8K of each. 211 * This should be enlarged for the Q22 bus. 212 */ 213 extern struct pte UMEMmap[][512]; /* uba device addr pte's */ 214 extern char umem[][512*NBPG]; /* uba device addr space */ 215 216 /* 217 * Since some VAXen vector their unibus interrupts 218 * just adjacent to the system control block, we must 219 * allocate space there when running on ``any'' cpu. This space is 220 * used for the vectors for all ubas. 221 */ 222 extern int (*UNIvec[][128])(); /* unibus vec for ubas */ 223 extern int (*eUNIvec)(); /* end of unibus vec */ 224 225 #if defined(VAX780) || defined(VAX8600) 226 /* 227 * On DW780's, we must set the scb vectors for the nexus of the 228 * UNIbus adaptors to vector to locore unibus adaptor interrupt dispatchers 229 * which make 780's look like the other VAXen. 230 */ 231 extern Xua0int(), Xua1int(), Xua2int(), Xua3int(); 232 #endif VAX780 233 #endif KERNEL 234 #endif !LOCORE 235