Home | History | Annotate | Line # | Download | only in pci
pcivar.h revision 1.85.2.1
      1  1.85.2.1     rmind /*	$NetBSD: pcivar.h,v 1.85.2.1 2010/05/30 05:17:39 rmind Exp $	*/
      2       1.2       cgd 
      3       1.1   mycroft /*
      4      1.19       cgd  * Copyright (c) 1996, 1997 Christopher G. Demetriou.  All rights reserved.
      5      1.36   mycroft  * Copyright (c) 1994 Charles M. Hannum.  All rights reserved.
      6       1.1   mycroft  *
      7       1.1   mycroft  * Redistribution and use in source and binary forms, with or without
      8       1.1   mycroft  * modification, are permitted provided that the following conditions
      9       1.1   mycroft  * are met:
     10       1.1   mycroft  * 1. Redistributions of source code must retain the above copyright
     11       1.1   mycroft  *    notice, this list of conditions and the following disclaimer.
     12       1.1   mycroft  * 2. Redistributions in binary form must reproduce the above copyright
     13       1.1   mycroft  *    notice, this list of conditions and the following disclaimer in the
     14       1.1   mycroft  *    documentation and/or other materials provided with the distribution.
     15       1.1   mycroft  * 3. All advertising materials mentioning features or use of this software
     16       1.1   mycroft  *    must display the following acknowledgement:
     17      1.36   mycroft  *	This product includes software developed by Charles M. Hannum.
     18       1.1   mycroft  * 4. The name of the author may not be used to endorse or promote products
     19       1.1   mycroft  *    derived from this software without specific prior written permission.
     20       1.1   mycroft  *
     21       1.1   mycroft  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     22       1.1   mycroft  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     23       1.1   mycroft  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     24       1.1   mycroft  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     25       1.1   mycroft  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     26       1.1   mycroft  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     27       1.1   mycroft  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     28       1.1   mycroft  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     29       1.1   mycroft  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     30       1.1   mycroft  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     31       1.1   mycroft  */
     32       1.1   mycroft 
     33      1.12       cgd #ifndef _DEV_PCI_PCIVAR_H_
     34      1.12       cgd #define	_DEV_PCI_PCIVAR_H_
     35      1.12       cgd 
     36       1.1   mycroft /*
     37       1.1   mycroft  * Definitions for PCI autoconfiguration.
     38       1.1   mycroft  *
     39       1.1   mycroft  * This file describes types and functions which are used for PCI
     40       1.1   mycroft  * configuration.  Some of this information is machine-specific, and is
     41      1.14       cgd  * provided by pci_machdep.h.
     42       1.1   mycroft  */
     43       1.1   mycroft 
     44      1.48   thorpej #include <sys/device.h>
     45      1.77  jmcneill #include <sys/pmf.h>
     46      1.75        ad #include <sys/bus.h>
     47      1.14       cgd #include <dev/pci/pcireg.h>
     48  1.85.2.1     rmind #include <dev/pci/pci_verbose.h>
     49      1.12       cgd 
     50      1.14       cgd /*
     51      1.14       cgd  * Structures and definitions needed by the machine-dependent header.
     52      1.14       cgd  */
     53      1.14       cgd struct pcibus_attach_args;
     54      1.50   thorpej struct pci_softc;
     55      1.14       cgd 
     56      1.48   thorpej #ifdef _KERNEL
     57      1.14       cgd /*
     58      1.14       cgd  * Machine-dependent definitions.
     59      1.14       cgd  */
     60      1.38       cgd #include <machine/pci_machdep.h>
     61       1.4       cgd 
     62  1.85.2.1     rmind enum pci_override_idx {
     63  1.85.2.1     rmind 	  PCI_OVERRIDE_CONF_READ		= __BIT(0)
     64  1.85.2.1     rmind 	, PCI_OVERRIDE_CONF_WRITE		= __BIT(1)
     65  1.85.2.1     rmind 	, PCI_OVERRIDE_INTR_MAP			= __BIT(2)
     66  1.85.2.1     rmind 	, PCI_OVERRIDE_INTR_STRING		= __BIT(3)
     67  1.85.2.1     rmind 	, PCI_OVERRIDE_INTR_EVCNT		= __BIT(4)
     68  1.85.2.1     rmind 	, PCI_OVERRIDE_INTR_ESTABLISH		= __BIT(5)
     69  1.85.2.1     rmind 	, PCI_OVERRIDE_INTR_DISESTABLISH	= __BIT(6)
     70  1.85.2.1     rmind 	, PCI_OVERRIDE_MAKE_TAG			= __BIT(7)
     71  1.85.2.1     rmind 	, PCI_OVERRIDE_DECOMPOSE_TAG		= __BIT(8)
     72  1.85.2.1     rmind };
     73  1.85.2.1     rmind 
     74  1.85.2.1     rmind /* Only add new fields to the end of this structure! */
     75  1.85.2.1     rmind struct pci_overrides {
     76  1.85.2.1     rmind 	pcireg_t (*ov_conf_read)(void *, pci_chipset_tag_t, pcitag_t, int);
     77  1.85.2.1     rmind 	void (*ov_conf_write)(void *, pci_chipset_tag_t, pcitag_t, int,
     78  1.85.2.1     rmind 	    pcireg_t);
     79  1.85.2.1     rmind 	int (*ov_intr_map)(void *, struct pci_attach_args *,
     80  1.85.2.1     rmind 	   pci_intr_handle_t *);
     81  1.85.2.1     rmind 	const char *(*ov_intr_string)(void *, pci_chipset_tag_t,
     82  1.85.2.1     rmind 	    pci_intr_handle_t);
     83  1.85.2.1     rmind 	const struct evcnt *(*ov_intr_evcnt)(void *, pci_chipset_tag_t,
     84  1.85.2.1     rmind 	    pci_intr_handle_t);
     85  1.85.2.1     rmind 	void *(*ov_intr_establish)(void *, pci_chipset_tag_t, pci_intr_handle_t,
     86  1.85.2.1     rmind 	    int, int (*)(void *), void *);
     87  1.85.2.1     rmind 	void (*ov_intr_disestablish)(void *, pci_chipset_tag_t, void *);
     88  1.85.2.1     rmind 	pcitag_t (*ov_make_tag)(void *, pci_chipset_tag_t, int, int, int);
     89  1.85.2.1     rmind 	void (*ov_decompose_tag)(void *, pci_chipset_tag_t, pcitag_t,
     90  1.85.2.1     rmind 	    int *, int *, int *);
     91  1.85.2.1     rmind };
     92  1.85.2.1     rmind 
     93      1.11       cgd /*
     94      1.11       cgd  * PCI bus attach arguments.
     95      1.11       cgd  */
     96      1.11       cgd struct pcibus_attach_args {
     97      1.66  drochner 	char		*_pba_busname;	/* XXX placeholder */
     98      1.16   thorpej 	bus_space_tag_t pba_iot;	/* pci i/o space tag */
     99      1.16   thorpej 	bus_space_tag_t pba_memt;	/* pci mem space tag */
    100      1.23   thorpej 	bus_dma_tag_t pba_dmat;		/* DMA tag */
    101      1.56      fvdl 	bus_dma_tag_t pba_dmat64;	/* DMA tag */
    102      1.14       cgd 	pci_chipset_tag_t pba_pc;
    103      1.19       cgd 	int		pba_flags;	/* flags; see below */
    104      1.11       cgd 
    105      1.11       cgd 	int		pba_bus;	/* PCI bus number */
    106      1.14       cgd 
    107      1.14       cgd 	/*
    108      1.50   thorpej 	 * Pointer to the pcitag of our parent bridge.  If there is no
    109      1.50   thorpej 	 * parent bridge, then we assume we are a root bus.
    110      1.50   thorpej 	 */
    111      1.50   thorpej 	pcitag_t	*pba_bridgetag;
    112      1.50   thorpej 
    113      1.50   thorpej 	/*
    114      1.14       cgd 	 * Interrupt swizzling information.  These fields
    115      1.14       cgd 	 * are only used by secondary busses.
    116      1.14       cgd 	 */
    117      1.14       cgd 	u_int		pba_intrswiz;	/* how to swizzle pins */
    118      1.14       cgd 	pcitag_t	pba_intrtag;	/* intr. appears to come from here */
    119      1.11       cgd };
    120      1.11       cgd 
    121      1.11       cgd /*
    122      1.11       cgd  * PCI device attach arguments.
    123      1.11       cgd  */
    124       1.1   mycroft struct pci_attach_args {
    125      1.16   thorpej 	bus_space_tag_t pa_iot;		/* pci i/o space tag */
    126      1.16   thorpej 	bus_space_tag_t pa_memt;	/* pci mem space tag */
    127      1.23   thorpej 	bus_dma_tag_t pa_dmat;		/* DMA tag */
    128      1.56      fvdl 	bus_dma_tag_t pa_dmat64;	/* DMA tag */
    129      1.14       cgd 	pci_chipset_tag_t pa_pc;
    130      1.19       cgd 	int		pa_flags;	/* flags; see below */
    131      1.12       cgd 
    132      1.46    bouyer 	u_int		pa_bus;
    133      1.15       cgd 	u_int		pa_device;
    134      1.15       cgd 	u_int		pa_function;
    135      1.11       cgd 	pcitag_t	pa_tag;
    136      1.11       cgd 	pcireg_t	pa_id, pa_class;
    137      1.14       cgd 
    138      1.14       cgd 	/*
    139      1.14       cgd 	 * Interrupt information.
    140      1.14       cgd 	 *
    141      1.14       cgd 	 * "Intrline" is used on systems whose firmware puts
    142      1.14       cgd 	 * the right routing data into the line register in
    143      1.14       cgd 	 * configuration space.  The rest are used on systems
    144      1.14       cgd 	 * that do not.
    145      1.14       cgd 	 */
    146      1.14       cgd 	u_int		pa_intrswiz;	/* how to swizzle pins if ppb */
    147      1.14       cgd 	pcitag_t	pa_intrtag;	/* intr. appears to come from here */
    148      1.14       cgd 	pci_intr_pin_t	pa_intrpin;	/* intr. appears on this pin */
    149      1.14       cgd 	pci_intr_line_t	pa_intrline;	/* intr. routing information */
    150      1.51  sommerfe 	pci_intr_pin_t  pa_rawintrpin; 	/* unswizzled pin */
    151       1.1   mycroft };
    152      1.19       cgd 
    153      1.19       cgd /*
    154      1.19       cgd  * Flags given in the bus and device attachment args.
    155      1.19       cgd  */
    156      1.19       cgd #define	PCI_FLAGS_IO_ENABLED	0x01		/* I/O space is enabled */
    157      1.19       cgd #define	PCI_FLAGS_MEM_ENABLED	0x02		/* memory space is enabled */
    158      1.41   thorpej #define	PCI_FLAGS_MRL_OKAY	0x04		/* Memory Read Line okay */
    159      1.41   thorpej #define	PCI_FLAGS_MRM_OKAY	0x08		/* Memory Read Multiple okay */
    160      1.41   thorpej #define	PCI_FLAGS_MWI_OKAY	0x10		/* Memory Write and Invalidate
    161      1.41   thorpej 						   okay */
    162      1.85      matt #define	PCI_FLAGS_MSI_OKAY	0x20		/* Message Signaled Interrupts
    163      1.85      matt 						   okay */
    164      1.85      matt #define	PCI_FLAGS_MSIX_OKAY	0x40		/* Message Signaled Interrupts
    165      1.85      matt 						   (Extended) okay */
    166      1.13       cgd 
    167      1.33       cgd /*
    168      1.33       cgd  * PCI device 'quirks'.
    169      1.33       cgd  *
    170      1.33       cgd  * In general strange behaviour which can be handled by a driver (e.g.
    171      1.33       cgd  * a bridge's inability to pass a type of access correctly) should be.
    172      1.33       cgd  * The quirks table should only contain information which impacts
    173      1.33       cgd  * the operation of the MI PCI code and which can't be pushed lower
    174      1.33       cgd  * (e.g. because it's unacceptable to require a driver to be present
    175      1.33       cgd  * for the information to be known).
    176      1.33       cgd  */
    177      1.33       cgd struct pci_quirkdata {
    178      1.33       cgd 	pci_vendor_id_t		vendor;		/* Vendor ID */
    179      1.33       cgd 	pci_product_id_t	product;	/* Product ID */
    180      1.33       cgd 	int			quirks;		/* quirks; see below */
    181      1.33       cgd };
    182      1.33       cgd #define	PCI_QUIRK_MULTIFUNCTION		1
    183      1.59    itojun #define	PCI_QUIRK_MONOFUNCTION		2
    184      1.59    itojun #define	PCI_QUIRK_SKIP_FUNC(n)		(4 << n)
    185      1.59    itojun #define	PCI_QUIRK_SKIP_FUNC0		PCI_QUIRK_SKIP_FUNC(0)
    186      1.59    itojun #define	PCI_QUIRK_SKIP_FUNC1		PCI_QUIRK_SKIP_FUNC(1)
    187      1.59    itojun #define	PCI_QUIRK_SKIP_FUNC2		PCI_QUIRK_SKIP_FUNC(2)
    188      1.59    itojun #define	PCI_QUIRK_SKIP_FUNC3		PCI_QUIRK_SKIP_FUNC(3)
    189      1.59    itojun #define	PCI_QUIRK_SKIP_FUNC4		PCI_QUIRK_SKIP_FUNC(4)
    190      1.59    itojun #define	PCI_QUIRK_SKIP_FUNC5		PCI_QUIRK_SKIP_FUNC(5)
    191      1.59    itojun #define	PCI_QUIRK_SKIP_FUNC6		PCI_QUIRK_SKIP_FUNC(6)
    192      1.59    itojun #define	PCI_QUIRK_SKIP_FUNC7		PCI_QUIRK_SKIP_FUNC(7)
    193      1.48   thorpej 
    194      1.81    dyoung struct pci_conf_state {
    195      1.81    dyoung 	pcireg_t reg[16];
    196      1.81    dyoung };
    197      1.81    dyoung 
    198      1.81    dyoung struct pci_child {
    199      1.81    dyoung 	device_t		c_dev;
    200      1.81    dyoung 	bool			c_psok;
    201      1.81    dyoung 	pcireg_t		c_powerstate;
    202      1.81    dyoung 	struct pci_conf_state	c_conf;
    203      1.81    dyoung };
    204      1.81    dyoung 
    205      1.48   thorpej struct pci_softc {
    206      1.79      cube 	device_t sc_dev;
    207      1.48   thorpej 	bus_space_tag_t sc_iot, sc_memt;
    208      1.51  sommerfe 	bus_dma_tag_t sc_dmat;
    209      1.56      fvdl 	bus_dma_tag_t sc_dmat64;
    210      1.51  sommerfe 	pci_chipset_tag_t sc_pc;
    211      1.48   thorpej 	int sc_bus, sc_maxndevs;
    212      1.50   thorpej 	pcitag_t *sc_bridgetag;
    213      1.48   thorpej 	u_int sc_intrswiz;
    214      1.48   thorpej 	pcitag_t sc_intrtag;
    215      1.48   thorpej 	int sc_flags;
    216      1.64  drochner 	/* accounting of child devices */
    217      1.81    dyoung 	struct pci_child sc_devices[32*8];
    218      1.64  drochner #define PCI_SC_DEVICESC(d, f) sc_devices[(d) * 8 + (f)]
    219      1.48   thorpej };
    220      1.48   thorpej 
    221      1.48   thorpej extern struct cfdriver pci_cd;
    222      1.24       jtk 
    223      1.65  drochner int pcibusprint(void *, const char *);
    224      1.65  drochner 
    225      1.14       cgd /*
    226      1.14       cgd  * Configuration space access and utility functions.  (Note that most,
    227      1.14       cgd  * e.g. make_tag, conf_read, conf_write are declared by pci_machdep.h.)
    228      1.14       cgd  */
    229      1.69     perry int	pci_mapreg_probe(pci_chipset_tag_t, pcitag_t, int, pcireg_t *);
    230      1.69     perry pcireg_t pci_mapreg_type(pci_chipset_tag_t, pcitag_t, int);
    231      1.69     perry int	pci_mapreg_info(pci_chipset_tag_t, pcitag_t, int, pcireg_t,
    232      1.69     perry 	    bus_addr_t *, bus_size_t *, int *);
    233      1.69     perry int	pci_mapreg_map(struct pci_attach_args *, int, pcireg_t, int,
    234      1.20       cgd 	    bus_space_tag_t *, bus_space_handle_t *, bus_addr_t *,
    235      1.69     perry 	    bus_size_t *);
    236      1.83       bjs int	pci_mapreg_submap(struct pci_attach_args *, int, pcireg_t, int,
    237      1.83       bjs 	    bus_size_t, bus_size_t, bus_space_tag_t *, bus_space_handle_t *,
    238      1.83       bjs 	    bus_addr_t *, bus_size_t *);
    239      1.37  drochner 
    240      1.71   gdamore int pci_find_rom(struct pci_attach_args *, bus_space_tag_t, bus_space_handle_t,
    241      1.71   gdamore 	    int, bus_space_handle_t *, bus_size_t *);
    242      1.71   gdamore 
    243      1.69     perry int pci_get_capability(pci_chipset_tag_t, pcitag_t, int, int *, pcireg_t *);
    244      1.14       cgd 
    245      1.14       cgd /*
    246      1.14       cgd  * Helper functions for autoconfiguration.
    247      1.14       cgd  */
    248      1.49   thorpej int	pci_probe_device(struct pci_softc *, pcitag_t tag,
    249      1.49   thorpej 	    int (*)(struct pci_attach_args *), struct pci_attach_args *);
    250      1.69     perry void	pci_devinfo(pcireg_t, pcireg_t, int, char *, size_t);
    251      1.69     perry void	pci_conf_print(pci_chipset_tag_t, pcitag_t,
    252      1.69     perry 	    void (*)(pci_chipset_tag_t, pcitag_t, const pcireg_t *));
    253      1.33       cgd const struct pci_quirkdata *
    254      1.69     perry 	pci_lookup_quirkdata(pci_vendor_id_t, pci_product_id_t);
    255      1.35  augustss 
    256      1.35  augustss /*
    257      1.48   thorpej  * Helper functions for user access to the PCI bus.
    258      1.48   thorpej  */
    259      1.48   thorpej struct proc;
    260      1.74  christos int	pci_devioctl(pci_chipset_tag_t, pcitag_t, u_long, void *,
    261      1.70  christos 	    int flag, struct lwp *);
    262      1.53  tshiozak 
    263      1.53  tshiozak /*
    264      1.53  tshiozak  * Power Management (PCI 2.2)
    265      1.53  tshiozak  */
    266      1.53  tshiozak 
    267      1.53  tshiozak #define PCI_PWR_D0	0
    268      1.53  tshiozak #define PCI_PWR_D1	1
    269      1.53  tshiozak #define PCI_PWR_D2	2
    270      1.53  tshiozak #define PCI_PWR_D3	3
    271      1.69     perry int	pci_powerstate(pci_chipset_tag_t, pcitag_t, const int *, int *);
    272      1.55   thorpej 
    273      1.55   thorpej /*
    274      1.55   thorpej  * Vital Product Data (PCI 2.2)
    275      1.55   thorpej  */
    276      1.69     perry int	pci_vpd_read(pci_chipset_tag_t, pcitag_t, int, int, pcireg_t *);
    277      1.69     perry int	pci_vpd_write(pci_chipset_tag_t, pcitag_t, int, int, pcireg_t *);
    278      1.48   thorpej 
    279      1.48   thorpej /*
    280      1.35  augustss  * Misc.
    281      1.35  augustss  */
    282      1.47      fvdl int	pci_find_device(struct pci_attach_args *pa,
    283      1.47      fvdl 			int (*match)(struct pci_attach_args *));
    284      1.56      fvdl int	pci_dma64_available(struct pci_attach_args *);
    285      1.68  jmcneill void	pci_conf_capture(pci_chipset_tag_t, pcitag_t, struct pci_conf_state *);
    286      1.68  jmcneill void	pci_conf_restore(pci_chipset_tag_t, pcitag_t, struct pci_conf_state *);
    287      1.72  christos int	pci_get_powerstate(pci_chipset_tag_t, pcitag_t, pcireg_t *);
    288      1.72  christos int	pci_set_powerstate(pci_chipset_tag_t, pcitag_t, pcireg_t);
    289      1.78    dyoung int	pci_activate(pci_chipset_tag_t, pcitag_t, device_t,
    290      1.78    dyoung     int (*)(pci_chipset_tag_t, pcitag_t, device_t, pcireg_t));
    291      1.78    dyoung int	pci_activate_null(pci_chipset_tag_t, pcitag_t, device_t, pcireg_t);
    292  1.85.2.1     rmind int	pci_chipset_tag_create(pci_chipset_tag_t, uint64_t,
    293  1.85.2.1     rmind 	                       const struct pci_overrides *,
    294  1.85.2.1     rmind 	                       void *, pci_chipset_tag_t *);
    295  1.85.2.1     rmind void	pci_chipset_tag_destroy(pci_chipset_tag_t);
    296      1.47      fvdl 
    297      1.82        ad /*
    298      1.82        ad  * Device abstraction for inheritance by elanpci(4), for example.
    299      1.82        ad  */
    300      1.80    dyoung int pcimatch(device_t, cfdata_t, void *);
    301      1.80    dyoung void pciattach(device_t, device_t, void *);
    302      1.80    dyoung int pcidetach(device_t, int);
    303      1.80    dyoung void pcidevdetached(device_t, device_t);
    304      1.80    dyoung int pcirescan(device_t, const char *, const int *);
    305      1.80    dyoung 
    306      1.82        ad /*
    307      1.82        ad  * Interrupts.
    308      1.82        ad  */
    309      1.82        ad #define	PCI_INTR_MPSAFE		1
    310      1.82        ad 
    311      1.82        ad int	pci_intr_setattr(pci_chipset_tag_t, pci_intr_handle_t *, int, uint64_t);
    312      1.82        ad 
    313      1.48   thorpej #endif /* _KERNEL */
    314      1.12       cgd 
    315      1.12       cgd #endif /* _DEV_PCI_PCIVAR_H_ */
    316