pcivar.h revision 21673
1/************************************************************************** 2** 3** $FreeBSD: head/sys/dev/pci/pcivar.h 21673 1997-01-14 07:20:47Z jkh $ 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) (int, 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** Map a pci device to physical and virtual memory. 153** 154** Entry selects the register in the pci configuration 155** space, which supplies the size of the region, and 156** receives the physical address. 157** 158** In case of success the function sets the addresses 159** in *va and *pa, and returns 1. 160** In case of errors a message is written, 161** and the function returns 0. 162** 163**----------------------------------------------------------------- 164*/ 165 166int pci_map_mem (pcici_t tag, u_long entry, vm_offset_t *va, vm_offset_t *pa); 167 168/*----------------------------------------------------------------- 169** 170** Map a pci device to an io port area. 171** 172** Entry selects the register in the pci configuration 173** space, which supplies the size of the region, and 174** receives the port number. 175** 176** In case of success the function sets the port number in pa, 177** and returns 1. 178** In case of errors a message is written, 179** and the function returns 0. 180** 181**----------------------------------------------------------------- 182*/ 183 184int pci_map_port (pcici_t tag, u_long entry, u_short * pa); 185 186/*----------------------------------------------------------------- 187** 188** Map a pci interrupt to an isa irq line, and enable the interrupt. 189** 190** ----------------- 191** 192** func is the interrupt handler, arg is the argument 193** to the handler (usually a pointer to a softc). 194** 195** The maskptr argument should be &bio_imask, 196** &net_imask etc. or NULL. 197** 198** If there is any error, a message is written, and 199** the function returns with zero. 200** Else it returns with a value different to zero. 201** 202** ----------------- 203** 204** The irq number is read from the configuration space. 205** (Should have been set by the bios). 206** 207** Supports multiple handlers per irq (shared interrupts). 208** 209**----------------------------------------------------------------- 210*/ 211 212typedef void pci_inthand_t(void *arg); 213 214struct pci_int_desc { 215 struct pci_int_desc * pcid_next; 216 pcici_t pcid_tag; 217 pci_inthand_t *pcid_handler; 218 void* pcid_argument; 219 unsigned * pcid_maskptr; 220 unsigned pcid_tally; 221 unsigned pcid_mask; 222}; 223 224int pci_map_int (pcici_t tag, pci_inthand_t *func, void *arg, 225 unsigned *maskptr); 226 227int pci_unmap_int (pcici_t tag); 228 229#endif 230