Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * Common pmac/prep/chrp pci routines. -- Cort
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) #include <linux/pci.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) #include <linux/delay.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #include <linux/string.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/capability.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/sched.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/memblock.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/syscalls.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/irq.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <linux/list.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <linux/of.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #include <linux/export.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #include <asm/processor.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) #include <asm/io.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) #include <asm/prom.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) #include <asm/sections.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) #include <asm/pci-bridge.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) #include <asm/ppc-pci.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) #include <asm/byteorder.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) #include <linux/uaccess.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) #include <asm/machdep.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) #undef DEBUG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) unsigned long isa_io_base     = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) unsigned long pci_dram_offset = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) int pcibios_assign_bus_offset = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) EXPORT_SYMBOL(isa_io_base);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) EXPORT_SYMBOL(pci_dram_offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) void pcibios_make_OF_bus_map(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) static void fixup_cpc710_pci64(struct pci_dev* dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) static u8* pci_to_OF_bus_map;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) /* By default, we don't re-assign bus numbers. We do this only on
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46)  * some pmacs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) static int pci_assign_all_buses;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) static int pci_bus_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) /* This will remain NULL for now, until isa-bridge.c is made common
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53)  * to both 32-bit and 64-bit.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) struct pci_dev *isa_bridge_pcidev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) EXPORT_SYMBOL_GPL(isa_bridge_pcidev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) fixup_cpc710_pci64(struct pci_dev* dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	/* Hide the PCI64 BARs from the kernel as their content doesn't
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	 * fit well in the resource management
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	dev->resource[0].start = dev->resource[0].end = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	dev->resource[0].flags = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	dev->resource[1].start = dev->resource[1].end = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	dev->resource[1].flags = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_IBM,	PCI_DEVICE_ID_IBM_CPC710_PCI64,	fixup_cpc710_pci64);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72)  * Functions below are used on OpenFirmware machines.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) make_one_node_map(struct device_node* node, u8 pci_bus)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	const int *bus_range;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	int len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	if (pci_bus >= pci_bus_count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	bus_range = of_get_property(node, "bus-range", &len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	if (bus_range == NULL || len < 2 * sizeof(int)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 		printk(KERN_WARNING "Can't get bus-range for %pOF, "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 		       "assuming it starts at 0\n", node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 		pci_to_OF_bus_map[pci_bus] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 		pci_to_OF_bus_map[pci_bus] = bus_range[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	for_each_child_of_node(node, node) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 		struct pci_dev* dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 		const unsigned int *class_code, *reg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 		class_code = of_get_property(node, "class-code", NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 		if (!class_code || ((*class_code >> 8) != PCI_CLASS_BRIDGE_PCI &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 			(*class_code >> 8) != PCI_CLASS_BRIDGE_CARDBUS))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 		reg = of_get_property(node, "reg", NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 		if (!reg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 		dev = pci_get_domain_bus_and_slot(0, pci_bus,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 						  ((reg[0] >> 8) & 0xff));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 		if (!dev || !dev->subordinate) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 			pci_dev_put(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 		make_one_node_map(node, dev->subordinate->number);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 		pci_dev_put(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) pcibios_make_OF_bus_map(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	struct pci_controller *hose, *tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	struct property *map_prop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	struct device_node *dn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	pci_to_OF_bus_map = kmalloc(pci_bus_count, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	if (!pci_to_OF_bus_map) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 		printk(KERN_ERR "Can't allocate OF bus map !\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	/* We fill the bus map with invalid values, that helps
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 	 * debugging.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	for (i=0; i<pci_bus_count; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 		pci_to_OF_bus_map[i] = 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 	/* For each hose, we begin searching bridges */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	list_for_each_entry_safe(hose, tmp, &hose_list, list_node) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 		struct device_node* node = hose->dn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 		if (!node)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 		make_one_node_map(node, hose->first_busno);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	dn = of_find_node_by_path("/");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 	map_prop = of_find_property(dn, "pci-OF-bus-map", NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 	if (map_prop) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 		BUG_ON(pci_bus_count > map_prop->length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 		memcpy(map_prop->value, pci_to_OF_bus_map, pci_bus_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 	of_node_put(dn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) #ifdef DEBUG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 	printk("PCI->OF bus map:\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 	for (i=0; i<pci_bus_count; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 		if (pci_to_OF_bus_map[i] == 0xff)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 		printk("%d -> %d\n", i, pci_to_OF_bus_map[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159)  * Returns the PCI device matching a given OF node
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) int pci_device_from_OF_node(struct device_node *node, u8 *bus, u8 *devfn)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 	struct pci_dev *dev = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 	const __be32 *reg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 	int size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 	/* Check if it might have a chance to be a PCI device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 	if (!pci_find_hose_for_OF_device(node))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 	reg = of_get_property(node, "reg", &size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 	if (!reg || size < 5 * sizeof(u32))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 	*bus = (be32_to_cpup(&reg[0]) >> 16) & 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 	*devfn = (be32_to_cpup(&reg[0]) >> 8) & 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 	/* Ok, here we need some tweak. If we have already renumbered
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 	 * all busses, we can't rely on the OF bus number any more.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 	 * the pci_to_OF_bus_map is not enough as several PCI busses
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 	 * may match the same OF bus number.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 	if (!pci_to_OF_bus_map)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 	for_each_pci_dev(dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 		if (pci_to_OF_bus_map[dev->bus->number] == *bus &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 				dev->devfn == *devfn) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 			*bus = dev->bus->number;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 			pci_dev_put(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 			return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 	return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) EXPORT_SYMBOL(pci_device_from_OF_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) /* We create the "pci-OF-bus-map" property now so it appears in the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199)  * /proc device tree
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) void __init
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) pci_create_OF_bus_map(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 	struct property* of_prop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 	struct device_node *dn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 	of_prop = memblock_alloc(sizeof(struct property) + 256,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 				 SMP_CACHE_BYTES);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 	if (!of_prop)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 		panic("%s: Failed to allocate %zu bytes\n", __func__,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 		      sizeof(struct property) + 256);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 	dn = of_find_node_by_path("/");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 	if (dn) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 		memset(of_prop, -1, sizeof(struct property) + 256);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 		of_prop->name = "pci-OF-bus-map";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 		of_prop->length = 256;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 		of_prop->value = &of_prop[1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 		of_add_property(dn, of_prop);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 		of_node_put(dn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) void pcibios_setup_phb_io_space(struct pci_controller *hose)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 	unsigned long io_offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 	struct resource *res = &hose->io_resource;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 	/* Fixup IO space offset */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 	io_offset = pcibios_io_space_offset(hose);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 	res->start += io_offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 	res->end += io_offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) static int __init pcibios_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 	struct pci_controller *hose, *tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 	int next_busno = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 	printk(KERN_INFO "PCI: Probing PCI hardware\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 	if (pci_has_flag(PCI_REASSIGN_ALL_BUS))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 		pci_assign_all_buses = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 	/* Scan all of the recorded PCI controllers.  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 	list_for_each_entry_safe(hose, tmp, &hose_list, list_node) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 		if (pci_assign_all_buses)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 			hose->first_busno = next_busno;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 		hose->last_busno = 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 		pcibios_scan_phb(hose);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 		pci_bus_add_devices(hose->bus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 		if (pci_assign_all_buses || next_busno <= hose->last_busno)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 			next_busno = hose->last_busno + pcibios_assign_bus_offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 	pci_bus_count = next_busno;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 	/* OpenFirmware based machines need a map of OF bus
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 	 * numbers vs. kernel bus numbers since we may have to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 	 * remap them.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 	if (pci_assign_all_buses)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 		pcibios_make_OF_bus_map();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 	/* Call common code to handle resource allocation */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 	pcibios_resource_survey();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 	/* Call machine dependent fixup */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 	if (ppc_md.pcibios_fixup)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 		ppc_md.pcibios_fixup();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 	/* Call machine dependent post-init code */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 	if (ppc_md.pcibios_after_init)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 		ppc_md.pcibios_after_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) subsys_initcall(pcibios_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) static struct pci_controller*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) pci_bus_to_hose(int bus)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 	struct pci_controller *hose, *tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 	list_for_each_entry_safe(hose, tmp, &hose_list, list_node)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 		if (bus >= hose->first_busno && bus <= hose->last_busno)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 			return hose;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 	return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) /* Provide information on locations of various I/O regions in physical
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291)  * memory.  Do this on a per-card basis so that we choose the right
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292)  * root bridge.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293)  * Note that the returned IO or memory base is a physical address
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) SYSCALL_DEFINE3(pciconfig_iobase, long, which,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 		unsigned long, bus, unsigned long, devfn)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 	struct pci_controller* hose;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 	long result = -EOPNOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 	hose = pci_bus_to_hose(bus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 	if (!hose)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 	switch (which) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 	case IOBASE_BRIDGE_NUMBER:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 		return (long)hose->first_busno;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 	case IOBASE_MEMORY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 		return (long)hose->mem_offset[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 	case IOBASE_IO:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 		return (long)hose->io_base_phys;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 	case IOBASE_ISA_IO:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 		return (long)isa_io_base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 	case IOBASE_ISA_MEM:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 		return (long)isa_mem_base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 	return result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) }