pcivar.h revision 6100
1/************************************************************************** 2** 3** $Id: pcireg.h,v 1.2 1994/11/02 23:47:14 se Exp $ 4** 5** Declarations for pci device drivers. 6** 7** 386bsd / 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__ 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 } pcici_t; 67 68/*----------------------------------------------------------------- 69** 70** Each pci device has an unique device id. 71** It is used to find a matching driver. 72** 73**----------------------------------------------------------------- 74*/ 75 76typedef u_long pcidi_t; 77 78/*----------------------------------------------------------------- 79** 80** The following functions are provided for the device driver 81** to read/write the configuration space. 82** 83** pci_conf_read(): 84** Read a long word from the pci configuration space. 85** Requires a tag (from pcitag) and the register 86** number (should be a long word alligned one). 87** 88** pci_conf_write(): 89** Writes a long word to the pci configuration space. 90** Requires a tag (from pcitag), the register number 91** (should be a long word alligned one), and a value. 92** 93**----------------------------------------------------------------- 94*/ 95 96u_long pci_conf_read (pcici_t tag, u_long reg ); 97 98void pci_conf_write (pcici_t tag, u_long reg, u_long data); 99 100/*----------------------------------------------------------------- 101** 102** The pci driver structure. 103** 104** name: The short device name. 105** 106** probe: Checks if the driver can support a device 107** with this type. The tag may be used to get 108** more info with pci_read_conf(). See below. 109** It returns a string with the devices name, 110** or a NULL pointer, if the driver cannot 111** support this device. 112** 113** attach: Allocate a control structure and prepare 114** it. This function may use the pci mapping 115** functions. See below. 116** (configuration id) or type. 117** 118** count: A pointer to a unit counter. 119** It's used by the pci configurator to 120** allocate unit numbers. 121** 122**----------------------------------------------------------------- 123*/ 124 125struct pci_device { 126 char* pd_name; 127 char* (*pd_probe ) (pcici_t tag, pcidi_t type); 128 void (*pd_attach) (pcici_t tag, int unit); 129 u_long *pd_count; 130}; 131 132/*----------------------------------------------------------------- 133** 134** This table includes pointers to all pci device drivers. 135** It should be generated by the linker. 136** 137**----------------------------------------------------------------- 138*/ 139 140extern struct linker_set pcidevice_set; 141 142/*----------------------------------------------------------------- 143** 144** The pci-devconf interface. 145** 146**----------------------------------------------------------------- 147*/ 148 149struct pci_info { 150 u_short pi_bus; 151 u_short pi_device; 152}; 153 154#define PCI_EXT_CONF_LEN (16) 155#define PCI_EXTERNAL_LEN (sizeof(struct pci_externalize_buffer)) 156 157struct pci_externalize_buffer { 158 struct pci_info peb_pci_info; 159 u_long peb_config[PCI_EXT_CONF_LEN]; 160}; 161 162 163/*----------------------------------------------------------------- 164** 165** Map a pci device to physical and virtual memory. 166** 167** The va and pa addresses are "in/out" parameters. 168** If they are 0 on entry, the function assigns an address. 169** 170** Entry selects the register in the pci configuration 171** space, which supplies the size of the region, and 172** receives the physical address. 173** 174** If there is any error, a message is written, and 175** the function returns with zero. 176** Else it returns with a value different to zero. 177** 178**----------------------------------------------------------------- 179*/ 180 181int pci_map_mem (pcici_t tag, u_long entry, u_long * va, u_long * pa); 182 183/*----------------------------------------------------------------- 184** 185** Map a pci device to an io port area. 186** 187** *pa is an "in/out" parameter. 188** If it's 0 on entry, the function assigns an port number.. 189** 190** Entry selects the register in the pci configuration 191** space, which supplies the size of the region, and 192** receives the port number. 193** 194** If there is any error, a message is written, and 195** the function returns with zero. 196** Else it returns with a value different to zero. 197** 198**----------------------------------------------------------------- 199*/ 200 201int pci_map_port(pcici_t tag, u_long entry, u_short * pa); 202 203/*----------------------------------------------------------------- 204** 205** Map a pci interrupt to an isa irq line, 206** and enable the interrupt. 207** 208** func is the interrupt handler, arg is the argument 209** to this function. 210** 211** The maskptr argument should be &bio_imask, 212** &net_imask etc. or NULL. 213** 214** If there is any error, a message is written, and 215** the function returns with zero. 216** Else it returns with a value different to zero. 217** 218** A word of caution for FreeBSD 2.0: 219** 220** We use the register_intr() function. 221** 222** The interrupt line of the selected device is included 223** into the supplied mask: after the corresponding splXXX 224** this drivers interrupts are blocked. 225** 226** But in the interrupt handlers startup code ONLY 227** the interrupt of the driver is blocked, and NOT 228** all interrupts of the spl group. 229** 230** It may be required to additional block the group 231** interrupts by splXXX() inside the interrupt handler. 232** 233** In pre 2.0 kernels we emulate the register_intr 234** function. The emulating function blocks all interrupts 235** of the group in the interrupt handler prefix code. 236** 237**----------------------------------------------------------------- 238*/ 239 240int pci_map_int (pcici_t tag, int (*func)(), void* arg, unsigned * maskptr); 241 242#endif 243