Commit 40399e6d authored by Andrew Morton's avatar Andrew Morton Committed by Linus Torvalds

[PATCH] ppc64: Change to new OF device tree API, from Nathan Lynch

From: Anton Blanchard <anton@samba.org>

Attached is a patch which replaces all the uses of the old device tree API in
arch/ppc64.  Patch is against 2.6.0-test5 (cset 1.1328) from ameslab bk, plus
the patch from my previous message.  I've tested this on a pSeries LPAR.
parent 4e0cbcfe
......@@ -96,16 +96,19 @@ chrp_get_cpuinfo(struct seq_file *m)
seq_printf(m, "timebase\t: %lu\n", ppc_tb_freq);
root = find_path_device("/");
root = of_find_node_by_path("/");
if (root)
model = get_property(root, "model", NULL);
seq_printf(m, "machine\t\t: CHRP %s\n", model);
of_node_put(root);
}
#define I8042_DATA_REG 0x60
void __init chrp_request_regions(void)
void __init chrp_request_regions(void)
{
struct device_node *i8042;
request_region(0x20,0x20,"pic1");
request_region(0xa0,0x20,"pic2");
request_region(0x00,0x20,"dma1");
......@@ -118,8 +121,9 @@ void __init chrp_request_regions(void)
* tree and reserve the region if it does not appear. Later on
* the i8042 code will try and reserve this region and fail.
*/
if (!find_type_devices("8042"))
if (!(i8042 = of_find_node_by_type(NULL, "8042")))
request_region(I8042_DATA_REG, 16, "reserved (no i8042)");
of_node_put(i8042);
}
void __init
......@@ -158,7 +162,7 @@ chrp_setup_arch(void)
#endif
/* Find the Open PIC if present */
root = find_path_device("/");
root = of_find_node_by_path("/");
opprop = (unsigned int *) get_property(root,
"platform-open-pic", NULL);
if (opprop != 0) {
......@@ -170,6 +174,7 @@ chrp_setup_arch(void)
printk(KERN_DEBUG "OpenPIC addr: %lx\n", openpic);
OpenPIC_Addr = __ioremap(openpic, 0x40000, _PAGE_NO_CACHE);
}
of_node_put(root);
#ifdef CONFIG_DUMMY_CONSOLE
conswitchp = &dummy_con;
......@@ -271,7 +276,7 @@ chrp_init(unsigned long r3, unsigned long r4, unsigned long r5,
struct device_node * dn;
char * hypertas;
unsigned int len;
dn = find_path_device("/rtas");
dn = of_find_node_by_path("/rtas");
cur_cpu_spec->firmware_features = 0;
hypertas = get_property(dn, "ibm,hypertas-functions", &len);
if (hypertas) {
......@@ -290,6 +295,7 @@ chrp_init(unsigned long r3, unsigned long r4, unsigned long r5,
hypertas+= hypertas_len +1;
}
}
of_node_put(dn);
udbg_printf("firmware_features bitmask: 0x%x \n",
cur_cpu_spec->firmware_features);
}
......@@ -405,11 +411,11 @@ void __init pSeries_calibrate_decr(void)
/*
* The cpu node should have a timebase-frequency property
* to tell us the rate at which the decrementer counts.
* to tell us the rate at which the decrementer counts.
*/
freq = 16666000; /* hardcoded default */
cpu = find_type_devices("cpu");
if (cpu != 0) {
cpu = of_find_node_by_type(NULL, "cpu");
if (cpu != 0) {
fp = (int *) get_property(cpu, "timebase-frequency", NULL);
if (fp != 0)
freq = *fp;
......@@ -422,11 +428,12 @@ void __init pSeries_calibrate_decr(void)
processor_freq = *fp;
}
ppc_proc_freq = processor_freq;
printk("time_init: decrementer frequency = %lu.%.6lu MHz\n",
freq/1000000, freq%1000000 );
of_node_put(cpu);
printk("time_init: decrementer frequency = %lu.%.6lu MHz\n",
freq/1000000, freq%1000000);
printk("time_init: processor frequency = %lu.%.6lu MHz\n",
processor_freq/1000000, processor_freq%1000000 );
processor_freq/1000000, processor_freq%1000000);
tb_ticks_per_jiffy = freq / HZ;
tb_ticks_per_sec = tb_ticks_per_jiffy * HZ;
......
......@@ -257,7 +257,7 @@ void eeh_init(void)
/* Enable EEH for all adapters. Note that eeh requires buid's */
info.adapters_enabled = 0;
for (phb = find_devices("pci"); phb; phb = phb->next) {
for (phb = of_find_node_by_name(NULL, "pci"); phb; phb = of_find_node_by_name(phb, "pci")) {
int len;
int *buid_vals = (int *) get_property(phb, "ibm,fw-phb-id", &len);
if (!buid_vals)
......
......@@ -116,7 +116,7 @@ int __init nvram_init(void)
{
struct device_node *nvram;
unsigned int *nbytes_p, proplen;
if ((nvram = find_type_devices("nvram")) != NULL) {
if ((nvram = of_find_node_by_type(NULL, "nvram")) != NULL) {
nbytes_p = (unsigned int *)get_property(nvram, "#bytes", &proplen);
if (nbytes_p && proplen == sizeof(unsigned int)) {
rtas_nvram_size = *nbytes_p;
......@@ -125,6 +125,7 @@ int __init nvram_init(void)
nvram_fetch = rtas_token("nvram-fetch");
nvram_store = rtas_token("nvram-store");
printk(KERN_INFO "PPC64 nvram contains %d bytes\n", rtas_nvram_size);
of_node_put(nvram);
return misc_register(&nvram_dev);
}
......
......@@ -142,7 +142,7 @@ void __init openpic_init_IRQ(void)
struct device_node *kbd;
#endif
if (!(np = find_devices("pci"))
if (!(np = of_find_node_by_name(NULL, "pci"))
|| !(addrp = (unsigned int *)
get_property(np, "8259-interrupt-acknowledge", NULL)))
printk(KERN_ERR "Cannot find pci to get ack address\n");
......@@ -158,6 +158,7 @@ void __init openpic_init_IRQ(void)
openpic_init(1, NUM_8259_INTERRUPTS, chrp_int_ack_special, nmi_irq);
for ( i = 0 ; i < NUM_8259_INTERRUPTS ; i++ )
irq_desc[i].handler = &i8259_pic;
of_node_put(np);
}
static inline u_int openpic_read(volatile u_int *addr)
......
......@@ -389,10 +389,11 @@ void hpte_init_pSeries(void)
ppc_md.hpte_remove = pSeries_hpte_remove;
/* Disable TLB batching on nighthawk */
root = find_path_device("/");
root = of_find_node_by_path("/");
if (root) {
model = get_property(root, "model", NULL);
if (strcmp(model, "CHRP IBM,9076-N81"))
ppc_md.flush_hash_range = pSeries_flush_hash_range;
of_node_put(root);
}
}
......@@ -234,11 +234,12 @@ void pSeriesLP_init_early(void)
* is the starting termno (the one we use) and the second is the
* number of terminals.
*/
np = find_path_device("/rtas");
np = of_find_node_by_path("/rtas");
if (np) {
u32 *termno = (u32 *)get_property(np, "ibm,termno", 0);
if (termno)
vtermno = termno[0];
of_node_put(np);
}
ppc_md.udbg_putc = udbg_putcLP;
ppc_md.udbg_getc = udbg_getcLP;
......@@ -289,15 +290,17 @@ int hvc_count(int *start_termno)
{
u32 *termno;
struct device_node *dn;
int ret = 0;
if ((dn = find_path_device("/rtas")) != NULL) {
if ((dn = of_find_node_by_path("/rtas")) != NULL) {
if ((termno = (u32 *)get_property(dn, "ibm,termno", 0)) != NULL) {
if (start_termno)
*start_termno = termno[0];
return termno[1];
ret = termno[1];
}
of_node_put(dn);
}
return 0;
return ret;
}
......
......@@ -188,6 +188,7 @@ static void __init pci_process_bridge_OF_ranges(struct pci_controller *hose,
struct resource *res;
int np, na = prom_n_addr_cells(dev);
unsigned long pci_addr, cpu_phys_addr;
struct device_node *isa_dn;
np = na + 5;
......@@ -219,8 +220,11 @@ static void __init pci_process_bridge_OF_ranges(struct pci_controller *hose,
size, _PAGE_NO_CACHE);
if (primary) {
pci_io_base = (unsigned long)hose->io_base_virt;
if (find_type_devices("isa"))
isa_dn = of_find_node_by_type(NULL, "isa");
if (isa_dn) {
isa_io_base = pci_io_base;
of_node_put(isa_dn);
}
}
res = &hose->io_resource;
......@@ -386,7 +390,7 @@ unsigned long __init find_and_init_phbs(void)
unsigned int root_size_cells = 0;
unsigned int index;
unsigned int *opprop;
struct device_node *root = find_path_device("/");
struct device_node *root = of_find_node_by_path("/");
read_pci_config = rtas_token("read-pci-config");
write_pci_config = rtas_token("write-pci-config");
......@@ -402,7 +406,9 @@ unsigned long __init find_and_init_phbs(void)
index = 0;
for (node = root->child; node != NULL; node = node->sibling) {
for (node = of_get_next_child(root, NULL);
node != NULL;
node = of_get_next_child(root, node)) {
if (node->type == NULL || strcmp(node->type, "pci") != 0)
continue;
......@@ -420,6 +426,7 @@ unsigned long __init find_and_init_phbs(void)
index++;
}
of_node_put(root);
pci_devs_phb_init();
return 0;
......@@ -525,11 +532,12 @@ static void check_s7a(void)
struct device_node *root;
char *model;
root = find_path_device("/");
root = of_find_node_by_path("/");
if (root) {
model = get_property(root, "model", NULL);
if (model && !strcmp(model, "IBM,7013-S7A"))
s7a_workaround = 1;
of_node_put(root);
}
}
......
......@@ -1504,7 +1504,7 @@ finish_device_tree(void)
klimit = mem;
rtas.dev = find_devices("rtas");
rtas.dev = of_find_node_by_name(NULL, "rtas");
}
static unsigned long __init
......@@ -1956,11 +1956,14 @@ int
machine_is_compatible(const char *compat)
{
struct device_node *root;
root = find_path_device("/");
if (root == 0)
return 0;
return device_is_compatible(root, compat);
int rc = 0;
root = of_find_node_by_path("/");
if (root) {
rc = device_is_compatible(root, compat);
of_node_put(root);
}
return rc;
}
/*
......
......@@ -70,27 +70,29 @@ static int __init init_ras_IRQ(void)
struct device_node *np;
unsigned int *ireg, len, i;
if((np = find_path_device("/event-sources/internal-errors")) &&
(ireg = (unsigned int *)get_property(np, "open-pic-interrupt",
&len))) {
for(i=0; i<(len / sizeof(*ireg)); i++) {
if ((np = of_find_node_by_path("/event-sources/internal-errors")) &&
(ireg = (unsigned int *)get_property(np, "open-pic-interrupt",
&len))) {
for (i=0; i<(len / sizeof(*ireg)); i++) {
request_irq(virt_irq_create_mapping(*(ireg)) + NUM_8259_INTERRUPTS,
ras_error_interrupt, 0,
"RAS_ERROR", NULL);
ireg++;
}
}
of_node_put(np);
if((np = find_path_device("/event-sources/epow-events")) &&
(ireg = (unsigned int *)get_property(np, "open-pic-interrupt",
&len))) {
for(i=0; i<(len / sizeof(*ireg)); i++) {
if ((np = of_find_node_by_path("/event-sources/epow-events")) &&
(ireg = (unsigned int *)get_property(np, "open-pic-interrupt",
&len))) {
for (i=0; i<(len / sizeof(*ireg)); i++) {
request_irq(virt_irq_create_mapping(*(ireg)) + NUM_8259_INTERRUPTS,
ras_epow_interrupt, 0,
"RAS_EPOW", NULL);
ireg++;
}
}
of_node_put(np);
return 1;
}
......
......@@ -200,7 +200,7 @@ void proc_rtas_init(void)
{
struct proc_dir_entry *entry;
rtas_node = find_devices("rtas");
rtas_node = of_find_node_by_name(NULL, "rtas");
if ((rtas_node == NULL) || (systemcfg->platform == PLATFORM_ISERIES_LPAR)) {
return;
}
......
......@@ -165,11 +165,12 @@ static int get_eventscan_parms(void)
struct device_node *node;
int *ip;
node = find_path_device("/rtas");
node = of_find_node_by_path("/rtas");
ip = (int *)get_property(node, "rtas-event-scan-rate", NULL);
if (ip == NULL) {
printk(KERN_ERR "rtasd: no rtas-event-scan-rate\n");
of_node_put(node);
return -1;
}
rtas_event_scan_rate = *ip;
......@@ -178,6 +179,7 @@ static int get_eventscan_parms(void)
ip = (int *)get_property(node, "rtas-error-log-max", NULL);
if (ip == NULL) {
printk(KERN_ERR "rtasd: no rtas-error-log-max\n");
of_node_put(node);
return -1;
}
rtas_error_log_max = *ip;
......@@ -187,6 +189,7 @@ static int get_eventscan_parms(void)
printk(KERN_ERR "rtasd: truncated error log from %d to %d bytes\n", rtas_error_log_max, RTAS_ERROR_LOG_MAX);
rtas_error_log_max = RTAS_ERROR_LOG_MAX;
}
of_node_put(node);
return 0;
}
......
......@@ -315,13 +315,14 @@ static int show_cpuinfo(struct seq_file *m, void *v)
struct device_node *cpu_node;
int *fp;
cpu_node = find_type_devices("cpu");
cpu_node = of_find_node_by_type(NULL, "cpu");
if (cpu_node) {
fp = (int *) get_property(cpu_node, "clock-frequency",
NULL);
if (fp)
seq_printf(m, "clock\t\t: %dMHz\n",
*fp / 1000000);
of_node_put(cpu_node);
}
}
......@@ -375,11 +376,12 @@ void parse_cmd_line(unsigned long r3, unsigned long r4, unsigned long r5,
strlcpy(cmd_line, CONFIG_CMDLINE, sizeof(cmd_line));
#endif /* CONFIG_CMDLINE */
chosen = find_devices("chosen");
chosen = of_find_node_by_name(NULL, "chosen");
if (chosen != NULL) {
p = get_property(chosen, "bootargs", NULL);
if (p != NULL && p[0] != 0)
strlcpy(cmd_line, p, sizeof(cmd_line));
of_node_put(chosen);
}
/* Look for mem= option on command line */
......
......@@ -398,7 +398,7 @@ void xics_init_IRQ(void)
ibm_int_on = rtas_token("ibm,int-on");
ibm_int_off = rtas_token("ibm,int-off");
np = find_type_devices("PowerPC-External-Interrupt-Presentation");
np = of_find_node_by_type(NULL, "PowerPC-External-Interrupt-Presentation");
if (!np) {
printk(KERN_WARNING "Can't find Interrupt Presentation\n");
udbg_printf("Can't find Interrupt Presentation\n");
......@@ -433,11 +433,13 @@ void xics_init_IRQ(void)
if (indx >= NR_CPUS) break;
}
np = np->next;
np = of_find_node_by_type(np, "PowerPC-External-Interrupt-Presentation");
if ((indx < NR_CPUS) && np) goto nextnode;
/* Find the server numbers for the boot cpu. */
for (np = find_type_devices("cpu"); np; np = np->next) {
for (np = of_find_node_by_type(NULL, "cpu");
np;
np = of_find_node_by_type(np, "cpu")) {
ireg = (uint *)get_property(np, "reg", &ilen);
if (ireg && ireg[0] == smp_processor_id()) {
ireg = (uint *)get_property(np, "ibm,ppc-interrupt-gserver#s", &ilen);
......@@ -449,11 +451,12 @@ void xics_init_IRQ(void)
break;
}
}
of_node_put(np);
intr_base = inodes[0].addr;
intr_size = (ulong)inodes[0].size;
np = find_type_devices("interrupt-controller");
np = of_find_node_by_type(NULL, "interrupt-controller");
if (!np) {
printk(KERN_WARNING "xics: no ISA Interrupt Controller\n");
xics_irq_8259_cascade_real = -1;
......@@ -467,6 +470,7 @@ void xics_init_IRQ(void)
}
xics_irq_8259_cascade_real = *ireg;
xics_irq_8259_cascade = virt_irq_create_mapping(xics_irq_8259_cascade_real);
of_node_put(np);
}
if (systemcfg->platform == PLATFORM_PSERIES) {
......
......@@ -46,29 +46,29 @@ static inline void map_cpu_to_node(int cpu, int node)
static int __init parse_numa_properties(void)
{
struct device_node *cpu;
struct device_node *memory;
struct device_node *cpu = NULL;
struct device_node *memory = NULL;
int *cpu_associativity;
int *memory_associativity;
int depth;
int max_domain = 0;
cpu = find_type_devices("cpu");
cpu = of_find_node_by_type(NULL, "cpu");
if (!cpu)
return -1;
goto err;
memory = find_type_devices("memory");
memory = of_find_node_by_type(NULL, "memory");
if (!memory)
return -1;
goto err;
cpu_associativity = (int *)get_property(cpu, "ibm,associativity", NULL);
if (!cpu_associativity)
return -1;
goto err;
memory_associativity = (int *)get_property(memory, "ibm,associativity",
NULL);
if (!memory_associativity)
return -1;
goto err;
/* find common depth */
if (cpu_associativity[0] < memory_associativity[0])
......@@ -76,7 +76,7 @@ static int __init parse_numa_properties(void)
else
depth = memory_associativity[0];
for (cpu = find_type_devices("cpu"); cpu; cpu = cpu->next) {
for (; cpu; cpu = of_find_node_by_type(cpu, "cpu")) {
int *tmp;
int cpu_nr, numa_domain;
......@@ -106,8 +106,7 @@ static int __init parse_numa_properties(void)
map_cpu_to_node(cpu_nr, numa_domain);
}
for (memory = find_type_devices("memory"); memory;
memory = memory->next) {
for (; memory; memory = of_find_node_by_type(memory, "memory")) {
int *tmp1, *tmp2;
unsigned long i;
unsigned long start = 0;
......@@ -196,6 +195,10 @@ static int __init parse_numa_properties(void)
numnodes = max_domain + 1;
return 0;
err:
of_node_put(cpu);
of_node_put(memory);
return -1;
}
void setup_nonnuma(void)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment