pci: Add generic ECAM host support
Unlike x86, other architectures using generic ECAM PCI host
do not have a luxury of PCI bus initialized by a BIOS and
ready to use at start. Thus, we need allocate and assign
resources to all devices, much like an architecture's
firmware would do.
There is no any sort of resource management for memory and
io spaces, since only ones-per-BAR allocations are expected
and no deallocations at all.
Cc: Thomas Huth <thuth@redhat.com>
Cc: Andrew Jones <drjones@redhat.com>
Cc: Peter Xu <peterx@redhat.com>
Suggested-by: Andrew Jones <drjones@redhat.com>
Signed-off-by: Alexander Gordeev <agordeev@redhat.com>
Message-Id: <6488b060e4cbbead5a5ec525a53d65773ceb5f87.1478512824.git.agordeev@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
diff --git a/lib/pci-host-generic.h b/lib/pci-host-generic.h
new file mode 100644
index 0000000..fd30e7c
--- /dev/null
+++ b/lib/pci-host-generic.h
@@ -0,0 +1,46 @@
+#ifndef PCI_HOST_GENERIC_H
+#define PCI_HOST_GENERIC_H
+/*
+ * PCI host bridge supporting structures and constants
+ *
+ * Copyright (C) 2016, Red Hat Inc, Alexander Gordeev <agordeev@redhat.com>
+ *
+ * This work is licensed under the terms of the GNU LGPL, version 2.
+ */
+#include "libcflat.h"
+
+struct pci_addr_space {
+ phys_addr_t pci_start;
+ phys_addr_t start;
+ phys_addr_t size;
+ phys_addr_t allocated;
+ int type;
+};
+
+struct pci_host_bridge {
+ phys_addr_t start;
+ phys_addr_t size;
+ int bus;
+ int bus_max;
+ int nr_addr_spaces;
+ struct pci_addr_space addr_space[];
+};
+
+/*
+ * The following constants are derived from Linux, see this source:
+ *
+ * drivers/pci/host/pci-host-generic.c
+ * struct gen_pci_cfg_bus_ops::bus_shift
+ * int gen_pci_parse_map_cfg_windows(struct gen_pci *pci)
+ *
+ * Documentation/devicetree/bindings/pci/host-generic-pci.txt describes
+ * ECAM Configuration Space is be memory-mapped by concatenating the various
+ * components to form an offset:
+ *
+ * cfg_offset(bus, device, function, register) =
+ * bus << 20 | device << 15 | function << 12 | register
+ */
+#define PCI_ECAM_BUS_SHIFT 20
+#define PCI_ECAM_DEVFN_SHIFT 12
+
+#endif