0001
0002
0003
0004
0005
0006
0007
0008
0009 #include <linux/init.h>
0010 #include <linux/module.h>
0011
0012 #include <asm/openprom.h>
0013 #include <asm/oplib.h>
0014 #include <asm/types.h>
0015
0016 static struct linux_prom_ranges promlib_obio_ranges[PROMREG_MAX];
0017 static int num_obio_ranges;
0018
0019
0020 static void prom_adjust_regs(struct linux_prom_registers *regp, int nregs,
0021 struct linux_prom_ranges *rangep, int nranges)
0022 {
0023 int regc, rngc;
0024
0025 for (regc = 0; regc < nregs; regc++) {
0026 for (rngc = 0; rngc < nranges; rngc++)
0027 if (regp[regc].which_io == rangep[rngc].ot_child_space)
0028 break;
0029 if (rngc == nranges)
0030 prom_printf("adjust_regs: Could not find range with matching bus type...\n");
0031 regp[regc].which_io = rangep[rngc].ot_parent_space;
0032 regp[regc].phys_addr -= rangep[rngc].ot_child_base;
0033 regp[regc].phys_addr += rangep[rngc].ot_parent_base;
0034 }
0035 }
0036
0037 static void prom_adjust_ranges(struct linux_prom_ranges *ranges1, int nranges1,
0038 struct linux_prom_ranges *ranges2, int nranges2)
0039 {
0040 int rng1c, rng2c;
0041
0042 for (rng1c = 0; rng1c < nranges1; rng1c++) {
0043 for (rng2c = 0; rng2c < nranges2; rng2c++)
0044 if (ranges1[rng1c].ot_parent_space == ranges2[rng2c].ot_child_space &&
0045 ranges1[rng1c].ot_parent_base >= ranges2[rng2c].ot_child_base &&
0046 ranges2[rng2c].ot_child_base + ranges2[rng2c].or_size - ranges1[rng1c].ot_parent_base > 0U)
0047 break;
0048 if (rng2c == nranges2)
0049 prom_printf("adjust_ranges: Could not find matching bus type...\n");
0050 else if (ranges1[rng1c].ot_parent_base + ranges1[rng1c].or_size > ranges2[rng2c].ot_child_base + ranges2[rng2c].or_size)
0051 ranges1[rng1c].or_size = ranges2[rng2c].ot_child_base + ranges2[rng2c].or_size - ranges1[rng1c].ot_parent_base;
0052 ranges1[rng1c].ot_parent_space = ranges2[rng2c].ot_parent_space;
0053 ranges1[rng1c].ot_parent_base += ranges2[rng2c].ot_parent_base;
0054 }
0055 }
0056
0057
0058 void prom_apply_obio_ranges(struct linux_prom_registers *regs, int nregs)
0059 {
0060 if (num_obio_ranges)
0061 prom_adjust_regs(regs, nregs, promlib_obio_ranges, num_obio_ranges);
0062 }
0063 EXPORT_SYMBOL(prom_apply_obio_ranges);
0064
0065 void __init prom_ranges_init(void)
0066 {
0067 phandle node, obio_node;
0068 int success;
0069
0070 num_obio_ranges = 0;
0071
0072
0073 node = prom_getchild(prom_root_node);
0074 obio_node = prom_searchsiblings(node, "obio");
0075
0076 if (obio_node) {
0077 success = prom_getproperty(obio_node, "ranges",
0078 (char *) promlib_obio_ranges,
0079 sizeof(promlib_obio_ranges));
0080 if (success != -1)
0081 num_obio_ranges = (success / sizeof(struct linux_prom_ranges));
0082 }
0083
0084 if (num_obio_ranges)
0085 prom_printf("PROMLIB: obio_ranges %d\n", num_obio_ranges);
0086 }
0087
0088 void prom_apply_generic_ranges(phandle node, phandle parent,
0089 struct linux_prom_registers *regs, int nregs)
0090 {
0091 int success;
0092 int num_ranges;
0093 struct linux_prom_ranges ranges[PROMREG_MAX];
0094
0095 success = prom_getproperty(node, "ranges",
0096 (char *) ranges,
0097 sizeof(ranges));
0098 if (success != -1) {
0099 num_ranges = (success / sizeof(struct linux_prom_ranges));
0100 if (parent) {
0101 struct linux_prom_ranges parent_ranges[PROMREG_MAX];
0102 int num_parent_ranges;
0103
0104 success = prom_getproperty(parent, "ranges",
0105 (char *) parent_ranges,
0106 sizeof(parent_ranges));
0107 if (success != -1) {
0108 num_parent_ranges = (success / sizeof(struct linux_prom_ranges));
0109 prom_adjust_ranges(ranges, num_ranges, parent_ranges, num_parent_ranges);
0110 }
0111 }
0112 prom_adjust_regs(regs, nregs, ranges, num_ranges);
0113 }
0114 }