1 1.39 matt /* $NetBSD: ubavar.h,v 1.39 2008/03/11 05:34:02 matt Exp $ */ 2 1.2 cgd 3 1.1 ragge /* 4 1.1 ragge * Copyright (c) 1982, 1986 Regents of the University of California. 5 1.1 ragge * All rights reserved. 6 1.1 ragge * 7 1.1 ragge * Redistribution and use in source and binary forms, with or without 8 1.1 ragge * modification, are permitted provided that the following conditions 9 1.1 ragge * are met: 10 1.1 ragge * 1. Redistributions of source code must retain the above copyright 11 1.1 ragge * notice, this list of conditions and the following disclaimer. 12 1.1 ragge * 2. Redistributions in binary form must reproduce the above copyright 13 1.1 ragge * notice, this list of conditions and the following disclaimer in the 14 1.1 ragge * documentation and/or other materials provided with the distribution. 15 1.33 agc * 3. Neither the name of the University nor the names of its contributors 16 1.1 ragge * may be used to endorse or promote products derived from this software 17 1.1 ragge * without specific prior written permission. 18 1.1 ragge * 19 1.1 ragge * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 20 1.1 ragge * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 1.1 ragge * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 1.1 ragge * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 23 1.1 ragge * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24 1.1 ragge * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 25 1.1 ragge * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 26 1.1 ragge * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 27 1.1 ragge * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 28 1.1 ragge * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 29 1.1 ragge * SUCH DAMAGE. 30 1.1 ragge * 31 1.2 cgd * @(#)ubavar.h 7.7 (Berkeley) 6/28/90 32 1.1 ragge */ 33 1.26 matt #ifndef _QBUS_UBAVAR_H 34 1.26 matt #define _QBUS_UBAVAR_H 35 1.1 ragge 36 1.1 ragge /* 37 1.1 ragge * This file contains definitions related to the kernel structures 38 1.1 ragge * for dealing with the unibus adapters. 39 1.1 ragge * 40 1.7 ragge * Each uba has a uba_softc structure. 41 1.1 ragge * Each unibus controller which is not a device has a uba_ctlr structure. 42 1.1 ragge * Each unibus device has a uba_device structure. 43 1.1 ragge */ 44 1.1 ragge 45 1.1 ragge /* 46 1.1 ragge * Per-uba structure. 47 1.1 ragge * 48 1.1 ragge * This structure holds the interrupt vector for the uba, 49 1.1 ragge * and its address in physical and virtual space. At boot time 50 1.1 ragge * we determine the devices attached to the uba's and their 51 1.1 ragge * interrupt vectors, filling in uh_vec. We free the map 52 1.1 ragge * register and bdp resources of the uba into the structures 53 1.1 ragge * defined here. 54 1.1 ragge * 55 1.1 ragge * During normal operation, resources are allocated and returned 56 1.1 ragge * to the structures here. We watch the number of passive releases 57 1.1 ragge * on each uba, and if the number is excessive may reset the uba. 58 1.36 simonb * 59 1.1 ragge * When uba resources are needed and not available, or if a device 60 1.1 ragge * which can tolerate no other uba activity (rk07) gets on the bus, 61 1.1 ragge * then device drivers may have to wait to get to the bus and are 62 1.1 ragge * queued here. It is also possible for processes to block in 63 1.1 ragge * the unibus driver in resource wait (mrwant, bdpwant); these 64 1.1 ragge * wait states are also recorded here. 65 1.1 ragge */ 66 1.7 ragge struct uba_softc { 67 1.39 matt device_t uh_dev; /* Device struct, autoconfig */ 68 1.39 matt struct evcnt uh_intrcnt; /* interrupt counting */ 69 1.18 ragge SIMPLEQ_HEAD(, uba_unit) uh_resq; /* resource wait chain */ 70 1.27 ragge SIMPLEQ_HEAD(, uba_reset) uh_resetq; /* ubareset queue */ 71 1.1 ragge int uh_lastiv; /* last free interrupt vector */ 72 1.35 perry int (*uh_errchk)(struct uba_softc *); 73 1.35 perry void (*uh_beforescan)(struct uba_softc *); 74 1.35 perry void (*uh_afterscan)(struct uba_softc *); 75 1.35 perry void (*uh_ubainit)(struct uba_softc *); 76 1.35 perry void (*uh_ubapurge)(struct uba_softc *, int); 77 1.18 ragge short uh_nr; /* Unibus sequential number */ 78 1.32 ragge short uh_type; /* Type of bus */ 79 1.23 ragge bus_space_tag_t uh_iot; /* Tag for this Unibus */ 80 1.22 ragge bus_space_handle_t uh_ioh; /* Handle for I/O space */ 81 1.25 ragge bus_dma_tag_t uh_dmat; 82 1.34 ragge char *uh_used; /* I/O addresses used */ 83 1.1 ragge }; 84 1.1 ragge 85 1.1 ragge /* 86 1.1 ragge * Per-controller structure. 87 1.16 ragge * The unit struct is common to both the adapter and the controller 88 1.16 ragge * to which it belongs. It is only used on controllers that handles 89 1.16 ragge * BDP's, and calls the adapter queueing subroutines. 90 1.16 ragge */ 91 1.16 ragge struct uba_unit { 92 1.18 ragge SIMPLEQ_ENTRY(uba_unit) uu_resq;/* Queue while waiting for resources */ 93 1.39 matt device_t uu_dev; /* unit's device_t */ 94 1.16 ragge int uu_bdp; /* for controllers that hang on to bdp's */ 95 1.35 perry int (*uu_ready)(struct uba_unit *); 96 1.25 ragge void *uu_ref; /* Buffer this is related to */ 97 1.36 simonb short uu_xclu; /* want exclusive use of bdp's */ 98 1.36 simonb short uu_keepbdp; /* hang on to bdp's once allocated */ 99 1.1 ragge }; 100 1.8 ragge 101 1.8 ragge /* 102 1.27 ragge * Reset structure. All devices that needs to be reinitialized 103 1.27 ragge * after an ubareset registers with this struct. 104 1.27 ragge */ 105 1.27 ragge struct uba_reset { 106 1.27 ragge SIMPLEQ_ENTRY(uba_reset) ur_resetq; 107 1.39 matt void (*ur_reset)(device_t); 108 1.39 matt device_t ur_dev; 109 1.27 ragge }; 110 1.27 ragge 111 1.27 ragge /* 112 1.8 ragge * uba_attach_args is used during autoconfiguration. It is sent 113 1.8 ragge * from ubascan() to each (possible) device. 114 1.8 ragge */ 115 1.8 ragge struct uba_attach_args { 116 1.23 ragge bus_space_tag_t ua_iot; /* Tag for this bus I/O-space */ 117 1.23 ragge bus_addr_t ua_ioh; /* I/O regs addr */ 118 1.30 matt bus_dma_tag_t ua_dmat; /* DMA tag for this bus'es dma */ 119 1.30 matt struct evcnt *ua_evcnt; 120 1.26 matt void *ua_icookie; /* Cookie for interrupt establish */ 121 1.23 ragge int ua_iaddr; /* Full CSR address of device */ 122 1.23 ragge int ua_br; /* IPL this dev interrupted on */ 123 1.23 ragge int ua_cvec; /* Vector for this device */ 124 1.8 ragge }; 125 1.1 ragge 126 1.1 ragge /* 127 1.1 ragge * Flags to UBA map/bdp allocation routines 128 1.1 ragge */ 129 1.1 ragge #define UBA_NEEDBDP 0x01 /* transfer needs a bdp */ 130 1.1 ragge #define UBA_CANTWAIT 0x02 /* don't block me */ 131 1.1 ragge #define UBA_NEED16 0x04 /* need 16 bit addresses only */ 132 1.1 ragge #define UBA_HAVEBDP 0x08 /* use bdp specified in high bits */ 133 1.25 ragge #define UBA_DONTQUE 0x10 /* Do not enqueue xfer */ 134 1.1 ragge 135 1.32 ragge /* 136 1.32 ragge * Type of adapter. 137 1.32 ragge */ 138 1.32 ragge #define UBA_UBA 0 /* Traditional unibus adapter */ 139 1.32 ragge #define UBA_MVI 1 /* MVI direct-mapped unibus */ 140 1.32 ragge #define UBA_QBUS 2 /* Qbus with map registers */ 141 1.1 ragge /* 142 1.31 ragge * Struct for unibus allocation. 143 1.31 ragge */ 144 1.31 ragge struct ubinfo { 145 1.31 ragge bus_dmamap_t ui_dmam; 146 1.31 ragge bus_dma_segment_t ui_seg; 147 1.31 ragge int ui_rseg; 148 1.38 christos void *ui_vaddr; 149 1.31 ragge bus_addr_t ui_baddr; 150 1.31 ragge bus_size_t ui_size; 151 1.31 ragge }; 152 1.31 ragge 153 1.31 ragge /* 154 1.25 ragge * Some common defines for all subtypes of U/Q-buses/adapters. 155 1.1 ragge */ 156 1.25 ragge #define MAXUBAXFER (63*1024) /* Max transfer size in bytes */ 157 1.25 ragge #define ubdevreg(addr) ((addr) & 017777) 158 1.1 ragge 159 1.6 jtc #ifdef _KERNEL 160 1.28 matt void uba_intr_establish(void *, int, void (*)(void *), void *, struct evcnt *); 161 1.39 matt void uba_reset_establish(void (*)(device_t), device_t); 162 1.28 matt void uba_attach(struct uba_softc *, unsigned long); 163 1.28 matt void uba_enqueue(struct uba_unit *); 164 1.28 matt void uba_done(struct uba_softc *); 165 1.28 matt void ubareset(struct uba_softc *); 166 1.31 ragge int uballoc(struct uba_softc *, struct ubinfo *, int); 167 1.31 ragge int ubmemalloc(struct uba_softc *, struct ubinfo *, int); 168 1.31 ragge void ubfree(struct uba_softc *, struct ubinfo *); 169 1.31 ragge void ubmemfree(struct uba_softc *, struct ubinfo *); 170 1.6 jtc #endif /* _KERNEL */ 171 1.26 matt 172 1.26 matt #endif /* _QBUS_UBAVAR_H */ 173