1 /*- 2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD 3 * 4 * Copyright (c) 1997, Stefan Esser <se@freebsd.org> 5 * Copyright (c) 2000, Michael Smith <msmith@freebsd.org> 6 * Copyright (c) 2000, BSDi 7 * All rights reserved. 8 * 9 * Redistribution and use in source and binary forms, with or without 10 * modification, are permitted provided that the following conditions 11 * are met: 12 * 1. Redistributions of source code must retain the above copyright 13 * notice unmodified, this list of conditions, and the following 14 * disclaimer. 15 * 2. Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in the 17 * documentation and/or other materials provided with the distribution. 18 * 19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 20 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 21 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 22 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 23 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 24 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 28 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 * 30 * $FreeBSD$ 31 * 32 */ 33 34 #ifndef _PCI_PRIVATE_H_ 35 #define _PCI_PRIVATE_H_ 36 37 /* 38 * Export definitions of the pci bus so that we can more easily share 39 * it with "subclass" buses. 40 */ 41 DECLARE_CLASS(pci_driver); 42 43 struct pci_softc { 44 bus_dma_tag_t sc_dma_tag; 45 #ifdef PCI_RES_BUS 46 struct resource *sc_bus; 47 #endif 48 }; 49 50 extern int pci_do_power_resume; 51 extern int pci_do_power_suspend; 52 53 void pci_add_children(device_t dev, int domain, int busno); 54 void pci_add_child(device_t bus, struct pci_devinfo *dinfo); 55 device_t pci_add_iov_child(device_t bus, device_t pf, uint16_t rid, 56 uint16_t vid, uint16_t did); 57 void pci_add_resources(device_t bus, device_t dev, int force, 58 uint32_t prefetchmask); 59 void pci_add_resources_ea(device_t bus, device_t dev, int alloc_iov); 60 struct pci_devinfo *pci_alloc_devinfo_method(device_t dev); 61 int pci_attach(device_t dev); 62 int pci_attach_common(device_t dev); 63 int pci_detach(device_t dev); 64 int pci_rescan_method(device_t dev); 65 void pci_driver_added(device_t dev, driver_t *driver); 66 int pci_ea_is_enabled(device_t dev, int rid); 67 int pci_print_child(device_t dev, device_t child); 68 void pci_probe_nomatch(device_t dev, device_t child); 69 int pci_read_ivar(device_t dev, device_t child, int which, 70 uintptr_t *result); 71 int pci_write_ivar(device_t dev, device_t child, int which, 72 uintptr_t value); 73 int pci_setup_intr(device_t dev, device_t child, 74 struct resource *irq, int flags, driver_filter_t *filter, 75 driver_intr_t *intr, void *arg, void **cookiep); 76 int pci_teardown_intr(device_t dev, device_t child, 77 struct resource *irq, void *cookie); 78 int pci_get_vpd_ident_method(device_t dev, device_t child, 79 const char **identptr); 80 int pci_get_vpd_readonly_method(device_t dev, device_t child, 81 const char *kw, const char **vptr); 82 int pci_set_powerstate_method(device_t dev, device_t child, 83 int state); 84 int pci_get_powerstate_method(device_t dev, device_t child); 85 uint32_t pci_read_config_method(device_t dev, device_t child, 86 int reg, int width); 87 void pci_write_config_method(device_t dev, device_t child, 88 int reg, uint32_t val, int width); 89 int pci_enable_busmaster_method(device_t dev, device_t child); 90 int pci_disable_busmaster_method(device_t dev, device_t child); 91 int pci_enable_io_method(device_t dev, device_t child, int space); 92 int pci_disable_io_method(device_t dev, device_t child, int space); 93 int pci_find_cap_method(device_t dev, device_t child, 94 int capability, int *capreg); 95 int pci_find_next_cap_method(device_t dev, device_t child, 96 int capability, int start, int *capreg); 97 int pci_find_extcap_method(device_t dev, device_t child, 98 int capability, int *capreg); 99 int pci_find_next_extcap_method(device_t dev, device_t child, 100 int capability, int start, int *capreg); 101 int pci_find_htcap_method(device_t dev, device_t child, 102 int capability, int *capreg); 103 int pci_find_next_htcap_method(device_t dev, device_t child, 104 int capability, int start, int *capreg); 105 int pci_alloc_msi_method(device_t dev, device_t child, int *count); 106 int pci_alloc_msix_method(device_t dev, device_t child, int *count); 107 void pci_enable_msi_method(device_t dev, device_t child, 108 uint64_t address, uint16_t data); 109 void pci_enable_msix_method(device_t dev, device_t child, 110 u_int index, uint64_t address, uint32_t data); 111 void pci_disable_msi_method(device_t dev, device_t child); 112 int pci_remap_msix_method(device_t dev, device_t child, 113 int count, const u_int *vectors); 114 int pci_release_msi_method(device_t dev, device_t child); 115 int pci_msi_count_method(device_t dev, device_t child); 116 int pci_msix_count_method(device_t dev, device_t child); 117 int pci_msix_pba_bar_method(device_t dev, device_t child); 118 int pci_msix_table_bar_method(device_t dev, device_t child); 119 struct resource *pci_alloc_resource(device_t dev, device_t child, 120 int type, int *rid, rman_res_t start, rman_res_t end, 121 rman_res_t count, u_int flags); 122 int pci_release_resource(device_t dev, device_t child, int type, 123 int rid, struct resource *r); 124 int pci_activate_resource(device_t dev, device_t child, int type, 125 int rid, struct resource *r); 126 int pci_deactivate_resource(device_t dev, device_t child, int type, 127 int rid, struct resource *r); 128 void pci_delete_resource(device_t dev, device_t child, 129 int type, int rid); 130 struct resource_list *pci_get_resource_list (device_t dev, device_t child); 131 struct pci_devinfo *pci_read_device(device_t pcib, device_t bus, int d, int b, 132 int s, int f); 133 void pci_print_verbose(struct pci_devinfo *dinfo); 134 int pci_freecfg(struct pci_devinfo *dinfo); 135 void pci_child_deleted(device_t dev, device_t child); 136 void pci_child_detached(device_t dev, device_t child); 137 int pci_child_location_method(device_t cbdev, device_t child, 138 struct sbuf *sb); 139 int pci_child_pnpinfo_method(device_t cbdev, device_t child, 140 struct sbuf *sb); 141 int pci_assign_interrupt_method(device_t dev, device_t child); 142 int pci_resume(device_t dev); 143 int pci_resume_child(device_t dev, device_t child); 144 int pci_suspend_child(device_t dev, device_t child); 145 bus_dma_tag_t pci_get_dma_tag(device_t bus, device_t dev); 146 void pci_child_added_method(device_t dev, device_t child); 147 148 /** Restore the config register state. The state must be previously 149 * saved with pci_cfg_save. However, the pci bus driver takes care of 150 * that. This function will also return the device to PCI_POWERSTATE_D0 151 * if it is currently in a lower power mode. 152 */ 153 void pci_cfg_restore(device_t, struct pci_devinfo *); 154 155 /** Save the config register state. Optionally set the power state to D3 156 * if the third argument is non-zero. 157 */ 158 void pci_cfg_save(device_t, struct pci_devinfo *, int); 159 160 int pci_mapsize(uint64_t testval); 161 void pci_read_bar(device_t dev, int reg, pci_addr_t *mapp, 162 pci_addr_t *testvalp, int *bar64); 163 struct pci_map *pci_add_bar(device_t dev, int reg, pci_addr_t value, 164 pci_addr_t size); 165 166 struct resource *pci_alloc_multi_resource(device_t dev, device_t child, 167 int type, int *rid, rman_res_t start, rman_res_t end, 168 rman_res_t count, u_long num, u_int flags); 169 170 int pci_iov_attach_method(device_t bus, device_t dev, 171 struct nvlist *pf_schema, struct nvlist *vf_schema, 172 const char *name); 173 int pci_iov_detach_method(device_t bus, device_t dev); 174 175 device_t pci_create_iov_child_method(device_t bus, device_t pf, 176 uint16_t rid, uint16_t vid, uint16_t did); 177 178 struct resource *pci_vf_alloc_mem_resource(device_t dev, device_t child, 179 int *rid, rman_res_t start, rman_res_t end, 180 rman_res_t count, u_int flags); 181 int pci_vf_release_mem_resource(device_t dev, device_t child, 182 int rid, struct resource *r); 183 #endif /* _PCI_PRIVATE_H_ */ 184