xref: /freebsd/sys/dev/pci/pci_private.h (revision 104ee24349c033b63a50bd89ddc431a0d3ef9902)
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 	struct resource *sc_bus;
441b1596a3SJohn Baldwin };
451b1596a3SJohn Baldwin 
4662508c53SJohn Baldwin extern int 	pci_do_power_resume;
47f3e0b109SJung-uk Kim extern int 	pci_do_power_suspend;
4862508c53SJohn Baldwin 
490f1d148cSJohn Baldwin 
500f1d148cSJohn Baldwin device_attach_t		pci_attach;
510f1d148cSJohn Baldwin device_detach_t		pci_detach;
520f1d148cSJohn Baldwin device_resume_t		pci_resume;
530f1d148cSJohn Baldwin 
540f1d148cSJohn Baldwin bus_print_child_t	pci_print_child;
550f1d148cSJohn Baldwin bus_probe_nomatch_t	pci_probe_nomatch;
560f1d148cSJohn Baldwin bus_read_ivar_t		pci_read_ivar;
570f1d148cSJohn Baldwin bus_write_ivar_t	pci_write_ivar;
580f1d148cSJohn Baldwin bus_driver_added_t	pci_driver_added;
590f1d148cSJohn Baldwin bus_setup_intr_t	pci_setup_intr;
600f1d148cSJohn Baldwin bus_teardown_intr_t	pci_teardown_intr;
610f1d148cSJohn Baldwin 
620f1d148cSJohn Baldwin bus_get_dma_tag_t	pci_get_dma_tag;
630f1d148cSJohn Baldwin bus_get_resource_list_t	pci_get_resource_list;
640f1d148cSJohn Baldwin bus_delete_resource_t	pci_delete_resource;
650f1d148cSJohn Baldwin bus_alloc_resource_t	pci_alloc_resource;
66*871b33adSJohn Baldwin bus_adjust_resource_t	pci_adjust_resource;
670f1d148cSJohn Baldwin bus_release_resource_t	pci_release_resource;
680f1d148cSJohn Baldwin bus_activate_resource_t	pci_activate_resource;
690f1d148cSJohn Baldwin bus_deactivate_resource_t pci_deactivate_resource;
70*871b33adSJohn Baldwin bus_map_resource_t	pci_map_resource;
71*871b33adSJohn Baldwin bus_unmap_resource_t	pci_unmap_resource;
720f1d148cSJohn Baldwin bus_child_deleted_t	pci_child_deleted;
730f1d148cSJohn Baldwin bus_child_detached_t	pci_child_detached;
740f1d148cSJohn Baldwin bus_child_pnpinfo_t	pci_child_pnpinfo_method;
750f1d148cSJohn Baldwin bus_child_location_t	pci_child_location_method;
760f1d148cSJohn Baldwin bus_get_device_path_t	pci_get_device_path_method;
770f1d148cSJohn Baldwin bus_suspend_child_t	pci_suspend_child;
780f1d148cSJohn Baldwin bus_resume_child_t	pci_resume_child;
790f1d148cSJohn Baldwin bus_rescan_t		pci_rescan_method;
800f1d148cSJohn Baldwin 
810f1d148cSJohn Baldwin pci_read_config_t	pci_read_config_method;
820f1d148cSJohn Baldwin pci_write_config_t	pci_write_config_method;
830f1d148cSJohn Baldwin pci_enable_busmaster_t	pci_enable_busmaster_method;
840f1d148cSJohn Baldwin pci_disable_busmaster_t	pci_disable_busmaster_method;
850f1d148cSJohn Baldwin pci_enable_io_t		pci_enable_io_method;
860f1d148cSJohn Baldwin pci_disable_io_t	pci_disable_io_method;
870f1d148cSJohn Baldwin pci_get_vpd_ident_t	pci_get_vpd_ident_method;
880f1d148cSJohn Baldwin pci_get_vpd_readonly_t	pci_get_vpd_readonly_method;
890f1d148cSJohn Baldwin pci_get_powerstate_t	pci_get_powerstate_method;
900f1d148cSJohn Baldwin pci_set_powerstate_t	pci_set_powerstate_method;
910f1d148cSJohn Baldwin pci_assign_interrupt_t	pci_assign_interrupt_method;
920f1d148cSJohn Baldwin pci_find_cap_t		pci_find_cap_method;
930f1d148cSJohn Baldwin pci_find_next_cap_t	pci_find_next_cap_method;
940f1d148cSJohn Baldwin pci_find_extcap_t	pci_find_extcap_method;
950f1d148cSJohn Baldwin pci_find_next_extcap_t	pci_find_next_extcap_method;
960f1d148cSJohn Baldwin pci_find_htcap_t	pci_find_htcap_method;
970f1d148cSJohn Baldwin pci_find_next_htcap_t	pci_find_next_htcap_method;
980f1d148cSJohn Baldwin pci_alloc_msi_t		pci_alloc_msi_method;
990f1d148cSJohn Baldwin pci_alloc_msix_t	pci_alloc_msix_method;
1000f1d148cSJohn Baldwin pci_enable_msi_t	pci_enable_msi_method;
1010f1d148cSJohn Baldwin pci_enable_msix_t	pci_enable_msix_method;
1020f1d148cSJohn Baldwin pci_disable_msi_t	pci_disable_msi_method;
1030f1d148cSJohn Baldwin pci_remap_msix_t	pci_remap_msix_method;
1040f1d148cSJohn Baldwin pci_release_msi_t	pci_release_msi_method;
1050f1d148cSJohn Baldwin pci_msi_count_t		pci_msi_count_method;
1060f1d148cSJohn Baldwin pci_msix_count_t	pci_msix_count_method;
1070f1d148cSJohn Baldwin pci_msix_pba_bar_t	pci_msix_pba_bar_method;
1080f1d148cSJohn Baldwin pci_msix_table_bar_t	pci_msix_table_bar_method;
1090f1d148cSJohn Baldwin pci_alloc_devinfo_t	pci_alloc_devinfo_method;
1100f1d148cSJohn Baldwin pci_child_added_t	pci_child_added_method;
1110f1d148cSJohn Baldwin #ifdef PCI_IOV
1120f1d148cSJohn Baldwin pci_iov_attach_t	pci_iov_attach_method;
1130f1d148cSJohn Baldwin pci_iov_detach_t	pci_iov_detach_method;
1140f1d148cSJohn Baldwin pci_create_iov_child_t	pci_create_iov_child_method;
1150f1d148cSJohn Baldwin #endif
1160f1d148cSJohn Baldwin 
1176cd99ae8SJohn Baldwin void		pci_add_children(device_t dev, int domain, int busno);
11842dbeaeeSJohn Baldwin void		pci_add_child(device_t bus, struct pci_devinfo *dinfo);
1196cd99ae8SJohn Baldwin device_t	pci_add_iov_child(device_t bus, device_t pf, uint16_t rid,
1206cd99ae8SJohn Baldwin 		    uint16_t vid, uint16_t did);
121a9883bc8SWarner Losh void		pci_add_resources(device_t bus, device_t dev, int force,
122a9883bc8SWarner Losh 		    uint32_t prefetchmask);
1234d185754SWojciech Macek void		pci_add_resources_ea(device_t bus, device_t dev, int alloc_iov);
1241b1596a3SJohn Baldwin int		pci_attach_common(device_t dev);
1254d185754SWojciech Macek int		pci_ea_is_enabled(device_t dev, int rid);
1266cd99ae8SJohn Baldwin struct pci_devinfo *pci_read_device(device_t pcib, device_t bus, int d, int b,
1276cd99ae8SJohn Baldwin 		    int s, int f);
1287ba175acSWarner Losh void		pci_print_verbose(struct pci_devinfo *dinfo);
1297ba175acSWarner Losh int		pci_freecfg(struct pci_devinfo *dinfo);
1307a528f5cSWarner Losh 
1317a528f5cSWarner Losh /** Restore the config register state.  The state must be previously
1327a528f5cSWarner Losh  * saved with pci_cfg_save.  However, the pci bus driver takes care of
1337a528f5cSWarner Losh  * that.  This function will also return the device to PCI_POWERSTATE_D0
1347a528f5cSWarner Losh  * if it is currently in a lower power mode.
1357a528f5cSWarner Losh  */
136c3c08f30SWarner Losh void		pci_cfg_restore(device_t, struct pci_devinfo *);
1377a528f5cSWarner Losh 
1387a528f5cSWarner Losh /** Save the config register state.  Optionally set the power state to D3
1397a528f5cSWarner Losh  * if the third argument is non-zero.
1407a528f5cSWarner Losh  */
141c3c08f30SWarner Losh void		pci_cfg_save(device_t, struct pci_devinfo *, int);
142d6592688SJohn Baldwin 
1435ce88dc6SRyan Stone int		pci_mapsize(uint64_t testval);
1445ce88dc6SRyan Stone void		pci_read_bar(device_t dev, int reg, pci_addr_t *mapp,
1455ce88dc6SRyan Stone 		    pci_addr_t *testvalp, int *bar64);
1465ce88dc6SRyan Stone struct pci_map *pci_add_bar(device_t dev, int reg, pci_addr_t value,
1475ce88dc6SRyan Stone 		    pci_addr_t size);
1485ce88dc6SRyan Stone 
14982098c8bSJessica Clarke struct resource *pci_reserve_map(device_t dev, device_t child, int type,
15082098c8bSJessica Clarke 		    int *rid, rman_res_t start, rman_res_t end,
15182098c8bSJessica Clarke 		    rman_res_t count, u_int num, u_int flags);
15282098c8bSJessica Clarke 
1535ce88dc6SRyan Stone struct resource *pci_alloc_multi_resource(device_t dev, device_t child,
1542dd1bdf1SJustin Hibbits 		    int type, int *rid, rman_res_t start, rman_res_t end,
1552dd1bdf1SJustin Hibbits 		    rman_res_t count, u_long num, u_int flags);
1565ce88dc6SRyan Stone 
157e9309eacSRyan Stone struct resource *pci_vf_alloc_mem_resource(device_t dev, device_t child,
1582dd1bdf1SJustin Hibbits 		    int *rid, rman_res_t start, rman_res_t end,
1592dd1bdf1SJustin Hibbits 		    rman_res_t count, u_int flags);
160e9309eacSRyan Stone int		pci_vf_release_mem_resource(device_t dev, device_t child,
1619dbf5b0eSJohn Baldwin 		    struct resource *r);
162*871b33adSJohn Baldwin int		pci_vf_activate_mem_resource(device_t dev, device_t child,
163*871b33adSJohn Baldwin 		    struct resource *r);
164*871b33adSJohn Baldwin int		pci_vf_deactivate_mem_resource(device_t dev, device_t child,
165*871b33adSJohn Baldwin 		    struct resource *r);
166*871b33adSJohn Baldwin int		pci_vf_adjust_mem_resource(device_t dev, device_t child,
167*871b33adSJohn Baldwin 		    struct resource *r, rman_res_t start, rman_res_t end);
168*871b33adSJohn Baldwin int		pci_vf_map_mem_resource(device_t dev, device_t child,
169*871b33adSJohn Baldwin 		    struct resource *r, struct resource_map_request *argsp,
170*871b33adSJohn Baldwin 		    struct resource_map *map);
171*871b33adSJohn Baldwin int		pci_vf_unmap_mem_resource(device_t dev, device_t child,
172*871b33adSJohn Baldwin 		    struct resource *r, struct resource_map *map);
173*871b33adSJohn Baldwin 
1747ba175acSWarner Losh #endif /* _PCI_PRIVATE_H_ */
175