blob: 10d5ee556702a6a9f1aa89be9116b8d9cbd4d039 [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
Michael Ellerman40681b92006-08-02 11:13:50 +1000108/**
Benjamin Herrenschmidtcc9fd712006-07-03 19:35:17 +1000109 * of_irq_map_pci - Resolve the interrupt for a PCI device
110 * @pdev: the device whose interrupt is to be resolved
111 * @out_irq: structure of_irq filled by this function
112 *
113 * This function resolves the PCI interrupt for a given PCI device. If a
114 * device-node exists for a given pci_dev, it will use normal OF tree
115 * walking. If not, it will implement standard swizzling and walk up the
116 * PCI tree until an device-node is found, at which point it will finish
117 * resolving using the OF tree walking.
118 */
119struct pci_dev;
120extern int of_irq_map_pci(struct pci_dev *pdev, struct of_irq *out_irq);
121
Christian Krafftc3e80112007-04-25 01:32:02 +1000122/**
123 * of_iomap - Maps the memory mapped IO for a given device_node
124 * @device: the device whose io range will be mapped
125 * @index: index of the io range
126 *
127 * Returns a pointer to the mapped memory
128 */
129extern void __iomem *of_iomap(struct device_node *device, int index);
Benjamin Herrenschmidtcc9fd712006-07-03 19:35:17 +1000130
Paul Mackerras9b6b5632005-10-06 12:06:20 +1000131#endif /* __KERNEL__ */
132#endif /* _POWERPC_PROM_H */