1 /************************************************************************** 2 ** 3 ** $Id: pcivar.h,v 1.6 1995/05/30 08:13:12 rgrimes Exp $ 4 ** 5 ** Declarations for pci device drivers. 6 ** 7 ** FreeBSD 8 ** 9 **------------------------------------------------------------------------- 10 ** 11 ** Copyright (c) 1994 Wolfgang Stanglmeier. All rights reserved. 12 ** 13 ** Redistribution and use in source and binary forms, with or without 14 ** modification, are permitted provided that the following conditions 15 ** are met: 16 ** 1. Redistributions of source code must retain the above copyright 17 ** notice, this list of conditions and the following disclaimer. 18 ** 2. Redistributions in binary form must reproduce the above copyright 19 ** notice, this list of conditions and the following disclaimer in the 20 ** documentation and/or other materials provided with the distribution. 21 ** 3. The name of the author may not be used to endorse or promote products 22 ** derived from this software without specific prior written permission. 23 ** 24 ** THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 25 ** IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 26 ** OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 27 ** IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 28 ** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 29 ** NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 30 ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 31 ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 32 ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 33 ** THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 ** 35 *************************************************************************** 36 */ 37 38 #ifndef __PCI_VAR_H__ 39 #define __PCI_VAR_H__ "pl2 95/03/21" 40 41 /*----------------------------------------------------------------- 42 ** 43 ** main pci initialization function. 44 ** called at boot time from autoconf.c 45 ** 46 **----------------------------------------------------------------- 47 */ 48 49 void pci_configure (void); 50 51 /*----------------------------------------------------------------- 52 ** 53 ** The pci configuration id describes a pci device on the bus. 54 ** It is constructed from: bus, device & function numbers. 55 ** 56 **----------------------------------------------------------------- 57 */ 58 59 typedef union { 60 u_long cfg1; 61 struct { 62 u_char enable; 63 u_char forward; 64 u_short port; 65 } cfg2; 66 unsigned tag; 67 } pcici_t; 68 69 #define sametag(x,y) ((x).tag == (y).tag) 70 71 /*----------------------------------------------------------------- 72 ** 73 ** Each pci device has an unique device id. 74 ** It is used to find a matching driver. 75 ** 76 **----------------------------------------------------------------- 77 */ 78 79 typedef u_long pcidi_t; 80 81 /*----------------------------------------------------------------- 82 ** 83 ** The following functions are provided for the device driver 84 ** to read/write the configuration space. 85 ** 86 ** pci_conf_read(): 87 ** Read a long word from the pci configuration space. 88 ** Requires a tag (from pcitag) and the register 89 ** number (should be a long word alligned one). 90 ** 91 ** pci_conf_write(): 92 ** Writes a long word to the pci configuration space. 93 ** Requires a tag (from pcitag), the register number 94 ** (should be a long word alligned one), and a value. 95 ** 96 **----------------------------------------------------------------- 97 */ 98 99 u_long pci_conf_read (pcici_t tag, u_long reg ); 100 101 void pci_conf_write (pcici_t tag, u_long reg, u_long data); 102 103 /*----------------------------------------------------------------- 104 ** 105 ** The pci driver structure. 106 ** 107 ** name: The short device name. 108 ** 109 ** probe: Checks if the driver can support a device 110 ** with this type. The tag may be used to get 111 ** more info with pci_read_conf(). See below. 112 ** It returns a string with the devices name, 113 ** or a NULL pointer, if the driver cannot 114 ** support this device. 115 ** 116 ** attach: Allocate a control structure and prepare 117 ** it. This function may use the pci mapping 118 ** functions. See below. 119 ** (configuration id) or type. 120 ** 121 ** count: A pointer to a unit counter. 122 ** It's used by the pci configurator to 123 ** allocate unit numbers. 124 ** 125 **----------------------------------------------------------------- 126 */ 127 128 struct kern_devconf; 129 130 struct pci_device { 131 char* pd_name; 132 char* (*pd_probe ) (pcici_t tag, pcidi_t type); 133 void (*pd_attach) (pcici_t tag, int unit); 134 u_long *pd_count; 135 int (*pd_shutdown) (struct kern_devconf *, int); 136 }; 137 138 /*----------------------------------------------------------------- 139 ** 140 ** This table includes pointers to all pci device drivers. 141 ** It should be generated by the linker. 142 ** 143 **----------------------------------------------------------------- 144 */ 145 146 extern struct linker_set pcidevice_set; 147 148 extern unsigned pci_max_burst_len; /* log2 of safe burst transfer length */ 149 extern unsigned pci_mechanism; 150 extern unsigned pci_maxdevice; 151 152 /*----------------------------------------------------------------- 153 ** 154 ** The pci-devconf interface. 155 ** 156 **----------------------------------------------------------------- 157 */ 158 159 struct pci_info { 160 u_short pi_bus; 161 u_short pi_device; 162 }; 163 164 #define PCI_EXT_CONF_LEN (16) 165 #define PCI_EXTERNAL_LEN (sizeof(struct pci_externalize_buffer)) 166 167 struct pci_externalize_buffer { 168 struct pci_info peb_pci_info; 169 u_long peb_config[PCI_EXT_CONF_LEN]; 170 }; 171 172 /*----------------------------------------------------------------- 173 ** 174 ** Map a pci device to physical and virtual memory. 175 ** 176 ** Entry selects the register in the pci configuration 177 ** space, which supplies the size of the region, and 178 ** receives the physical address. 179 ** 180 ** In case of success the function sets the addresses 181 ** in *va and *pa, and returns 1. 182 ** In case of errors a message is written, 183 ** and the function returns 0. 184 ** 185 **----------------------------------------------------------------- 186 */ 187 188 int pci_map_mem (pcici_t tag, u_long entry, u_long * va, u_long * pa); 189 190 /*----------------------------------------------------------------- 191 ** 192 ** Map a pci device to an io port area. 193 ** 194 ** Entry selects the register in the pci configuration 195 ** space, which supplies the size of the region, and 196 ** receives the port number. 197 ** 198 ** In case of success the function sets the port number in pa, 199 ** and returns 1. 200 ** In case of errors a message is written, 201 ** and the function returns 0. 202 ** 203 **----------------------------------------------------------------- 204 */ 205 206 int pci_map_port (pcici_t tag, u_long entry, u_short * pa); 207 208 /*----------------------------------------------------------------- 209 ** 210 ** Map a pci interrupt to an isa irq line, and enable the interrupt. 211 ** 212 ** ----------------- 213 ** 214 ** func is the interrupt handler, arg is the argument 215 ** to the handler (usually a pointer to a softc). 216 ** 217 ** The maskptr argument should be &bio_imask, 218 ** &net_imask etc. or NULL. 219 ** 220 ** If there is any error, a message is written, and 221 ** the function returns with zero. 222 ** Else it returns with a value different to zero. 223 ** 224 ** ----------------- 225 ** 226 ** The irq number is read from the configuration space. 227 ** (Should have been set by the bios). 228 ** 229 ** Supports multiple handlers per irq (shared interrupts). 230 ** 231 ** ----------------- 232 ** 233 ** There is code to support shared edge triggered ints. 234 ** This relies on the cooperation of the interrupt handlers: 235 ** they have to return a value <>0 if and only if something 236 ** was done. Beware of the performance penalty. 237 ** 238 **----------------------------------------------------------------- 239 */ 240 241 typedef int pci_inthand_t(void *arg); 242 243 struct pci_int_desc { 244 struct pci_int_desc * pcid_next; 245 pcici_t pcid_tag; 246 pci_inthand_t *pcid_handler; 247 void* pcid_argument; 248 unsigned * pcid_maskptr; 249 unsigned pcid_tally; 250 unsigned pcid_mask; 251 }; 252 253 int pci_map_int (pcici_t tag, pci_inthand_t *func, void *arg, 254 unsigned *maskptr); 255 256 int pci_unmap_int (pcici_t tag); 257 258 #endif 259