xref: /freebsd/sys/dev/pci/pci_private.h (revision 9dbf5b0e6876d8c93890754bcc9c748339de79c0)
1098ca2bdSWarner Losh /*-
24d846d26SWarner Losh  * SPDX-License-Identifier: BSD-2-Clause
3718cf2ccSPedro F. Giffuni  *
47ba175acSWarner Losh  * Copyright (c) 1997, Stefan Esser <se@freebsd.org>
57ba175acSWarner Losh  * Copyright (c) 2000, Michael Smith <msmith@freebsd.org>
67ba175acSWarner Losh  * Copyright (c) 2000, BSDi
77ba175acSWarner Losh  * All rights reserved.
87ba175acSWarner Losh  *
97ba175acSWarner Losh  * Redistribution and use in source and binary forms, with or without
107ba175acSWarner Losh  * modification, are permitted provided that the following conditions
117ba175acSWarner Losh  * are met:
127ba175acSWarner Losh  * 1. Redistributions of source code must retain the above copyright
137ba175acSWarner Losh  *    notice unmodified, this list of conditions, and the following
147ba175acSWarner Losh  *    disclaimer.
157ba175acSWarner Losh  * 2. Redistributions in binary form must reproduce the above copyright
167ba175acSWarner Losh  *    notice, this list of conditions and the following disclaimer in the
177ba175acSWarner Losh  *    documentation and/or other materials provided with the distribution.
187ba175acSWarner Losh  *
197ba175acSWarner Losh  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
207ba175acSWarner Losh  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
217ba175acSWarner Losh  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
227ba175acSWarner Losh  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
237ba175acSWarner Losh  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
247ba175acSWarner Losh  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
257ba175acSWarner Losh  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
267ba175acSWarner Losh  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
277ba175acSWarner Losh  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
287ba175acSWarner Losh  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
297ba175acSWarner Losh  *
307ba175acSWarner Losh  */
317ba175acSWarner Losh 
327ba175acSWarner Losh #ifndef _PCI_PRIVATE_H_
337ba175acSWarner Losh #define	_PCI_PRIVATE_H_
347ba175acSWarner Losh 
357ba175acSWarner Losh /*
367ba175acSWarner Losh  * Export definitions of the pci bus so that we can more easily share
37db4fcadfSConrad Meyer  * it with "subclass" buses.
387ba175acSWarner Losh  */
395aa58b3eSJohn Baldwin DECLARE_CLASS(pci_driver);
4042dbeaeeSJohn Baldwin 
411b1596a3SJohn Baldwin struct pci_softc {
421b1596a3SJohn Baldwin 	bus_dma_tag_t sc_dma_tag;
434edef187SJohn Baldwin #ifdef PCI_RES_BUS
444edef187SJohn Baldwin 	struct resource *sc_bus;
454edef187SJohn Baldwin #endif
461b1596a3SJohn Baldwin };
471b1596a3SJohn Baldwin 
4862508c53SJohn Baldwin extern int 	pci_do_power_resume;
49f3e0b109SJung-uk Kim extern int 	pci_do_power_suspend;
5062508c53SJohn Baldwin 
516cd99ae8SJohn Baldwin void		pci_add_children(device_t dev, int domain, int busno);
5242dbeaeeSJohn Baldwin void		pci_add_child(device_t bus, struct pci_devinfo *dinfo);
536cd99ae8SJohn Baldwin device_t	pci_add_iov_child(device_t bus, device_t pf, uint16_t rid,
546cd99ae8SJohn Baldwin 		    uint16_t vid, uint16_t did);
55a9883bc8SWarner Losh void		pci_add_resources(device_t bus, device_t dev, int force,
56a9883bc8SWarner Losh 		    uint32_t prefetchmask);
574d185754SWojciech Macek void		pci_add_resources_ea(device_t bus, device_t dev, int alloc_iov);
586cd99ae8SJohn Baldwin struct pci_devinfo *pci_alloc_devinfo_method(device_t dev);
5921d31962SJohn Baldwin int		pci_attach(device_t dev);
601b1596a3SJohn Baldwin int		pci_attach_common(device_t dev);
6121d31962SJohn Baldwin int		pci_detach(device_t dev);
623d0338a0SJohn Baldwin int		pci_rescan_method(device_t dev);
63cd8b53edSWarner Losh void		pci_driver_added(device_t dev, driver_t *driver);
644d185754SWojciech Macek int		pci_ea_is_enabled(device_t dev, int rid);
657ba175acSWarner Losh int		pci_print_child(device_t dev, device_t child);
667ba175acSWarner Losh void		pci_probe_nomatch(device_t dev, device_t child);
677ba175acSWarner Losh int		pci_read_ivar(device_t dev, device_t child, int which,
687ba175acSWarner Losh 		    uintptr_t *result);
697ba175acSWarner Losh int		pci_write_ivar(device_t dev, device_t child, int which,
707ba175acSWarner Losh 		    uintptr_t value);
71e706f7f0SJohn Baldwin int		pci_setup_intr(device_t dev, device_t child,
72e706f7f0SJohn Baldwin 		    struct resource *irq, int flags, driver_filter_t *filter,
73e706f7f0SJohn Baldwin 		    driver_intr_t *intr, void *arg, void **cookiep);
74e706f7f0SJohn Baldwin int		pci_teardown_intr(device_t dev, device_t child,
75e706f7f0SJohn Baldwin 		    struct resource *irq, void *cookie);
76667dc26eSJohn-Mark Gurney int		pci_get_vpd_ident_method(device_t dev, device_t child,
77667dc26eSJohn-Mark Gurney 		    const char **identptr);
78667dc26eSJohn-Mark Gurney int		pci_get_vpd_readonly_method(device_t dev, device_t child,
79667dc26eSJohn-Mark Gurney 		    const char *kw, const char **vptr);
807ba175acSWarner Losh int		pci_set_powerstate_method(device_t dev, device_t child,
817ba175acSWarner Losh 		    int state);
827ba175acSWarner Losh int		pci_get_powerstate_method(device_t dev, device_t child);
83b0cb115fSWarner Losh uint32_t	pci_read_config_method(device_t dev, device_t child,
847ba175acSWarner Losh 		    int reg, int width);
857ba175acSWarner Losh void		pci_write_config_method(device_t dev, device_t child,
86b0cb115fSWarner Losh 		    int reg, uint32_t val, int width);
87c047e5b1SMatthew N. Dodd int		pci_enable_busmaster_method(device_t dev, device_t child);
88c047e5b1SMatthew N. Dodd int		pci_disable_busmaster_method(device_t dev, device_t child);
89c047e5b1SMatthew N. Dodd int		pci_enable_io_method(device_t dev, device_t child, int space);
90c047e5b1SMatthew N. Dodd int		pci_disable_io_method(device_t dev, device_t child, int space);
91c668000bSJohn Baldwin int		pci_find_cap_method(device_t dev, device_t child,
92c668000bSJohn Baldwin 		    int capability, int *capreg);
937a16dacdSBryan Venteicher int		pci_find_next_cap_method(device_t dev, device_t child,
947a16dacdSBryan Venteicher 		    int capability, int start, int *capreg);
954f9795b9SJohn Baldwin int		pci_find_extcap_method(device_t dev, device_t child,
964f9795b9SJohn Baldwin 		    int capability, int *capreg);
977a16dacdSBryan Venteicher int		pci_find_next_extcap_method(device_t dev, device_t child,
987a16dacdSBryan Venteicher 		    int capability, int start, int *capreg);
99c668000bSJohn Baldwin int		pci_find_htcap_method(device_t dev, device_t child,
100c668000bSJohn Baldwin 		    int capability, int *capreg);
1017a16dacdSBryan Venteicher int		pci_find_next_htcap_method(device_t dev, device_t child,
1027a16dacdSBryan Venteicher 		    int capability, int start, int *capreg);
1039bf4c9c1SJohn Baldwin int		pci_alloc_msi_method(device_t dev, device_t child, int *count);
1045fe82bcaSJohn Baldwin int		pci_alloc_msix_method(device_t dev, device_t child, int *count);
105073bf9ddSRoger Pau Monné void		pci_enable_msi_method(device_t dev, device_t child,
106073bf9ddSRoger Pau Monné 		    uint64_t address, uint16_t data);
107073bf9ddSRoger Pau Monné void		pci_enable_msix_method(device_t dev, device_t child,
108073bf9ddSRoger Pau Monné 		    u_int index, uint64_t address, uint32_t data);
109073bf9ddSRoger Pau Monné void		pci_disable_msi_method(device_t dev, device_t child);
1105fe82bcaSJohn Baldwin int		pci_remap_msix_method(device_t dev, device_t child,
111e706f7f0SJohn Baldwin 		    int count, const u_int *vectors);
1129bf4c9c1SJohn Baldwin int		pci_release_msi_method(device_t dev, device_t child);
1139bf4c9c1SJohn Baldwin int		pci_msi_count_method(device_t dev, device_t child);
1145fe82bcaSJohn Baldwin int		pci_msix_count_method(device_t dev, device_t child);
115ce204e1bSJohn Baldwin int		pci_msix_pba_bar_method(device_t dev, device_t child);
116ce204e1bSJohn Baldwin int		pci_msix_table_bar_method(device_t dev, device_t child);
1177ba175acSWarner Losh struct resource	*pci_alloc_resource(device_t dev, device_t child,
1182dd1bdf1SJustin Hibbits 		    int type, int *rid, rman_res_t start, rman_res_t end,
1192dd1bdf1SJustin Hibbits 		    rman_res_t count, u_int flags);
120*9dbf5b0eSJohn Baldwin int		pci_release_resource(device_t dev, device_t child,
121*9dbf5b0eSJohn Baldwin 		    struct resource *r);
1222baed46eSJohn Baldwin int		pci_activate_resource(device_t dev, device_t child,
1232baed46eSJohn Baldwin 		    struct resource *r);
1242baed46eSJohn Baldwin int		pci_deactivate_resource(device_t dev, device_t child,
1252baed46eSJohn Baldwin 		    struct resource *r);
1267ba175acSWarner Losh void		pci_delete_resource(device_t dev, device_t child,
1277ba175acSWarner Losh 		    int type, int rid);
1287ba175acSWarner Losh struct resource_list *pci_get_resource_list (device_t dev, device_t child);
1296cd99ae8SJohn Baldwin struct pci_devinfo *pci_read_device(device_t pcib, device_t bus, int d, int b,
1306cd99ae8SJohn Baldwin 		    int s, int f);
1317ba175acSWarner Losh void		pci_print_verbose(struct pci_devinfo *dinfo);
1327ba175acSWarner Losh int		pci_freecfg(struct pci_devinfo *dinfo);
133496dfa89SJohn Baldwin void		pci_child_deleted(device_t dev, device_t child);
134e35ce1f2SJohn Baldwin void		pci_child_detached(device_t dev, device_t child);
135ddfc9c4cSWarner Losh int		pci_child_location_method(device_t cbdev, device_t child,
136ddfc9c4cSWarner Losh 		    struct sbuf *sb);
137ddfc9c4cSWarner Losh int		pci_child_pnpinfo_method(device_t cbdev, device_t child,
138ddfc9c4cSWarner Losh 		    struct sbuf *sb);
139d0a20e40SWarner Losh int		pci_get_device_path_method(device_t dev, device_t child,
140d0a20e40SWarner Losh 		    const char *locator, struct sbuf *sb);
1413920999dSThomas Moestl int		pci_assign_interrupt_method(device_t dev, device_t child);
142526b5e65SMitsuru IWASAKI int		pci_resume(device_t dev);
143a1c16348SJustin Hibbits int		pci_resume_child(device_t dev, device_t child);
144a1c16348SJustin Hibbits int		pci_suspend_child(device_t dev, device_t child);
145c54a713fSKonstantin Belousov bus_dma_tag_t pci_get_dma_tag(device_t bus, device_t dev);
146cd407ca2SRoger Pau Monné void		pci_child_added_method(device_t dev, device_t child);
1477a528f5cSWarner Losh 
1487a528f5cSWarner Losh /** Restore the config register state.  The state must be previously
1497a528f5cSWarner Losh  * saved with pci_cfg_save.  However, the pci bus driver takes care of
1507a528f5cSWarner Losh  * that.  This function will also return the device to PCI_POWERSTATE_D0
1517a528f5cSWarner Losh  * if it is currently in a lower power mode.
1527a528f5cSWarner Losh  */
153c3c08f30SWarner Losh void		pci_cfg_restore(device_t, struct pci_devinfo *);
1547a528f5cSWarner Losh 
1557a528f5cSWarner Losh /** Save the config register state.  Optionally set the power state to D3
1567a528f5cSWarner Losh  * if the third argument is non-zero.
1577a528f5cSWarner Losh  */
158c3c08f30SWarner Losh void		pci_cfg_save(device_t, struct pci_devinfo *, int);
159d6592688SJohn Baldwin 
1605ce88dc6SRyan Stone int		pci_mapsize(uint64_t testval);
1615ce88dc6SRyan Stone void		pci_read_bar(device_t dev, int reg, pci_addr_t *mapp,
1625ce88dc6SRyan Stone 		    pci_addr_t *testvalp, int *bar64);
1635ce88dc6SRyan Stone struct pci_map *pci_add_bar(device_t dev, int reg, pci_addr_t value,
1645ce88dc6SRyan Stone 		    pci_addr_t size);
1655ce88dc6SRyan Stone 
16682098c8bSJessica Clarke struct resource *pci_reserve_map(device_t dev, device_t child, int type,
16782098c8bSJessica Clarke 		    int *rid, rman_res_t start, rman_res_t end,
16882098c8bSJessica Clarke 		    rman_res_t count, u_int num, u_int flags);
16982098c8bSJessica Clarke 
1705ce88dc6SRyan Stone struct resource *pci_alloc_multi_resource(device_t dev, device_t child,
1712dd1bdf1SJustin Hibbits 		    int type, int *rid, rman_res_t start, rman_res_t end,
1722dd1bdf1SJustin Hibbits 		    rman_res_t count, u_long num, u_int flags);
1735ce88dc6SRyan Stone 
1741191f715SRyan Stone int		pci_iov_attach_method(device_t bus, device_t dev,
1750aee83ccSJohn Baldwin 		    struct nvlist *pf_schema, struct nvlist *vf_schema,
1760aee83ccSJohn Baldwin 		    const char *name);
1779bfb1e36SRyan Stone int		pci_iov_detach_method(device_t bus, device_t dev);
1789bfb1e36SRyan Stone 
1799bfb1e36SRyan Stone device_t	pci_create_iov_child_method(device_t bus, device_t pf,
1809bfb1e36SRyan Stone 		    uint16_t rid, uint16_t vid, uint16_t did);
1819bfb1e36SRyan Stone 
182e9309eacSRyan Stone struct resource *pci_vf_alloc_mem_resource(device_t dev, device_t child,
1832dd1bdf1SJustin Hibbits 		    int *rid, rman_res_t start, rman_res_t end,
1842dd1bdf1SJustin Hibbits 		    rman_res_t count, u_int flags);
185e9309eacSRyan Stone int		pci_vf_release_mem_resource(device_t dev, device_t child,
186*9dbf5b0eSJohn Baldwin 		    struct resource *r);
1877ba175acSWarner Losh #endif /* _PCI_PRIVATE_H_ */
188