1 /************************************************************************** 2 ** 3 ** $Id: pcivar.h,v 1.8 1996/01/23 21:47:17 se 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_char pi_bus; 161 u_char pi_device; 162 u_char pi_func; 163 u_char pi_dummy; 164 }; 165 166 #define PCI_EXT_CONF_LEN (16) 167 #define PCI_EXTERNAL_LEN (sizeof(struct pci_externalize_buffer)) 168 169 struct pci_externalize_buffer { 170 struct pci_info peb_pci_info; 171 u_long peb_config[PCI_EXT_CONF_LEN]; 172 }; 173 174 /*----------------------------------------------------------------- 175 ** 176 ** Map a pci device to physical and virtual memory. 177 ** 178 ** Entry selects the register in the pci configuration 179 ** space, which supplies the size of the region, and 180 ** receives the physical address. 181 ** 182 ** In case of success the function sets the addresses 183 ** in *va and *pa, and returns 1. 184 ** In case of errors a message is written, 185 ** and the function returns 0. 186 ** 187 **----------------------------------------------------------------- 188 */ 189 190 int pci_map_mem (pcici_t tag, u_long entry, u_long * va, u_long * pa); 191 192 /*----------------------------------------------------------------- 193 ** 194 ** Map a pci device to an io port area. 195 ** 196 ** Entry selects the register in the pci configuration 197 ** space, which supplies the size of the region, and 198 ** receives the port number. 199 ** 200 ** In case of success the function sets the port number in pa, 201 ** and returns 1. 202 ** In case of errors a message is written, 203 ** and the function returns 0. 204 ** 205 **----------------------------------------------------------------- 206 */ 207 208 int pci_map_port (pcici_t tag, u_long entry, u_short * pa); 209 210 /*----------------------------------------------------------------- 211 ** 212 ** Map a pci interrupt to an isa irq line, and enable the interrupt. 213 ** 214 ** ----------------- 215 ** 216 ** func is the interrupt handler, arg is the argument 217 ** to the handler (usually a pointer to a softc). 218 ** 219 ** The maskptr argument should be &bio_imask, 220 ** &net_imask etc. or NULL. 221 ** 222 ** If there is any error, a message is written, and 223 ** the function returns with zero. 224 ** Else it returns with a value different to zero. 225 ** 226 ** ----------------- 227 ** 228 ** The irq number is read from the configuration space. 229 ** (Should have been set by the bios). 230 ** 231 ** Supports multiple handlers per irq (shared interrupts). 232 ** 233 **----------------------------------------------------------------- 234 */ 235 236 typedef void pci_inthand_t(void *arg); 237 238 struct pci_int_desc { 239 struct pci_int_desc * pcid_next; 240 pcici_t pcid_tag; 241 pci_inthand_t *pcid_handler; 242 void* pcid_argument; 243 unsigned * pcid_maskptr; 244 unsigned pcid_tally; 245 unsigned pcid_mask; 246 }; 247 248 int pci_map_int (pcici_t tag, pci_inthand_t *func, void *arg, 249 unsigned *maskptr); 250 251 int pci_unmap_int (pcici_t tag); 252 253 #endif 254