diff options
| -rw-r--r-- | drivers/pci/Kconfig | 3 | ||||
| -rw-r--r-- | drivers/pci/Makefile | 1 | ||||
| -rw-r--r-- | drivers/pci/pci-bridge-emul.c | 408 | ||||
| -rw-r--r-- | drivers/pci/pci-bridge-emul.h | 124 |
4 files changed, 536 insertions, 0 deletions
diff --git a/drivers/pci/Kconfig b/drivers/pci/Kconfig index 56ff8f6d31fc..4a28e07d4c0e 100644 --- a/drivers/pci/Kconfig +++ b/drivers/pci/Kconfig | |||
| @@ -98,6 +98,9 @@ config PCI_ECAM | |||
| 98 | config PCI_LOCKLESS_CONFIG | 98 | config PCI_LOCKLESS_CONFIG |
| 99 | bool | 99 | bool |
| 100 | 100 | ||
| 101 | config PCI_BRIDGE_EMUL | ||
| 102 | bool | ||
| 103 | |||
| 101 | config PCI_IOV | 104 | config PCI_IOV |
| 102 | bool "PCI IOV support" | 105 | bool "PCI IOV support" |
| 103 | depends on PCI | 106 | depends on PCI |
diff --git a/drivers/pci/Makefile b/drivers/pci/Makefile index 1b2cfe51e8d7..3e5caf7347e9 100644 --- a/drivers/pci/Makefile +++ b/drivers/pci/Makefile | |||
| @@ -19,6 +19,7 @@ obj-$(CONFIG_HOTPLUG_PCI) += hotplug/ | |||
| 19 | obj-$(CONFIG_PCI_MSI) += msi.o | 19 | obj-$(CONFIG_PCI_MSI) += msi.o |
| 20 | obj-$(CONFIG_PCI_ATS) += ats.o | 20 | obj-$(CONFIG_PCI_ATS) += ats.o |
| 21 | obj-$(CONFIG_PCI_IOV) += iov.o | 21 | obj-$(CONFIG_PCI_IOV) += iov.o |
| 22 | obj-$(CONFIG_PCI_BRIDGE_EMUL) += pci-bridge-emul.o | ||
| 22 | obj-$(CONFIG_ACPI) += pci-acpi.o | 23 | obj-$(CONFIG_ACPI) += pci-acpi.o |
| 23 | obj-$(CONFIG_PCI_LABEL) += pci-label.o | 24 | obj-$(CONFIG_PCI_LABEL) += pci-label.o |
| 24 | obj-$(CONFIG_X86_INTEL_MID) += pci-mid.o | 25 | obj-$(CONFIG_X86_INTEL_MID) += pci-mid.o |
diff --git a/drivers/pci/pci-bridge-emul.c b/drivers/pci/pci-bridge-emul.c new file mode 100644 index 000000000000..129738362d90 --- /dev/null +++ b/drivers/pci/pci-bridge-emul.c | |||
| @@ -0,0 +1,408 @@ | |||
| 1 | // SPDX-License-Identifier: GPL-2.0 | ||
| 2 | /* | ||
| 3 | * Copyright (C) 2018 Marvell | ||
| 4 | * | ||
| 5 | * Author: Thomas Petazzoni <thomas.petazzoni@bootlin.com> | ||
| 6 | * | ||
| 7 | * This file helps PCI controller drivers implement a fake root port | ||
| 8 | * PCI bridge when the HW doesn't provide such a root port PCI | ||
| 9 | * bridge. | ||
| 10 | * | ||
| 11 | * It emulates a PCI bridge by providing a fake PCI configuration | ||
| 12 | * space (and optionally a PCIe capability configuration space) in | ||
| 13 | * memory. By default the read/write operations simply read and update | ||
| 14 | * this fake configuration space in memory. However, PCI controller | ||
| 15 | * drivers can provide through the 'struct pci_sw_bridge_ops' | ||
| 16 | * structure a set of operations to override or complement this | ||
| 17 | * default behavior. | ||
| 18 | */ | ||
| 19 | |||
| 20 | #include <linux/pci.h> | ||
| 21 | #include "pci-bridge-emul.h" | ||
| 22 | |||
| 23 | #define PCI_BRIDGE_CONF_END PCI_STD_HEADER_SIZEOF | ||
| 24 | #define PCI_CAP_PCIE_START PCI_BRIDGE_CONF_END | ||
| 25 | #define PCI_CAP_PCIE_END (PCI_CAP_PCIE_START + PCI_EXP_SLTSTA2 + 2) | ||
| 26 | |||
| 27 | /* | ||
| 28 | * Initialize a pci_bridge_emul structure to represent a fake PCI | ||
| 29 | * bridge configuration space. The caller needs to have initialized | ||
| 30 | * the PCI configuration space with whatever values make sense | ||
| 31 | * (typically at least vendor, device, revision), the ->ops pointer, | ||
| 32 | * and optionally ->data and ->has_pcie. | ||
| 33 | */ | ||
| 34 | void pci_bridge_emul_init(struct pci_bridge_emul *bridge) | ||
| 35 | { | ||
| 36 | bridge->conf.class_revision |= PCI_CLASS_BRIDGE_PCI << 16; | ||
| 37 | bridge->conf.header_type = PCI_HEADER_TYPE_BRIDGE; | ||
| 38 | bridge->conf.cache_line_size = 0x10; | ||
| 39 | bridge->conf.status = PCI_STATUS_CAP_LIST; | ||
| 40 | |||
| 41 | if (bridge->has_pcie) { | ||
| 42 | bridge->conf.capabilities_pointer = PCI_CAP_PCIE_START; | ||
| 43 | bridge->pcie_conf.cap_id = PCI_CAP_ID_EXP; | ||
| 44 | /* Set PCIe v2, root port, slot support */ | ||
| 45 | bridge->pcie_conf.cap = PCI_EXP_TYPE_ROOT_PORT << 4 | 2 | | ||
| 46 | PCI_EXP_FLAGS_SLOT; | ||
| 47 | } | ||
| 48 | } | ||
| 49 | |||
| 50 | struct pci_bridge_reg_behavior { | ||
| 51 | /* Read-only bits */ | ||
| 52 | u32 ro; | ||
| 53 | |||
| 54 | /* Read-write bits */ | ||
| 55 | u32 rw; | ||
| 56 | |||
| 57 | /* Write-1-to-clear bits */ | ||
| 58 | u32 w1c; | ||
| 59 | |||
| 60 | /* Reserved bits (hardwired to 0) */ | ||
| 61 | u32 rsvd; | ||
| 62 | }; | ||
| 63 | |||
| 64 | const static struct pci_bridge_reg_behavior pci_regs_behavior[] = { | ||
| 65 | [PCI_VENDOR_ID / 4] = { .ro = ~0 }, | ||
| 66 | [PCI_COMMAND / 4] = { | ||
| 67 | .rw = (PCI_COMMAND_IO | PCI_COMMAND_MEMORY | | ||
| 68 | PCI_COMMAND_MASTER | PCI_COMMAND_PARITY | | ||
| 69 | PCI_COMMAND_SERR), | ||
| 70 | .ro = ((PCI_COMMAND_SPECIAL | PCI_COMMAND_INVALIDATE | | ||
| 71 | PCI_COMMAND_VGA_PALETTE | PCI_COMMAND_WAIT | | ||
| 72 | PCI_COMMAND_FAST_BACK) | | ||
| 73 | (PCI_STATUS_CAP_LIST | PCI_STATUS_66MHZ | | ||
| 74 | PCI_STATUS_FAST_BACK | PCI_STATUS_DEVSEL_MASK) << 16), | ||
| 75 | .rsvd = GENMASK(15, 10) | ((BIT(6) | GENMASK(3, 0)) << 16), | ||
| 76 | .w1c = (PCI_STATUS_PARITY | | ||
| 77 | PCI_STATUS_SIG_TARGET_ABORT | | ||
| 78 | PCI_STATUS_REC_TARGET_ABORT | | ||
| 79 | PCI_STATUS_REC_MASTER_ABORT | | ||
| 80 | PCI_STATUS_SIG_SYSTEM_ERROR | | ||
| 81 | PCI_STATUS_DETECTED_PARITY) << 16, | ||
| 82 | }, | ||
| 83 | [PCI_CLASS_REVISION / 4] = { .ro = ~0 }, | ||
| 84 | |||
| 85 | /* | ||
| 86 | * Cache Line Size register: implement as read-only, we do not | ||
| 87 | * pretend implementing "Memory Write and Invalidate" | ||
| 88 | * transactions" | ||
| 89 | * | ||
| 90 | * Latency Timer Register: implemented as read-only, as "A | ||
| 91 | * bridge that is not capable of a burst transfer of more than | ||
| 92 | * two data phases on its primary interface is permitted to | ||
| 93 | * hardwire the Latency Timer to a value of 16 or less" | ||
| 94 | * | ||
| 95 | * Header Type: always read-only | ||
| 96 | * | ||
| 97 | * BIST register: implemented as read-only, as "A bridge that | ||
| 98 | * does not support BIST must implement this register as a | ||
| 99 | * read-only register that returns 0 when read" | ||
| 100 | */ | ||
| 101 | [PCI_CACHE_LINE_SIZE / 4] = { .ro = ~0 }, | ||
| 102 | |||
| 103 | /* | ||
| 104 | * Base Address registers not used must be implemented as | ||
| 105 | * read-only registers that return 0 when read. | ||
| 106 | */ | ||
| 107 | [PCI_BASE_ADDRESS_0 / 4] = { .ro = ~0 }, | ||
| 108 | [PCI_BASE_ADDRESS_1 / 4] = { .ro = ~0 }, | ||
| 109 | |||
| 110 | [PCI_PRIMARY_BUS / 4] = { | ||
| 111 | /* Primary, secondary and subordinate bus are RW */ | ||
| 112 | .rw = GENMASK(24, 0), | ||
| 113 | /* Secondary latency is read-only */ | ||
| 114 | .ro = GENMASK(31, 24), | ||
| 115 | }, | ||
| 116 | |||
| 117 | [PCI_IO_BASE / 4] = { | ||
| 118 | /* The high four bits of I/O base/limit are RW */ | ||
| 119 | .rw = (GENMASK(15, 12) | GENMASK(7, 4)), | ||
| 120 | |||
| 121 | /* The low four bits of I/O base/limit are RO */ | ||
| 122 | .ro = (((PCI_STATUS_66MHZ | PCI_STATUS_FAST_BACK | | ||
| 123 | PCI_STATUS_DEVSEL_MASK) << 16) | | ||
| 124 | GENMASK(11, 8) | GENMASK(3, 0)), | ||
| 125 | |||
| 126 | .w1c = (PCI_STATUS_PARITY | | ||
| 127 | PCI_STATUS_SIG_TARGET_ABORT | | ||
| 128 | PCI_STATUS_REC_TARGET_ABORT | | ||
| 129 | PCI_STATUS_REC_MASTER_ABORT | | ||
| 130 | PCI_STATUS_SIG_SYSTEM_ERROR | | ||
| 131 | PCI_STATUS_DETECTED_PARITY) << 16, | ||
| 132 | |||
| 133 | .rsvd = ((BIT(6) | GENMASK(4, 0)) << 16), | ||
| 134 | }, | ||
| 135 | |||
| 136 | [PCI_MEMORY_BASE / 4] = { | ||
| 137 | /* The high 12-bits of mem base/limit are RW */ | ||
| 138 | .rw = GENMASK(31, 20) | GENMASK(15, 4), | ||
| 139 | |||
| 140 | /* The low four bits of mem base/limit are RO */ | ||
| 141 | .ro = GENMASK(19, 16) | GENMASK(3, 0), | ||
| 142 | }, | ||
| 143 | |||
| 144 | [PCI_PREF_MEMORY_BASE / 4] = { | ||
| 145 | /* The high 12-bits of pref mem base/limit are RW */ | ||
| 146 | .rw = GENMASK(31, 20) | GENMASK(15, 4), | ||
| 147 | |||
| 148 | /* The low four bits of pref mem base/limit are RO */ | ||
| 149 | .ro = GENMASK(19, 16) | GENMASK(3, 0), | ||
| 150 | }, | ||
| 151 | |||
| 152 | [PCI_PREF_BASE_UPPER32 / 4] = { | ||
| 153 | .rw = ~0, | ||
| 154 | }, | ||
| 155 | |||
| 156 | [PCI_PREF_LIMIT_UPPER32 / 4] = { | ||
| 157 | .rw = ~0, | ||
| 158 | }, | ||
| 159 | |||
| 160 | [PCI_IO_BASE_UPPER16 / 4] = { | ||
| 161 | .rw = ~0, | ||
| 162 | }, | ||
| 163 | |||
| 164 | [PCI_CAPABILITY_LIST / 4] = { | ||
| 165 | .ro = GENMASK(7, 0), | ||
| 166 | .rsvd = GENMASK(31, 8), | ||
| 167 | }, | ||
| 168 | |||
| 169 | [PCI_ROM_ADDRESS1 / 4] = { | ||
| 170 | .rw = GENMASK(31, 11) | BIT(0), | ||
| 171 | .rsvd = GENMASK(10, 1), | ||
| 172 | }, | ||
| 173 | |||
| 174 | /* | ||
| 175 | * Interrupt line (bits 7:0) are RW, interrupt pin (bits 15:8) | ||
| 176 | * are RO, and bridge control (31:16) are a mix of RW, RO, | ||
| 177 | * reserved and W1C bits | ||
| 178 | */ | ||
| 179 | [PCI_INTERRUPT_LINE / 4] = { | ||
| 180 | /* Interrupt line is RW */ | ||
| 181 | .rw = (GENMASK(7, 0) | | ||
| 182 | ((PCI_BRIDGE_CTL_PARITY | | ||
