Lines Matching +full:4 +full:- +full:bits
1 // SPDX-License-Identifier: GPL-2.0
21 #include "pci-bridge-emul.h"
29 * struct pci_bridge_reg_behavior - register bits behaviors
30 * @ro: Read-Only bits
31 * @rw: Read-Write bits
32 * @w1c: Write-1-to-Clear bits
34 * Reads and Writes will be filtered by specified behavior. All other bits not
37 * multi-bit fields) when read".
40 /* Read-only bits */
43 /* Read-write bits */
46 /* Write-1-to-clear bits */
51 struct pci_bridge_reg_behavior pci_regs_behavior[PCI_STD_HEADER_SIZEOF / 4] = {
52 [PCI_VENDOR_ID / 4] = { .ro = ~0 },
53 [PCI_COMMAND / 4] = {
64 [PCI_CLASS_REVISION / 4] = { .ro = ~0 },
67 * Cache Line Size register: implement as read-only, we do not
71 * Latency Timer Register: implemented as read-only, as "A
76 * Header Type: always read-only
78 * BIST register: implemented as read-only, as "A bridge that
80 * read-only register that returns 0 when read"
82 [PCI_CACHE_LINE_SIZE / 4] = { .ro = ~0 },
86 * read-only registers that return 0 when read.
88 [PCI_BASE_ADDRESS_0 / 4] = { .ro = ~0 },
89 [PCI_BASE_ADDRESS_1 / 4] = { .ro = ~0 },
91 [PCI_PRIMARY_BUS / 4] = {
94 /* Secondary latency is read-only */
98 [PCI_IO_BASE / 4] = {
99 /* The high four bits of I/O base/limit are RW */
100 .rw = (GENMASK(15, 12) | GENMASK(7, 4)),
102 /* The low four bits of I/O base/limit are RO */
110 [PCI_MEMORY_BASE / 4] = {
111 /* The high 12-bits of mem base/limit are RW */
112 .rw = GENMASK(31, 20) | GENMASK(15, 4),
114 /* The low four bits of mem base/limit are RO */
118 [PCI_PREF_MEMORY_BASE / 4] = {
119 /* The high 12-bits of pref mem base/limit are RW */
120 .rw = GENMASK(31, 20) | GENMASK(15, 4),
122 /* The low four bits of pref mem base/limit are RO */
126 [PCI_PREF_BASE_UPPER32 / 4] = {
130 [PCI_PREF_LIMIT_UPPER32 / 4] = {
134 [PCI_IO_BASE_UPPER16 / 4] = {
138 [PCI_CAPABILITY_LIST / 4] = {
144 * be implemented as read-only register that return 0 when read, same
147 [PCI_ROM_ADDRESS1 / 4] = {
152 * Interrupt line (bits 7:0) are RW, interrupt pin (bits 15:8)
154 * reserved and W1C bits
156 [PCI_INTERRUPT_LINE / 4] = {
175 struct pci_bridge_reg_behavior pcie_cap_regs_behavior[PCI_CAP_PCIE_SIZEOF / 4] = {
176 [PCI_CAP_LIST_ID / 4] = {
179 * bits [14:0] of Capabilities register are all read-only.
185 [PCI_EXP_DEVCAP / 4] = {
187 * Bits [31:29] and [17:16] are reserved.
188 * Bits [27:18] are reserved for non-upstream ports.
189 * Bits 28 and [14:6] are reserved for non-endpoint devices.
190 * Other bits are read-only.
195 [PCI_EXP_DEVCTL / 4] = {
198 * reserved for non-endpoints or non-PCIe-to-PCI/X bridges.
203 * Device status register has bits 6 and [3:0] W1C, [5:4] RO,
204 * the rest is reserved. Also bit 6 is reserved for non-upstream
208 .ro = GENMASK(5, 4) << 16,
211 [PCI_EXP_LNKCAP / 4] = {
213 * All bits are RO, except bit 23 which is reserved and
214 * bit 18 which is reserved for non-upstream ports.
219 [PCI_EXP_LNKCTL / 4] = {
221 * Link control has bits [15:14], [11:3] and [1:0] RW, the
222 * rest is reserved. Bit 8 is reserved for non-upstream ports.
224 * Link status has bits [13:0] RO, and bits [15:14]
232 [PCI_EXP_SLTCAP / 4] = {
236 [PCI_EXP_SLTCTL / 4] = {
238 * Slot control has bits [14:0] RW, the rest is
241 * Slot status has bits 8 and [4:0] W1C, bits [7:5] RO, the
252 [PCI_EXP_RTCTL / 4] = {
254 * Root control has bits [4:0] RW, the rest is
265 [PCI_EXP_RTSTA / 4] = {
267 * Root status has bits 17 and [15:0] RO, bit 16 W1C, the rest
279 * (typically at least vendor, device, revision), the ->ops pointer,
280 * and optionally ->data and ->has_pcie.
285 BUILD_BUG_ON(sizeof(bridge->conf) != PCI_BRIDGE_CONF_END); in pci_bridge_emul_init()
287 bridge->conf.class_revision |= cpu_to_le32(PCI_CLASS_BRIDGE_PCI << 16); in pci_bridge_emul_init()
288 bridge->conf.header_type = PCI_HEADER_TYPE_BRIDGE; in pci_bridge_emul_init()
289 bridge->conf.cache_line_size = 0x10; in pci_bridge_emul_init()
290 bridge->conf.status = cpu_to_le16(PCI_STATUS_CAP_LIST); in pci_bridge_emul_init()
291 bridge->pci_regs_behavior = kmemdup(pci_regs_behavior, in pci_bridge_emul_init()
294 if (!bridge->pci_regs_behavior) in pci_bridge_emul_init()
295 return -ENOMEM; in pci_bridge_emul_init()
297 if (bridge->has_pcie) { in pci_bridge_emul_init()
298 bridge->conf.capabilities_pointer = PCI_CAP_PCIE_START; in pci_bridge_emul_init()
299 bridge->conf.status |= cpu_to_le16(PCI_STATUS_CAP_LIST); in pci_bridge_emul_init()
300 bridge->pcie_conf.cap_id = PCI_CAP_ID_EXP; in pci_bridge_emul_init()
301 bridge->pcie_conf.cap |= cpu_to_le16(PCI_EXP_TYPE_ROOT_PORT << 4); in pci_bridge_emul_init()
302 bridge->pcie_cap_regs_behavior = in pci_bridge_emul_init()
306 if (!bridge->pcie_cap_regs_behavior) { in pci_bridge_emul_init()
307 kfree(bridge->pci_regs_behavior); in pci_bridge_emul_init()
308 return -ENOMEM; in pci_bridge_emul_init()
310 /* These bits are applicable only for PCI and reserved on PCIe */ in pci_bridge_emul_init()
311 bridge->pci_regs_behavior[PCI_CACHE_LINE_SIZE / 4].ro &= in pci_bridge_emul_init()
313 bridge->pci_regs_behavior[PCI_COMMAND / 4].ro &= in pci_bridge_emul_init()
319 bridge->pci_regs_behavior[PCI_PRIMARY_BUS / 4].ro &= in pci_bridge_emul_init()
321 bridge->pci_regs_behavior[PCI_IO_BASE / 4].ro &= in pci_bridge_emul_init()
324 bridge->pci_regs_behavior[PCI_INTERRUPT_LINE / 4].rw &= in pci_bridge_emul_init()
327 bridge->pci_regs_behavior[PCI_INTERRUPT_LINE / 4].ro &= in pci_bridge_emul_init()
329 bridge->pci_regs_behavior[PCI_INTERRUPT_LINE / 4].w1c &= in pci_bridge_emul_init()
334 bridge->pci_regs_behavior[PCI_PREF_MEMORY_BASE / 4].ro = ~0; in pci_bridge_emul_init()
335 bridge->pci_regs_behavior[PCI_PREF_MEMORY_BASE / 4].rw = 0; in pci_bridge_emul_init()
348 if (bridge->has_pcie) in pci_bridge_emul_cleanup()
349 kfree(bridge->pcie_cap_regs_behavior); in pci_bridge_emul_cleanup()
350 kfree(bridge->pci_regs_behavior); in pci_bridge_emul_cleanup()
357 * ->ops->read_base or ->ops->read_pcie operations.
369 if (bridge->has_pcie && reg >= PCI_CAP_PCIE_END) { in pci_bridge_emul_conf_read()
374 if (!bridge->has_pcie && reg >= PCI_BRIDGE_CONF_END) { in pci_bridge_emul_conf_read()
379 if (bridge->has_pcie && reg >= PCI_CAP_PCIE_START) { in pci_bridge_emul_conf_read()
380 reg -= PCI_CAP_PCIE_START; in pci_bridge_emul_conf_read()
381 read_op = bridge->ops->read_pcie; in pci_bridge_emul_conf_read()
382 cfgspace = (__le32 *) &bridge->pcie_conf; in pci_bridge_emul_conf_read()
383 behavior = bridge->pcie_cap_regs_behavior; in pci_bridge_emul_conf_read()
385 read_op = bridge->ops->read_base; in pci_bridge_emul_conf_read()
386 cfgspace = (__le32 *) &bridge->conf; in pci_bridge_emul_conf_read()
387 behavior = bridge->pci_regs_behavior; in pci_bridge_emul_conf_read()
396 *value = le32_to_cpu(cfgspace[reg / 4]); in pci_bridge_emul_conf_read()
402 *value &= behavior[reg / 4].ro | behavior[reg / 4].rw | in pci_bridge_emul_conf_read()
403 behavior[reg / 4].w1c; in pci_bridge_emul_conf_read()
409 else if (size != 4) in pci_bridge_emul_conf_read()
419 * ->ops->write_base or ->ops->write_pcie operations.
431 if (bridge->has_pcie && reg >= PCI_CAP_PCIE_END) in pci_bridge_emul_conf_write()
434 if (!bridge->has_pcie && reg >= PCI_BRIDGE_CONF_END) in pci_bridge_emul_conf_write()
439 if (size == 4) in pci_bridge_emul_conf_write()
448 ret = pci_bridge_emul_conf_read(bridge, reg, 4, &old); in pci_bridge_emul_conf_write()
452 if (bridge->has_pcie && reg >= PCI_CAP_PCIE_START) { in pci_bridge_emul_conf_write()
453 reg -= PCI_CAP_PCIE_START; in pci_bridge_emul_conf_write()
454 write_op = bridge->ops->write_pcie; in pci_bridge_emul_conf_write()
455 cfgspace = (__le32 *) &bridge->pcie_conf; in pci_bridge_emul_conf_write()
456 behavior = bridge->pcie_cap_regs_behavior; in pci_bridge_emul_conf_write()
458 write_op = bridge->ops->write_base; in pci_bridge_emul_conf_write()
459 cfgspace = (__le32 *) &bridge->conf; in pci_bridge_emul_conf_write()
460 behavior = bridge->pci_regs_behavior; in pci_bridge_emul_conf_write()
463 /* Keep all bits, except the RW bits */ in pci_bridge_emul_conf_write()
464 new = old & (~mask | ~behavior[reg / 4].rw); in pci_bridge_emul_conf_write()
466 /* Update the value of the RW bits */ in pci_bridge_emul_conf_write()
467 new |= (value << shift) & (behavior[reg / 4].rw & mask); in pci_bridge_emul_conf_write()
469 /* Clear the W1C bits */ in pci_bridge_emul_conf_write()
470 new &= ~((value << shift) & (behavior[reg / 4].w1c & mask)); in pci_bridge_emul_conf_write()
472 /* Save the new value with the cleared W1C bits into the cfgspace */ in pci_bridge_emul_conf_write()
473 cfgspace[reg / 4] = cpu_to_le32(new); in pci_bridge_emul_conf_write()
476 * Clear the W1C bits not specified by the write mask, so that the in pci_bridge_emul_conf_write()
479 new &= ~(behavior[reg / 4].w1c & ~mask); in pci_bridge_emul_conf_write()
482 * Set the W1C bits specified by the write mask, so that write_op() in pci_bridge_emul_conf_write()
485 new |= (value << shift) & (behavior[reg / 4].w1c & mask); in pci_bridge_emul_conf_write()