2018-01-27 02:50:27 +08:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0 */
|
2016-05-10 23:19:51 +08:00
|
|
|
/*
|
|
|
|
* Copyright 2016 Broadcom
|
|
|
|
*/
|
|
|
|
#ifndef DRIVERS_PCI_ECAM_H
|
|
|
|
#define DRIVERS_PCI_ECAM_H
|
|
|
|
|
2017-03-17 22:53:19 +08:00
|
|
|
#include <linux/pci.h>
|
2016-05-10 23:19:51 +08:00
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/platform_device.h>
|
|
|
|
|
2020-11-30 07:07:39 +08:00
|
|
|
/*
|
|
|
|
* Memory address shift values for the byte-level address that
|
|
|
|
* can be used when accessing the PCI Express Configuration Space.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Enhanced Configuration Access Mechanism (ECAM)
|
|
|
|
*
|
|
|
|
* See PCI Express Base Specification, Revision 5.0, Version 1.0,
|
|
|
|
* Section 7.2.2, Table 7-1, p. 677.
|
|
|
|
*/
|
|
|
|
#define PCIE_ECAM_BUS_SHIFT 20 /* Bus number */
|
|
|
|
#define PCIE_ECAM_DEVFN_SHIFT 12 /* Device and Function number */
|
|
|
|
|
|
|
|
#define PCIE_ECAM_BUS_MASK 0xff
|
|
|
|
#define PCIE_ECAM_DEVFN_MASK 0xff
|
|
|
|
#define PCIE_ECAM_REG_MASK 0xfff /* Limit offset to a maximum of 4K */
|
|
|
|
|
|
|
|
#define PCIE_ECAM_BUS(x) (((x) & PCIE_ECAM_BUS_MASK) << PCIE_ECAM_BUS_SHIFT)
|
|
|
|
#define PCIE_ECAM_DEVFN(x) (((x) & PCIE_ECAM_DEVFN_MASK) << PCIE_ECAM_DEVFN_SHIFT)
|
|
|
|
#define PCIE_ECAM_REG(x) ((x) & PCIE_ECAM_REG_MASK)
|
|
|
|
|
|
|
|
#define PCIE_ECAM_OFFSET(bus, devfn, where) \
|
|
|
|
(PCIE_ECAM_BUS(bus) | \
|
|
|
|
PCIE_ECAM_DEVFN(devfn) | \
|
|
|
|
PCIE_ECAM_REG(where))
|
|
|
|
|
2016-05-10 23:19:51 +08:00
|
|
|
/*
|
|
|
|
* struct to hold pci ops and bus shift of the config window
|
|
|
|
* for a PCI controller.
|
|
|
|
*/
|
|
|
|
struct pci_config_window;
|
|
|
|
struct pci_ecam_ops {
|
|
|
|
unsigned int bus_shift;
|
|
|
|
struct pci_ops pci_ops;
|
2016-06-11 03:55:10 +08:00
|
|
|
int (*init)(struct pci_config_window *);
|
2016-05-10 23:19:51 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* struct to hold the mappings of a config space window. This
|
|
|
|
* is expected to be used as sysdata for PCI controllers that
|
|
|
|
* use ECAM.
|
|
|
|
*/
|
|
|
|
struct pci_config_window {
|
|
|
|
struct resource res;
|
|
|
|
struct resource busr;
|
PCI: Dynamically map ECAM regions
Attempting to boot 32-bit ARM kernels under QEMU's 3.x virt models fails
when we have more than 512M of RAM in the model as we run out of vmalloc
space for the PCI ECAM regions. This failure will be silent when running
libvirt, as the console in that situation is a PCI device.
In this configuration, the kernel maps the whole ECAM, which QEMU sets up
for 256 buses, even when maybe only seven buses are in use. Each bus uses
1M of ECAM space, and ioremap() adds an additional guard page between
allocations. The kernel vmap allocator will align these regions to 512K,
resulting in each mapping eating 1.5M of vmalloc space. This means we need
384M of vmalloc space just to map all of these, which is very wasteful of
resources.
Fix this by only mapping the ECAM for buses we are going to be using. In
my setups, this is around seven buses in most guests, which is 10.5M of
vmalloc space - way smaller than the 384M that would otherwise be required.
This also means that the kernel can boot without forcing extra RAM into
highmem with the vmalloc= argument, or decreasing the virtual RAM available
to the guest.
Suggested-by: Arnd Bergmann <arnd@arndb.de>
Link: https://lore.kernel.org/r/E1lhCAV-0002yb-50@rmk-PC.armlinux.org.uk
Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Reviewed-by: Arnd Bergmann <arnd@arndb.de>
2021-05-13 22:18:27 +08:00
|
|
|
unsigned int bus_shift;
|
2016-05-10 23:19:51 +08:00
|
|
|
void *priv;
|
2020-04-10 07:49:21 +08:00
|
|
|
const struct pci_ecam_ops *ops;
|
2016-05-10 23:19:51 +08:00
|
|
|
union {
|
|
|
|
void __iomem *win; /* 64-bit single mapping */
|
|
|
|
void __iomem **winp; /* 32-bit per-bus mapping */
|
|
|
|
};
|
2016-06-11 03:55:10 +08:00
|
|
|
struct device *parent;/* ECAM res was from this dev */
|
2016-05-10 23:19:51 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/* create and free pci_config_window */
|
|
|
|
struct pci_config_window *pci_ecam_create(struct device *dev,
|
|
|
|
struct resource *cfgres, struct resource *busr,
|
2020-04-10 07:49:21 +08:00
|
|
|
const struct pci_ecam_ops *ops);
|
2016-05-10 23:19:51 +08:00
|
|
|
void pci_ecam_free(struct pci_config_window *cfg);
|
|
|
|
|
|
|
|
/* map_bus when ->sysdata is an instance of pci_config_window */
|
|
|
|
void __iomem *pci_ecam_map_bus(struct pci_bus *bus, unsigned int devfn,
|
|
|
|
int where);
|
|
|
|
/* default ECAM ops */
|
2020-04-10 07:49:21 +08:00
|
|
|
extern const struct pci_ecam_ops pci_generic_ecam_ops;
|
2016-05-10 23:19:51 +08:00
|
|
|
|
2016-11-03 00:11:27 +08:00
|
|
|
#if defined(CONFIG_ACPI) && defined(CONFIG_PCI_QUIRKS)
|
2020-04-10 07:49:21 +08:00
|
|
|
extern const struct pci_ecam_ops pci_32b_ops; /* 32-bit accesses only */
|
2020-08-07 05:57:34 +08:00
|
|
|
extern const struct pci_ecam_ops pci_32b_read_ops; /* 32-bit read only */
|
2020-04-10 07:49:21 +08:00
|
|
|
extern const struct pci_ecam_ops hisi_pcie_ops; /* HiSilicon */
|
|
|
|
extern const struct pci_ecam_ops thunder_pem_ecam_ops; /* Cavium ThunderX 1.x & 2.x */
|
|
|
|
extern const struct pci_ecam_ops pci_thunder_ecam_ops; /* Cavium ThunderX 1.x */
|
|
|
|
extern const struct pci_ecam_ops xgene_v1_pcie_ecam_ops; /* APM X-Gene PCIe v1 */
|
|
|
|
extern const struct pci_ecam_ops xgene_v2_pcie_ecam_ops; /* APM X-Gene PCIe v2.x */
|
|
|
|
extern const struct pci_ecam_ops al_pcie_ops; /* Amazon Annapurna Labs PCIe */
|
2021-04-16 21:45:37 +08:00
|
|
|
extern const struct pci_ecam_ops tegra194_pcie_ops; /* Tegra194 PCIe */
|
2022-07-14 20:42:12 +08:00
|
|
|
extern const struct pci_ecam_ops loongson_pci_ecam_ops; /* Loongson PCIe */
|
2016-11-03 00:11:27 +08:00
|
|
|
#endif
|
|
|
|
|
2020-04-10 07:49:22 +08:00
|
|
|
#if IS_ENABLED(CONFIG_PCI_HOST_COMMON)
|
2016-05-12 06:34:46 +08:00
|
|
|
/* for DT-based PCI controllers that support ECAM */
|
2020-04-10 07:49:23 +08:00
|
|
|
int pci_host_common_probe(struct platform_device *pdev);
|
2018-05-15 17:07:06 +08:00
|
|
|
int pci_host_common_remove(struct platform_device *pdev);
|
2016-05-12 06:34:46 +08:00
|
|
|
#endif
|
2016-05-10 23:19:51 +08:00
|
|
|
#endif
|