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) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * ranges.c: Handle ranges in newer proms for obio/sbus.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  * Copyright (C) 1997 Jakub Jelinek (jj@sunsite.mff.cuni.cz)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <asm/openprom.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <asm/oplib.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <asm/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) static struct linux_prom_ranges promlib_obio_ranges[PROMREG_MAX];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) static int num_obio_ranges;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) /* Adjust register values based upon the ranges parameters. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) static void prom_adjust_regs(struct linux_prom_registers *regp, int nregs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) 			     struct linux_prom_ranges *rangep, int nranges)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 	int regc, rngc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 	for (regc = 0; regc < nregs; regc++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 		for (rngc = 0; rngc < nranges; rngc++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 			if (regp[regc].which_io == rangep[rngc].ot_child_space)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 				break; /* Fount it */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 		if (rngc == nranges) /* oops */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 			prom_printf("adjust_regs: Could not find range with matching bus type...\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 		regp[regc].which_io = rangep[rngc].ot_parent_space;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 		regp[regc].phys_addr -= rangep[rngc].ot_child_base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 		regp[regc].phys_addr += rangep[rngc].ot_parent_base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) static void prom_adjust_ranges(struct linux_prom_ranges *ranges1, int nranges1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 			       struct linux_prom_ranges *ranges2, int nranges2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 	int rng1c, rng2c;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 	for (rng1c = 0; rng1c < nranges1; rng1c++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 		for (rng2c = 0; rng2c < nranges2; rng2c++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 			if (ranges1[rng1c].ot_parent_space == ranges2[rng2c].ot_child_space &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 			   ranges1[rng1c].ot_parent_base >= ranges2[rng2c].ot_child_base &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 			   ranges2[rng2c].ot_child_base + ranges2[rng2c].or_size - ranges1[rng1c].ot_parent_base > 0U)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 		if (rng2c == nranges2) /* oops */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 			prom_printf("adjust_ranges: Could not find matching bus type...\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 		else if (ranges1[rng1c].ot_parent_base + ranges1[rng1c].or_size > ranges2[rng2c].ot_child_base + ranges2[rng2c].or_size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 			ranges1[rng1c].or_size = ranges2[rng2c].ot_child_base + ranges2[rng2c].or_size - ranges1[rng1c].ot_parent_base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 		ranges1[rng1c].ot_parent_space = ranges2[rng2c].ot_parent_space;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 		ranges1[rng1c].ot_parent_base += ranges2[rng2c].ot_parent_base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) /* Apply probed obio ranges to registers passed, if no ranges return. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) void prom_apply_obio_ranges(struct linux_prom_registers *regs, int nregs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	if (num_obio_ranges)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 		prom_adjust_regs(regs, nregs, promlib_obio_ranges, num_obio_ranges);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) EXPORT_SYMBOL(prom_apply_obio_ranges);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) void __init prom_ranges_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	phandle node, obio_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	int success;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	num_obio_ranges = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	/* Check for obio and sbus ranges. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	node = prom_getchild(prom_root_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	obio_node = prom_searchsiblings(node, "obio");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	if (obio_node) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 		success = prom_getproperty(obio_node, "ranges",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 					   (char *) promlib_obio_ranges,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 					   sizeof(promlib_obio_ranges));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 		if (success != -1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 			num_obio_ranges = (success / sizeof(struct linux_prom_ranges));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	if (num_obio_ranges)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 		prom_printf("PROMLIB: obio_ranges %d\n", num_obio_ranges);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) void prom_apply_generic_ranges(phandle node, phandle parent,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 			       struct linux_prom_registers *regs, int nregs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	int success;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	int num_ranges;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	struct linux_prom_ranges ranges[PROMREG_MAX];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	success = prom_getproperty(node, "ranges",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 				   (char *) ranges,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 				   sizeof(ranges));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	if (success != -1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 		num_ranges = (success / sizeof(struct linux_prom_ranges));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 		if (parent) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 			struct linux_prom_ranges parent_ranges[PROMREG_MAX];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 			int num_parent_ranges;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 			success = prom_getproperty(parent, "ranges",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 						   (char *) parent_ranges,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 						   sizeof(parent_ranges));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 			if (success != -1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 				num_parent_ranges = (success / sizeof(struct linux_prom_ranges));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 				prom_adjust_ranges(ranges, num_ranges, parent_ranges, num_parent_ranges);
^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) 		prom_adjust_regs(regs, nregs, ranges, num_ranges);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) }