2 #include <linux/kernel.h>
4 #include <linux/string.h>
5 #include <linux/init.h>
10 #include <asm/machdep.h>
11 #include <asm/sections.h>
12 #include <asm/pci-bridge.h>
19 * Access functions for PCI config space using RTAS calls.
21 static int rtas_read_config(struct pci_bus
*bus
, unsigned int devfn
, int offset
,
24 struct pci_controller
*hose
= bus
->sysdata
;
25 unsigned long addr
= (offset
& 0xff) | ((devfn
& 0xff) << 8)
26 | (((bus
->number
- hose
->first_busno
) & 0xff) << 16)
27 | (hose
->index
<< 24);
31 rval
= rtas_call(rtas_token("read-pci-config"), 2, 2, &ret
, addr
, len
);
33 return rval
? PCIBIOS_DEVICE_NOT_FOUND
: PCIBIOS_SUCCESSFUL
;
36 static int rtas_write_config(struct pci_bus
*bus
, unsigned int devfn
,
37 int offset
, int len
, u32 val
)
39 struct pci_controller
*hose
= bus
->sysdata
;
40 unsigned long addr
= (offset
& 0xff) | ((devfn
& 0xff) << 8)
41 | (((bus
->number
- hose
->first_busno
) & 0xff) << 16)
42 | (hose
->index
<< 24);
45 rval
= rtas_call(rtas_token("write-pci-config"), 3, 1, NULL
,
47 return rval
? PCIBIOS_DEVICE_NOT_FOUND
: PCIBIOS_SUCCESSFUL
;
50 static struct pci_ops rtas_pci_ops
= {
55 void __init
efika_pcisetup(void)
59 struct pci_controller
*hose
;
60 struct device_node
*root
;
61 struct device_node
*pcictrl
;
63 root
= of_find_node_by_path("/");
65 printk(KERN_WARNING EFIKA_PLATFORM_NAME
66 ": Unable to find the root node\n");
70 for (pcictrl
= NULL
;;) {
71 pcictrl
= of_get_next_child(root
, pcictrl
);
72 if ((pcictrl
== NULL
) || (strcmp(pcictrl
->name
, "pci") == 0))
78 if (pcictrl
== NULL
) {
79 printk(KERN_WARNING EFIKA_PLATFORM_NAME
80 ": Unable to find the PCI bridge node\n");
84 bus_range
= get_property(pcictrl
, "bus-range", &len
);
85 if (bus_range
== NULL
|| len
< 2 * sizeof(int)) {
86 printk(KERN_WARNING EFIKA_PLATFORM_NAME
87 ": Can't get bus-range for %s\n", pcictrl
->full_name
);
91 if (bus_range
[1] == bus_range
[0])
92 printk(KERN_INFO EFIKA_PLATFORM_NAME
": PCI bus %d",
95 printk(KERN_INFO EFIKA_PLATFORM_NAME
": PCI buses %d..%d",
96 bus_range
[0], bus_range
[1]);
97 printk(" controlled by %s\n", pcictrl
->full_name
);
100 hose
= pcibios_alloc_controller();
102 printk(KERN_WARNING EFIKA_PLATFORM_NAME
103 ": Can't allocate PCI controller structure for %s\n",
108 hose
->arch_data
= of_node_get(pcictrl
);
109 hose
->first_busno
= bus_range
[0];
110 hose
->last_busno
= bus_range
[1];
111 hose
->ops
= &rtas_pci_ops
;
113 pci_process_bridge_OF_ranges(hose
, pcictrl
, 0);
117 void __init
efika_pcisetup(void)