pci.h revision 1.39
1/* $NetBSD: pci.h,v 1.39 2020/02/14 14:34:59 maya Exp $ */ 2 3/*- 4 * Copyright (c) 2013 The NetBSD Foundation, Inc. 5 * All rights reserved. 6 * 7 * This code is derived from software contributed to The NetBSD Foundation 8 * by Taylor R. Campbell. 9 * 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the following conditions 12 * are met: 13 * 1. Redistributions of source code must retain the above copyright 14 * notice, this list of conditions and the following 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 NETBSD FOUNDATION, INC. AND CONTRIBUTORS 20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 * POSSIBILITY OF SUCH DAMAGE. 30 */ 31 32#ifndef _LINUX_PCI_H_ 33#define _LINUX_PCI_H_ 34 35#ifdef _KERNEL_OPT 36#if defined(i386) || defined(amd64) || defined(__aarch64__) 37#include "acpica.h" 38#else /* !(i386 || amd64) */ 39#define NACPICA 0 40#endif /* i386 || amd64 */ 41#endif 42 43#include <sys/types.h> 44#include <sys/param.h> 45#include <sys/bus.h> 46#include <sys/cdefs.h> 47#include <sys/kmem.h> 48#include <sys/systm.h> 49 50#include <machine/limits.h> 51 52#include <dev/pci/pcidevs.h> 53#include <dev/pci/pcireg.h> 54#include <dev/pci/pcivar.h> 55#include <dev/pci/agpvar.h> 56 57#if NACPICA > 0 58#include <dev/acpi/acpivar.h> 59#include <dev/acpi/acpi_pci.h> 60#else 61struct acpi_devnode; 62#endif 63 64#include <linux/device.h> 65#include <linux/dma-mapping.h> 66#include <linux/errno.h> 67#include <linux/io.h> 68#include <linux/ioport.h> 69#include <linux/kernel.h> 70 71struct pci_driver; 72 73struct pci_bus { 74 /* NetBSD private members */ 75 pci_chipset_tag_t pb_pc; 76 device_t pb_dev; 77 78 /* Linux API */ 79 u_int number; 80}; 81 82struct pci_device_id { 83 uint32_t vendor; 84 uint32_t device; 85 uint32_t subvendor; 86 uint32_t subdevice; 87 uint32_t class; 88 uint32_t class_mask; 89 unsigned long driver_data; 90}; 91 92#define PCI_ANY_ID (~0) 93 94#define PCI_BASE_CLASS_DISPLAY PCI_CLASS_DISPLAY 95 96#define PCI_CLASS_DISPLAY_VGA \ 97 ((PCI_CLASS_DISPLAY << 8) | PCI_SUBCLASS_DISPLAY_VGA) 98#define PCI_CLASS_BRIDGE_ISA \ 99 ((PCI_CLASS_BRIDGE << 8) | PCI_SUBCLASS_BRIDGE_ISA) 100CTASSERT(PCI_CLASS_BRIDGE_ISA == 0x0601); 101 102/* XXX This is getting silly... */ 103#define PCI_VENDOR_ID_APPLE PCI_VENDOR_APPLE 104#define PCI_VENDOR_ID_ASUSTEK PCI_VENDOR_ASUSTEK 105#define PCI_VENDOR_ID_ATI PCI_VENDOR_ATI 106#define PCI_VENDOR_ID_DELL PCI_VENDOR_DELL 107#define PCI_VENDOR_ID_IBM PCI_VENDOR_IBM 108#define PCI_VENDOR_ID_HP PCI_VENDOR_HP 109#define PCI_VENDOR_ID_INTEL PCI_VENDOR_INTEL 110#define PCI_VENDOR_ID_NVIDIA PCI_VENDOR_NVIDIA 111#define PCI_VENDOR_ID_SI PCI_VENDOR_SIS 112#define PCI_VENDOR_ID_SONY PCI_VENDOR_SONY 113#define PCI_VENDOR_ID_VIA PCI_VENDOR_VIATECH 114 115#define PCI_DEVICE_ID_ATI_RADEON_QY PCI_PRODUCT_ATI_RADEON_RV100_QY 116 117#define PCI_DEVFN(DEV, FN) \ 118 (__SHIFTIN((DEV), __BITS(3, 7)) | __SHIFTIN((FN), __BITS(0, 2))) 119#define PCI_SLOT(DEVFN) __SHIFTOUT((DEVFN), __BITS(3, 7)) 120#define PCI_FUNC(DEVFN) __SHIFTOUT((DEVFN), __BITS(0, 2)) 121 122#define PCI_NUM_RESOURCES ((PCI_MAPREG_END - PCI_MAPREG_START) / 4) 123#define DEVICE_COUNT_RESOURCE PCI_NUM_RESOURCES 124 125#define PCI_CAP_ID_AGP PCI_CAP_AGP 126 127typedef int pci_power_t; 128 129#define PCI_D0 0 130#define PCI_D1 1 131#define PCI_D2 2 132#define PCI_D3hot 3 133#define PCI_D3cold 4 134 135#define __pci_iomem 136 137struct pci_dev { 138 struct pci_attach_args pd_pa; 139 int pd_kludges; /* Gotta lose 'em... */ 140#define NBPCI_KLUDGE_GET_MUMBLE 0x01 141#define NBPCI_KLUDGE_MAP_ROM 0x02 142 bus_space_tag_t pd_rom_bst; 143 bus_space_handle_t pd_rom_bsh; 144 bus_size_t pd_rom_size; 145 bus_space_handle_t pd_rom_found_bsh; 146 bus_size_t pd_rom_found_size; 147 void *pd_rom_vaddr; 148 device_t pd_dev; 149 struct drm_device *pd_drm_dev; /* XXX Nouveau kludge! */ 150 struct { 151 pcireg_t type; 152 bus_addr_t addr; 153 bus_size_t size; 154 int flags; 155 bus_space_tag_t bst; 156 bus_space_handle_t bsh; 157 void __pci_iomem *kva; 158 bool mapped; 159 } pd_resources[PCI_NUM_RESOURCES]; 160 struct pci_conf_state *pd_saved_state; 161 struct acpi_devnode *pd_ad; 162 pci_intr_handle_t *pd_intr_handles; 163 unsigned pd_enablecnt; 164 165 /* Linx API only below */ 166 struct pci_bus *bus; 167 uint32_t devfn; 168 uint16_t vendor; 169 uint16_t device; 170 uint16_t subsystem_vendor; 171 uint16_t subsystem_device; 172 uint8_t revision; 173 uint32_t class; 174 bool msi_enabled; 175 bool no_64bit_msi; 176}; 177 178#define PCIBIOS_MIN_MEM 0x100000 /* XXX bogus x86 kludge bollocks */ 179 180#define __pci_rom_iomem 181 182/* Namespace. */ 183#define pci_bus_alloc_resource linux_pci_bus_alloc_resource 184#define pci_bus_read_config_byte linux_pci_bus_read_config_byte 185#define pci_bus_read_config_dword linux_pci_bus_read_config_dword 186#define pci_bus_read_config_word linux_pci_bus_read_config_word 187#define pci_bus_write_config_byte linux_pci_bus_write_config_byte 188#define pci_bus_write_config_dword linux_pci_bus_write_config_dword 189#define pci_bus_write_config_word linux_pci_bus_write_config_word 190#define pci_clear_master linux_pci_clear_master 191#define pci_dev_dev linux_pci_dev_dev 192#define pci_dev_put linux_pci_dev_put 193#define pci_disable_msi linux_pci_disable_msi 194#define pci_disable_rom linux_pci_disable_rom 195#define pci_dma_supported linux_pci_dma_supported 196#define pci_domain_nr linux_pci_domain_nr 197#define pci_enable_msi linux_pci_enable_msi 198#define pci_enable_rom linux_pci_enable_rom 199#define pci_find_capability linux_pci_find_capability 200#define pci_get_bus_and_slot linux_pci_get_bus_and_slot 201#define pci_get_class linux_pci_get_class 202#define pci_get_drvdata linux_pci_get_drvdata 203#define pci_iomap linux_pci_iomap 204#define pci_iounmap linux_pci_iounmap 205#define pci_is_pcie linux_pci_is_pcie 206#define pci_is_root_bus linux_pci_is_root_bus 207#define pci_map_rom linux_pci_map_rom 208#define pci_platform_rom linux_pci_platform_rom 209#define pci_read_config_byte linux_pci_read_config_byte 210#define pci_read_config_dword linux_pci_read_config_dword 211#define pci_read_config_word linux_pci_read_config_word 212#define pci_resource_end linux_pci_resource_end 213#define pci_resource_flags linux_pci_resource_flags 214#define pci_resource_len linux_pci_resource_len 215#define pci_resource_start linux_pci_resource_start 216#define pci_restore_state linux_pci_restore_state 217#define pci_save_state linux_pci_save_state 218#define pci_set_master linux_pci_set_master 219#define pci_unmap_rom linux_pci_unmap_rom 220#define pci_write_config_byte linux_pci_write_config_byte 221#define pci_write_config_dword linux_pci_write_config_dword 222#define pci_write_config_word linux_pci_write_config_word 223#define pcibios_align_resource linux_pcibios_align_resource 224 225/* NetBSD local additions. */ 226void linux_pci_dev_init(struct pci_dev *, device_t, device_t, 227 const struct pci_attach_args *, int); 228void linux_pci_dev_destroy(struct pci_dev *); 229 230/* NetBSD no-renames because use requires review. */ 231int linux_pci_enable_device(struct pci_dev *); 232void linux_pci_disable_device(struct pci_dev *); 233 234bool pci_is_root_bus(struct pci_bus *); 235int pci_domain_nr(struct pci_bus *); 236 237device_t pci_dev_dev(struct pci_dev *); 238struct drm_device * /* XXX Nouveau kludge! */ 239 pci_get_drvdata(struct pci_dev *); 240 241int pci_find_capability(struct pci_dev *, int); 242bool pci_is_pcie(struct pci_dev *); 243bool pci_dma_supported(struct pci_dev *, uintmax_t); 244 245int pci_read_config_dword(struct pci_dev *, int, uint32_t *); 246int pci_read_config_word(struct pci_dev *, int, uint16_t *); 247int pci_read_config_byte(struct pci_dev *, int, uint8_t *); 248int pci_write_config_dword(struct pci_dev *, int, uint32_t); 249int pci_write_config_word(struct pci_dev *, int, uint16_t); 250int pci_write_config_byte(struct pci_dev *, int, uint8_t); 251 252int pci_bus_read_config_dword(struct pci_bus *, unsigned, int, 253 uint32_t *); 254int pci_bus_read_config_word(struct pci_bus *, unsigned, int, 255 uint16_t *); 256int pci_bus_read_config_byte(struct pci_bus *, unsigned, int, 257 uint8_t *); 258int pci_bus_write_config_dword(struct pci_bus *, unsigned, int, 259 uint32_t); 260int pci_bus_write_config_word(struct pci_bus *, unsigned, int, 261 uint16_t); 262int pci_bus_write_config_byte(struct pci_bus *, unsigned, int, 263 uint8_t); 264 265int pci_enable_msi(struct pci_dev *); 266void pci_disable_msi(struct pci_dev *); 267void pci_set_master(struct pci_dev *); 268void pci_clear_master(struct pci_dev *); 269 270bus_addr_t pcibios_align_resource(void *, const struct resource *, 271 bus_addr_t, bus_size_t); 272int pci_bus_alloc_resource(struct pci_bus *, struct resource *, 273 bus_size_t, bus_size_t, bus_addr_t, int, 274 bus_addr_t (*)(void *, const struct resource *, bus_addr_t, 275 bus_size_t), struct pci_dev *); 276 277/* XXX Kludges only -- do not use without checking the implementation! */ 278struct pci_dev *pci_get_bus_and_slot(int, int); 279struct pci_dev *pci_get_class(uint32_t, struct pci_dev *); /* i915 kludge */ 280void pci_dev_put(struct pci_dev *); 281 282void __pci_rom_iomem * 283 pci_map_rom(struct pci_dev *, size_t *); 284void __pci_rom_iomem * 285 pci_platform_rom(struct pci_dev *, size_t *); 286void pci_unmap_rom(struct pci_dev *, void __pci_rom_iomem *); 287int pci_enable_rom(struct pci_dev *); 288void pci_disable_rom(struct pci_dev *); 289 290bus_addr_t pci_resource_start(struct pci_dev *, unsigned); 291bus_size_t pci_resource_len(struct pci_dev *, unsigned); 292bus_addr_t pci_resource_end(struct pci_dev *, unsigned); 293int pci_resource_flags(struct pci_dev *, unsigned); 294 295void __pci_iomem * 296 pci_iomap(struct pci_dev *, unsigned, bus_size_t); 297void pci_iounmap(struct pci_dev *, void __pci_iomem *); 298 299void pci_save_state(struct pci_dev *); 300void pci_restore_state(struct pci_dev *); 301 302#endif /* _LINUX_PCI_H_ */ 303