pcivar.h revision 7233
1/************************************************************************** 2** 3** $Id: pcivar.h,v 1.3 1995/03/17 04:27:21 davidg 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 49void 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 59typedef 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 79typedef 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 99u_long pci_conf_read (pcici_t tag, u_long reg ); 100 101void 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 128struct pci_device { 129 char* pd_name; 130 char* (*pd_probe ) (pcici_t tag, pcidi_t type); 131 void (*pd_attach) (pcici_t tag, int unit); 132 u_long *pd_count; 133 int (*pd_shutdown) (struct kern_devconf *, int); 134}; 135 136/*----------------------------------------------------------------- 137** 138** This table includes pointers to all pci device drivers. 139** It should be generated by the linker. 140** 141**----------------------------------------------------------------- 142*/ 143 144extern struct linker_set pcidevice_set; 145 146extern unsigned pci_max_burst_len; /* log2 of safe burst transfer length */ 147extern unsigned pci_mechanism; 148extern unsigned pci_maxdevice; 149 150/*----------------------------------------------------------------- 151** 152** The pci-devconf interface. 153** 154**----------------------------------------------------------------- 155*/ 156 157struct pci_info { 158 u_short pi_bus; 159 u_short pi_device; 160}; 161 162#define PCI_EXT_CONF_LEN (16) 163#define PCI_EXTERNAL_LEN (sizeof(struct pci_externalize_buffer)) 164 165struct pci_externalize_buffer { 166 struct pci_info peb_pci_info; 167 u_long peb_config[PCI_EXT_CONF_LEN]; 168}; 169 170/*----------------------------------------------------------------- 171** 172** Map a pci device to physical and virtual memory. 173** 174** Entry selects the register in the pci configuration 175** space, which supplies the size of the region, and 176** receives the physical address. 177** 178** In case of success the function sets the addresses 179** in *va and *pa, and returns 1. 180** In case of errors a message is written, 181** and the function returns 0. 182** 183**----------------------------------------------------------------- 184*/ 185 186int pci_map_mem (pcici_t tag, u_long entry, u_long * va, u_long * pa); 187 188/*----------------------------------------------------------------- 189** 190** Map a pci device to an io port area. 191** 192** Entry selects the register in the pci configuration 193** space, which supplies the size of the region, and 194** receives the port number. 195** 196** In case of success the function sets the port number in pa, 197** and returns 1. 198** In case of errors a message is written, 199** and the function returns 0. 200** 201**----------------------------------------------------------------- 202*/ 203 204int pci_map_port (pcici_t tag, u_long entry, u_short * pa); 205 206/*----------------------------------------------------------------- 207** 208** Map a pci interrupt to an isa irq line, and enable the interrupt. 209** 210** ----------------- 211** 212** func is the interrupt handler, arg is the argument 213** to the handler (usually a pointer to a softc). 214** 215** The maskptr argument should be &bio_imask, 216** &net_imask etc. or NULL. 217** 218** If there is any error, a message is written, and 219** the function returns with zero. 220** Else it returns with a value different to zero. 221** 222** ----------------- 223** 224** The irq number is read from the configuration space. 225** (Should have been set by the bios). 226** 227** Supports multiple handlers per irq (shared interrupts). 228** 229** ----------------- 230** 231** There is code to support shared edge triggered ints. 232** This relies on the cooperation of the interrupt handlers: 233** they have to return a value <>0 if and only if something 234** was done. Beware of the performance penalty. 235** 236**----------------------------------------------------------------- 237*/ 238 239struct pci_int_desc { 240 struct pci_int_desc * pcid_next; 241 pcici_t pcid_tag; 242 int (*pcid_handler)(); 243 void* pcid_argument; 244 unsigned * pcid_maskptr; 245 unsigned pcid_tally; 246 unsigned pcid_mask; 247}; 248 249int pci_map_int (pcici_t tag, int (*func)(), void* arg, unsigned * maskptr); 250 251int pci_unmap_int (pcici_t tag); 252 253#endif 254