blob: 47d41b67c94df62b5e7387e40de2157d8c419aea [file] [log] [blame]
Grant Likely9d24c882009-10-15 10:57:44 -06001#include <linux/of.h> /* linux/of.h gets to determine #include ordering */
Paul Mackerras9b6b5632005-10-06 12:06:20 +10002#ifndef _POWERPC_PROM_H
3#define _POWERPC_PROM_H
4#ifdef __KERNEL__
5
6/*
7 * Definitions for talking to the Open Firmware PROM on
8 * Power Macintosh computers.
9 *
10 * Copyright (C) 1996-2005 Paul Mackerras.
11 *
12 * Updates for PPC64 by Peter Bergner & David Engebretsen, IBM Corp.
13 *
14 * This program is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU General Public License
16 * as published by the Free Software Foundation; either version
17 * 2 of the License, or (at your option) any later version.
18 */
19#include <linux/types.h>
Grant Likelyd8678b52009-10-15 10:57:53 -060020#include <linux/of_fdt.h>
Grant Likelye3873442010-06-18 11:09:59 -060021#include <linux/of_irq.h>
Paul Mackerras9b6b5632005-10-06 12:06:20 +100022#include <linux/proc_fs.h>
Andy Fleminga9b14972006-10-19 19:52:26 -050023#include <linux/platform_device.h>
Andrew Morton99ddef92007-02-17 18:17:16 -070024#include <asm/irq.h>
Paul Mackerras9b6b5632005-10-06 12:06:20 +100025#include <asm/atomic.h>
26
Paul Mackerras9b6b5632005-10-06 12:06:20 +100027#define HAVE_ARCH_DEVTREE_FIXUPS
28
Paul Mackerras40ef8cb2005-10-10 22:50:37 +100029#ifdef CONFIG_PPC32
Paul Mackerras9b6b5632005-10-06 12:06:20 +100030/*
31 * PCI <-> OF matching functions
32 * (XXX should these be here?)
33 */
34struct pci_bus;
35struct pci_dev;
36extern int pci_device_from_OF_node(struct device_node *node,
37 u8* bus, u8* devfn);
38extern struct device_node* pci_busdev_to_OF_node(struct pci_bus *, int);
39extern struct device_node* pci_device_to_OF_node(struct pci_dev *);
40extern void pci_create_OF_bus_map(void);
Paul Mackerras40ef8cb2005-10-10 22:50:37 +100041#endif
42
Benjamin Herrenschmidtd1405b82005-11-23 17:53:42 +110043/*
Benjamin Herrenschmidtd2dd4822005-11-30 16:57:28 +110044 * OF address retreival & translation
45 */
46
Benjamin Herrenschmidtd2dd4822005-11-30 16:57:28 +110047/* Translate an OF address block into a CPU physical address
Benjamin Herrenschmidtd1405b82005-11-23 17:53:42 +110048 */
Jeremy Kerra7f67bd2006-07-12 15:35:54 +100049extern u64 of_translate_address(struct device_node *np, const u32 *addr);
Benjamin Herrenschmidtd1405b82005-11-23 17:53:42 +110050
Benjamin Herrenschmidt837c54d2007-12-11 14:48:22 +110051/* Translate a DMA address from device space to CPU space */
52extern u64 of_translate_dma_address(struct device_node *dev,
53 const u32 *in_addr);
54
Benjamin Herrenschmidtd2dd4822005-11-30 16:57:28 +110055/* Extract an address from a device, returns the region size and
56 * the address space flags too. The PCI version uses a BAR number
57 * instead of an absolute index
58 */
Jeremy Kerra7f67bd2006-07-12 15:35:54 +100059extern const u32 *of_get_address(struct device_node *dev, int index,
Benjamin Herrenschmidtd2dd4822005-11-30 16:57:28 +110060 u64 *size, unsigned int *flags);
Anton Vorontsovff1f4ee2008-06-11 08:31:00 +100061#ifdef CONFIG_PCI
Jeremy Kerra7f67bd2006-07-12 15:35:54 +100062extern const u32 *of_get_pci_address(struct device_node *dev, int bar_no,
Benjamin Herrenschmidtd2dd4822005-11-30 16:57:28 +110063 u64 *size, unsigned int *flags);
Anton Vorontsovff1f4ee2008-06-11 08:31:00 +100064#else
65static inline const u32 *of_get_pci_address(struct device_node *dev,
66 int bar_no, u64 *size, unsigned int *flags)
67{
68 return NULL;
69}
70#endif /* CONFIG_PCI */
Benjamin Herrenschmidtd2dd4822005-11-30 16:57:28 +110071
72/* Get an address as a resource. Note that if your address is
73 * a PIO address, the conversion will fail if the physical address
74 * can't be internally converted to an IO token with
75 * pci_address_to_pio(), that is because it's either called to early
76 * or it can't be matched to any host bridge IO space
77 */
78extern int of_address_to_resource(struct device_node *dev, int index,
79 struct resource *r);
Anton Vorontsovff1f4ee2008-06-11 08:31:00 +100080#ifdef CONFIG_PCI
Benjamin Herrenschmidtd2dd4822005-11-30 16:57:28 +110081extern int of_pci_address_to_resource(struct device_node *dev, int bar,
82 struct resource *r);
Anton Vorontsovff1f4ee2008-06-11 08:31:00 +100083#else
84static inline int of_pci_address_to_resource(struct device_node *dev, int bar,
85 struct resource *r)
86{
87 return -ENOSYS;
88}
89#endif /* CONFIG_PCI */
Benjamin Herrenschmidtd1405b82005-11-23 17:53:42 +110090
Jeremy Kerrd4ad66f2006-05-18 18:05:15 +100091/* Parse the ibm,dma-window property of an OF node into the busno, phys and
92 * size parameters.
93 */
Jeremy Kerra7f67bd2006-07-12 15:35:54 +100094void of_parse_dma_window(struct device_node *dn, const void *dma_window_prop,
Jeremy Kerrd4ad66f2006-05-18 18:05:15 +100095 unsigned long *busno, unsigned long *phys, unsigned long *size);
96
Michael Ellermanb68239e2006-02-03 19:05:47 +110097extern void kdump_move_device_tree(void);
98
Benjamin Herrenschmidtacf7d762006-06-19 20:33:16 +020099/* CPU OF node matching */
100struct device_node *of_get_cpu_node(int cpu, unsigned int *thread);
101
Nathan Lynche523f722008-12-10 14:46:04 +0000102/* cache lookup */
103struct device_node *of_find_next_cache_node(struct device_node *np);
104
Timur Tabi29cfe6f2007-02-16 12:01:29 -0600105/* Get the MAC address */
106extern const void *of_get_mac_address(struct device_node *np);
Benjamin Herrenschmidtcc9fd712006-07-03 19:35:17 +1000107
108/*
109 * OF interrupt mapping
110 */
111
Michael Ellerman40681b92006-08-02 11:13:50 +1000112/**
Benjamin Herrenschmidtcc9fd712006-07-03 19:35:17 +1000113 * of_irq_map_init - Initialize the irq remapper
114 * @flags: flags defining workarounds to enable
115 *
116 * Some machines have bugs in the device-tree which require certain workarounds
117 * to be applied. Call this before any interrupt mapping attempts to enable
118 * those workarounds.
119 */
120#define OF_IMAP_OLDWORLD_MAC 0x00000001
121#define OF_IMAP_NO_PHANDLE 0x00000002
122
123extern void of_irq_map_init(unsigned int flags);
124
Michael Ellerman40681b92006-08-02 11:13:50 +1000125/**
Benjamin Herrenschmidtcc9fd712006-07-03 19:35:17 +1000126 * of_irq_map_raw - Low level interrupt tree parsing
127 * @parent: the device interrupt parent
128 * @intspec: interrupt specifier ("interrupts" property of the device)
Benjamin Herrenschmidt006b64d2006-08-25 14:46:23 +1000129 * @ointsize: size of the passed in interrupt specifier
Benjamin Herrenschmidtcc9fd712006-07-03 19:35:17 +1000130 * @addr: address specifier (start of "reg" property of the device)
131 * @out_irq: structure of_irq filled by this function
132 *
133 * Returns 0 on success and a negative number on error
134 *
135 * This function is a low-level interrupt tree walking function. It
136 * can be used to do a partial walk with synthetized reg and interrupts
137 * properties, for example when resolving PCI interrupts when no device
138 * node exist for the parent.
139 *
140 */
141
Jeremy Kerra7f67bd2006-07-12 15:35:54 +1000142extern int of_irq_map_raw(struct device_node *parent, const u32 *intspec,
Paul Mackerrasaa43f772006-08-31 15:45:48 +1000143 u32 ointsize, const u32 *addr,
Benjamin Herrenschmidtcc9fd712006-07-03 19:35:17 +1000144 struct of_irq *out_irq);
145
Michael Ellerman40681b92006-08-02 11:13:50 +1000146/**
Benjamin Herrenschmidtcc9fd712006-07-03 19:35:17 +1000147 * of_irq_map_pci - Resolve the interrupt for a PCI device
148 * @pdev: the device whose interrupt is to be resolved
149 * @out_irq: structure of_irq filled by this function
150 *
151 * This function resolves the PCI interrupt for a given PCI device. If a
152 * device-node exists for a given pci_dev, it will use normal OF tree
153 * walking. If not, it will implement standard swizzling and walk up the
154 * PCI tree until an device-node is found, at which point it will finish
155 * resolving using the OF tree walking.
156 */
157struct pci_dev;
158extern int of_irq_map_pci(struct pci_dev *pdev, struct of_irq *out_irq);
159
Mathieu Desnoyersc0b3ae12007-02-06 12:03:31 +1100160extern int of_irq_to_resource(struct device_node *dev, int index,
161 struct resource *r);
Andy Fleminga9b14972006-10-19 19:52:26 -0500162
Christian Krafftc3e80112007-04-25 01:32:02 +1000163/**
164 * of_iomap - Maps the memory mapped IO for a given device_node
165 * @device: the device whose io range will be mapped
166 * @index: index of the io range
167 *
168 * Returns a pointer to the mapped memory
169 */
170extern void __iomem *of_iomap(struct device_node *device, int index);
Benjamin Herrenschmidtcc9fd712006-07-03 19:35:17 +1000171
Paul Mackerras9b6b5632005-10-06 12:06:20 +1000172#endif /* __KERNEL__ */
173#endif /* _POWERPC_PROM_H */