blob: ddd408a93b5a526c1c30d24c7c4d1a119365e338 [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>
Paul Mackerras9b6b5632005-10-06 12:06:20 +100021#include <linux/proc_fs.h>
Andy Fleminga9b14972006-10-19 19:52:26 -050022#include <linux/platform_device.h>
Andrew Morton99ddef92007-02-17 18:17:16 -070023#include <asm/irq.h>
Paul Mackerras9b6b5632005-10-06 12:06:20 +100024#include <asm/atomic.h>
25
Paul Mackerras9b6b5632005-10-06 12:06:20 +100026#define HAVE_ARCH_DEVTREE_FIXUPS
27
Paul Mackerras40ef8cb2005-10-10 22:50:37 +100028#ifdef CONFIG_PPC32
Paul Mackerras9b6b5632005-10-06 12:06:20 +100029/*
30 * PCI <-> OF matching functions
31 * (XXX should these be here?)
32 */
33struct pci_bus;
34struct pci_dev;
35extern int pci_device_from_OF_node(struct device_node *node,
36 u8* bus, u8* devfn);
37extern struct device_node* pci_busdev_to_OF_node(struct pci_bus *, int);
38extern struct device_node* pci_device_to_OF_node(struct pci_dev *);
39extern void pci_create_OF_bus_map(void);
Paul Mackerras40ef8cb2005-10-10 22:50:37 +100040#endif
41
Benjamin Herrenschmidtd1405b82005-11-23 17:53:42 +110042/*
Benjamin Herrenschmidtd2dd4822005-11-30 16:57:28 +110043 * OF address retreival & translation
44 */
45
Benjamin Herrenschmidtd2dd4822005-11-30 16:57:28 +110046/* Translate an OF address block into a CPU physical address
Benjamin Herrenschmidtd1405b82005-11-23 17:53:42 +110047 */
Jeremy Kerra7f67bd2006-07-12 15:35:54 +100048extern u64 of_translate_address(struct device_node *np, const u32 *addr);
Benjamin Herrenschmidtd1405b82005-11-23 17:53:42 +110049
Benjamin Herrenschmidt837c54d2007-12-11 14:48:22 +110050/* Translate a DMA address from device space to CPU space */
51extern u64 of_translate_dma_address(struct device_node *dev,
52 const u32 *in_addr);
53
Benjamin Herrenschmidtd2dd4822005-11-30 16:57:28 +110054/* Extract an address from a device, returns the region size and
55 * the address space flags too. The PCI version uses a BAR number
56 * instead of an absolute index
57 */
Jeremy Kerra7f67bd2006-07-12 15:35:54 +100058extern const u32 *of_get_address(struct device_node *dev, int index,
Benjamin Herrenschmidtd2dd4822005-11-30 16:57:28 +110059 u64 *size, unsigned int *flags);
Anton Vorontsovff1f4ee2008-06-11 08:31:00 +100060#ifdef CONFIG_PCI
Jeremy Kerra7f67bd2006-07-12 15:35:54 +100061extern const u32 *of_get_pci_address(struct device_node *dev, int bar_no,
Benjamin Herrenschmidtd2dd4822005-11-30 16:57:28 +110062 u64 *size, unsigned int *flags);
Anton Vorontsovff1f4ee2008-06-11 08:31:00 +100063#else
64static inline const u32 *of_get_pci_address(struct device_node *dev,
65 int bar_no, u64 *size, unsigned int *flags)
66{
67 return NULL;
68}
69#endif /* CONFIG_PCI */
Benjamin Herrenschmidtd2dd4822005-11-30 16:57:28 +110070
71/* Get an address as a resource. Note that if your address is
72 * a PIO address, the conversion will fail if the physical address
73 * can't be internally converted to an IO token with
74 * pci_address_to_pio(), that is because it's either called to early
75 * or it can't be matched to any host bridge IO space
76 */
77extern int of_address_to_resource(struct device_node *dev, int index,
78 struct resource *r);
Anton Vorontsovff1f4ee2008-06-11 08:31:00 +100079#ifdef CONFIG_PCI
Benjamin Herrenschmidtd2dd4822005-11-30 16:57:28 +110080extern int of_pci_address_to_resource(struct device_node *dev, int bar,
81 struct resource *r);
Anton Vorontsovff1f4ee2008-06-11 08:31:00 +100082#else
83static inline int of_pci_address_to_resource(struct device_node *dev, int bar,
84 struct resource *r)
85{
86 return -ENOSYS;
87}
88#endif /* CONFIG_PCI */
Benjamin Herrenschmidtd1405b82005-11-23 17:53:42 +110089
Jeremy Kerrd4ad66f2006-05-18 18:05:15 +100090/* Parse the ibm,dma-window property of an OF node into the busno, phys and
91 * size parameters.
92 */
Jeremy Kerra7f67bd2006-07-12 15:35:54 +100093void of_parse_dma_window(struct device_node *dn, const void *dma_window_prop,
Jeremy Kerrd4ad66f2006-05-18 18:05:15 +100094 unsigned long *busno, unsigned long *phys, unsigned long *size);
95
Michael Ellermanb68239e2006-02-03 19:05:47 +110096extern void kdump_move_device_tree(void);
97
Benjamin Herrenschmidtacf7d762006-06-19 20:33:16 +020098/* CPU OF node matching */
99struct device_node *of_get_cpu_node(int cpu, unsigned int *thread);
100
Nathan Lynche523f722008-12-10 14:46:04 +0000101/* cache lookup */
102struct device_node *of_find_next_cache_node(struct device_node *np);
103
Timur Tabi29cfe6f2007-02-16 12:01:29 -0600104/* Get the MAC address */
105extern const void *of_get_mac_address(struct device_node *np);
Benjamin Herrenschmidtcc9fd712006-07-03 19:35:17 +1000106
107/*
108 * OF interrupt mapping
109 */
110
111/* This structure is returned when an interrupt is mapped. The controller
112 * field needs to be put() after use
113 */
114
115#define OF_MAX_IRQ_SPEC 4 /* We handle specifiers of at most 4 cells */
116
117struct of_irq {
118 struct device_node *controller; /* Interrupt controller node */
119 u32 size; /* Specifier size */
120 u32 specifier[OF_MAX_IRQ_SPEC]; /* Specifier copy */
121};
122
Michael Ellerman40681b92006-08-02 11:13:50 +1000123/**
Benjamin Herrenschmidtcc9fd712006-07-03 19:35:17 +1000124 * of_irq_map_init - Initialize the irq remapper
125 * @flags: flags defining workarounds to enable
126 *
127 * Some machines have bugs in the device-tree which require certain workarounds
128 * to be applied. Call this before any interrupt mapping attempts to enable
129 * those workarounds.
130 */
131#define OF_IMAP_OLDWORLD_MAC 0x00000001
132#define OF_IMAP_NO_PHANDLE 0x00000002
133
134extern void of_irq_map_init(unsigned int flags);
135
Michael Ellerman40681b92006-08-02 11:13:50 +1000136/**
Benjamin Herrenschmidtcc9fd712006-07-03 19:35:17 +1000137 * of_irq_map_raw - Low level interrupt tree parsing
138 * @parent: the device interrupt parent
139 * @intspec: interrupt specifier ("interrupts" property of the device)
Benjamin Herrenschmidt006b64d2006-08-25 14:46:23 +1000140 * @ointsize: size of the passed in interrupt specifier
Benjamin Herrenschmidtcc9fd712006-07-03 19:35:17 +1000141 * @addr: address specifier (start of "reg" property of the device)
142 * @out_irq: structure of_irq filled by this function
143 *
144 * Returns 0 on success and a negative number on error
145 *
146 * This function is a low-level interrupt tree walking function. It
147 * can be used to do a partial walk with synthetized reg and interrupts
148 * properties, for example when resolving PCI interrupts when no device
149 * node exist for the parent.
150 *
151 */
152
Jeremy Kerra7f67bd2006-07-12 15:35:54 +1000153extern int of_irq_map_raw(struct device_node *parent, const u32 *intspec,
Paul Mackerrasaa43f772006-08-31 15:45:48 +1000154 u32 ointsize, const u32 *addr,
Benjamin Herrenschmidtcc9fd712006-07-03 19:35:17 +1000155 struct of_irq *out_irq);
156
157
Michael Ellerman40681b92006-08-02 11:13:50 +1000158/**
Benjamin Herrenschmidtcc9fd712006-07-03 19:35:17 +1000159 * of_irq_map_one - Resolve an interrupt for a device
160 * @device: the device whose interrupt is to be resolved
161 * @index: index of the interrupt to resolve
162 * @out_irq: structure of_irq filled by this function
163 *
164 * This function resolves an interrupt, walking the tree, for a given
165 * device-tree node. It's the high level pendant to of_irq_map_raw().
166 * It also implements the workarounds for OldWolrd Macs.
167 */
168extern int of_irq_map_one(struct device_node *device, int index,
169 struct of_irq *out_irq);
170
Michael Ellerman40681b92006-08-02 11:13:50 +1000171/**
Benjamin Herrenschmidtcc9fd712006-07-03 19:35:17 +1000172 * of_irq_map_pci - Resolve the interrupt for a PCI device
173 * @pdev: the device whose interrupt is to be resolved
174 * @out_irq: structure of_irq filled by this function
175 *
176 * This function resolves the PCI interrupt for a given PCI device. If a
177 * device-node exists for a given pci_dev, it will use normal OF tree
178 * walking. If not, it will implement standard swizzling and walk up the
179 * PCI tree until an device-node is found, at which point it will finish
180 * resolving using the OF tree walking.
181 */
182struct pci_dev;
183extern int of_irq_map_pci(struct pci_dev *pdev, struct of_irq *out_irq);
184
Mathieu Desnoyersc0b3ae12007-02-06 12:03:31 +1100185extern int of_irq_to_resource(struct device_node *dev, int index,
186 struct resource *r);
Andy Fleminga9b14972006-10-19 19:52:26 -0500187
Christian Krafftc3e80112007-04-25 01:32:02 +1000188/**
189 * of_iomap - Maps the memory mapped IO for a given device_node
190 * @device: the device whose io range will be mapped
191 * @index: index of the io range
192 *
193 * Returns a pointer to the mapped memory
194 */
195extern void __iomem *of_iomap(struct device_node *device, int index);
Benjamin Herrenschmidtcc9fd712006-07-03 19:35:17 +1000196
Paul Mackerras9b6b5632005-10-06 12:06:20 +1000197#endif /* __KERNEL__ */
198#endif /* _POWERPC_PROM_H */