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
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3) #include <linux/pci.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4) #include <linux/range.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6) #include "bus_numa.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) LIST_HEAD(pci_root_infos);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) static struct pci_root_info *x86_find_pci_root_info(int bus)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) 	struct pci_root_info *info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) 	list_for_each_entry(info, &pci_root_infos, list)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) 		if (info->busn.start == bus)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) 			return info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) 	return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) int x86_pci_root_bus_node(int bus)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 	struct pci_root_info *info = x86_find_pci_root_info(bus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 	if (!info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 		return NUMA_NO_NODE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 	return info->node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) void x86_pci_root_bus_resources(int bus, struct list_head *resources)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 	struct pci_root_info *info = x86_find_pci_root_info(bus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 	struct pci_root_res *root_res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 	struct resource_entry *window;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 	bool found = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 	if (!info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 		goto default_resources;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	printk(KERN_DEBUG "PCI: root bus %02x: hardware-probed resources\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 	       bus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 	/* already added by acpi ? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 	resource_list_for_each_entry(window, resources)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 		if (window->res->flags & IORESOURCE_BUS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 			found = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	if (!found)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 		pci_add_resource(resources, &info->busn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	list_for_each_entry(root_res, &info->resources, list)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 		pci_add_resource(resources, &root_res->res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) default_resources:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	 * We don't have any host bridge aperture information from the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	 * "native host bridge drivers," e.g., amd_bus or broadcom_bus,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	 * so fall back to the defaults historically used by pci_create_bus().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	printk(KERN_DEBUG "PCI: root bus %02x: using default resources\n", bus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	pci_add_resource(resources, &ioport_resource);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	pci_add_resource(resources, &iomem_resource);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) struct pci_root_info __init *alloc_pci_root_info(int bus_min, int bus_max,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 						 int node, int link)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	struct pci_root_info *info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	info = kzalloc(sizeof(*info), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	if (!info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 		return info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	sprintf(info->name, "PCI Bus #%02x", bus_min);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	INIT_LIST_HEAD(&info->resources);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	info->busn.name  = info->name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	info->busn.start = bus_min;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	info->busn.end   = bus_max;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	info->busn.flags = IORESOURCE_BUS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	info->node = node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	info->link = link;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	list_add_tail(&info->list, &pci_root_infos);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	return info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) void update_res(struct pci_root_info *info, resource_size_t start,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 		resource_size_t end, unsigned long flags, int merge)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	struct resource *res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	struct pci_root_res *root_res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	if (start > end)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	if (start == MAX_RESOURCE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	if (!merge)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 		goto addit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	/* try to merge it with old one */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	list_for_each_entry(root_res, &info->resources, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 		resource_size_t final_start, final_end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 		resource_size_t common_start, common_end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 		res = &root_res->res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 		if (res->flags != flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 		common_start = max(res->start, start);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 		common_end = min(res->end, end);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 		if (common_start > common_end + 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 		final_start = min(res->start, start);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 		final_end = max(res->end, end);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 		res->start = final_start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 		res->end = final_end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) addit:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 	/* need to add that */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 	root_res = kzalloc(sizeof(*root_res), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 	if (!root_res)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 	res = &root_res->res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	res->name = info->name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 	res->flags = flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 	res->start = start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 	res->end = end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 	list_add_tail(&root_res->list, &info->resources);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) }