Grant Likely | 9d24c88 | 2009-10-15 10:57:44 -0600 | [diff] [blame] | 1 | #include <linux/of.h> /* linux/of.h gets to determine #include ordering */ |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 2 | #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 Likely | d8678b5 | 2009-10-15 10:57:53 -0600 | [diff] [blame] | 20 | #include <linux/of_fdt.h> |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 21 | #include <linux/proc_fs.h> |
Andy Fleming | a9b1497 | 2006-10-19 19:52:26 -0500 | [diff] [blame] | 22 | #include <linux/platform_device.h> |
Andrew Morton | 99ddef9 | 2007-02-17 18:17:16 -0700 | [diff] [blame] | 23 | #include <asm/irq.h> |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 24 | #include <asm/atomic.h> |
| 25 | |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 26 | #define HAVE_ARCH_DEVTREE_FIXUPS |
| 27 | |
Paul Mackerras | 40ef8cb | 2005-10-10 22:50:37 +1000 | [diff] [blame] | 28 | #ifdef CONFIG_PPC32 |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 29 | /* |
| 30 | * PCI <-> OF matching functions |
| 31 | * (XXX should these be here?) |
| 32 | */ |
| 33 | struct pci_bus; |
| 34 | struct pci_dev; |
| 35 | extern int pci_device_from_OF_node(struct device_node *node, |
| 36 | u8* bus, u8* devfn); |
| 37 | extern struct device_node* pci_busdev_to_OF_node(struct pci_bus *, int); |
| 38 | extern struct device_node* pci_device_to_OF_node(struct pci_dev *); |
| 39 | extern void pci_create_OF_bus_map(void); |
Paul Mackerras | 40ef8cb | 2005-10-10 22:50:37 +1000 | [diff] [blame] | 40 | #endif |
| 41 | |
Benjamin Herrenschmidt | d1405b8 | 2005-11-23 17:53:42 +1100 | [diff] [blame] | 42 | /* |
Benjamin Herrenschmidt | d2dd482 | 2005-11-30 16:57:28 +1100 | [diff] [blame] | 43 | * OF address retreival & translation |
| 44 | */ |
| 45 | |
Benjamin Herrenschmidt | d2dd482 | 2005-11-30 16:57:28 +1100 | [diff] [blame] | 46 | /* Translate an OF address block into a CPU physical address |
Benjamin Herrenschmidt | d1405b8 | 2005-11-23 17:53:42 +1100 | [diff] [blame] | 47 | */ |
Jeremy Kerr | a7f67bd | 2006-07-12 15:35:54 +1000 | [diff] [blame] | 48 | extern u64 of_translate_address(struct device_node *np, const u32 *addr); |
Benjamin Herrenschmidt | d1405b8 | 2005-11-23 17:53:42 +1100 | [diff] [blame] | 49 | |
Benjamin Herrenschmidt | 837c54d | 2007-12-11 14:48:22 +1100 | [diff] [blame] | 50 | /* Translate a DMA address from device space to CPU space */ |
| 51 | extern u64 of_translate_dma_address(struct device_node *dev, |
| 52 | const u32 *in_addr); |
| 53 | |
Benjamin Herrenschmidt | d2dd482 | 2005-11-30 16:57:28 +1100 | [diff] [blame] | 54 | /* 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 Kerr | a7f67bd | 2006-07-12 15:35:54 +1000 | [diff] [blame] | 58 | extern const u32 *of_get_address(struct device_node *dev, int index, |
Benjamin Herrenschmidt | d2dd482 | 2005-11-30 16:57:28 +1100 | [diff] [blame] | 59 | u64 *size, unsigned int *flags); |
Anton Vorontsov | ff1f4ee | 2008-06-11 08:31:00 +1000 | [diff] [blame] | 60 | #ifdef CONFIG_PCI |
Jeremy Kerr | a7f67bd | 2006-07-12 15:35:54 +1000 | [diff] [blame] | 61 | extern const u32 *of_get_pci_address(struct device_node *dev, int bar_no, |
Benjamin Herrenschmidt | d2dd482 | 2005-11-30 16:57:28 +1100 | [diff] [blame] | 62 | u64 *size, unsigned int *flags); |
Anton Vorontsov | ff1f4ee | 2008-06-11 08:31:00 +1000 | [diff] [blame] | 63 | #else |
| 64 | static 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 Herrenschmidt | d2dd482 | 2005-11-30 16:57:28 +1100 | [diff] [blame] | 70 | |
| 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 | */ |
| 77 | extern int of_address_to_resource(struct device_node *dev, int index, |
| 78 | struct resource *r); |
Anton Vorontsov | ff1f4ee | 2008-06-11 08:31:00 +1000 | [diff] [blame] | 79 | #ifdef CONFIG_PCI |
Benjamin Herrenschmidt | d2dd482 | 2005-11-30 16:57:28 +1100 | [diff] [blame] | 80 | extern int of_pci_address_to_resource(struct device_node *dev, int bar, |
| 81 | struct resource *r); |
Anton Vorontsov | ff1f4ee | 2008-06-11 08:31:00 +1000 | [diff] [blame] | 82 | #else |
| 83 | static 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 Herrenschmidt | d1405b8 | 2005-11-23 17:53:42 +1100 | [diff] [blame] | 89 | |
Jeremy Kerr | d4ad66f | 2006-05-18 18:05:15 +1000 | [diff] [blame] | 90 | /* Parse the ibm,dma-window property of an OF node into the busno, phys and |
| 91 | * size parameters. |
| 92 | */ |
Jeremy Kerr | a7f67bd | 2006-07-12 15:35:54 +1000 | [diff] [blame] | 93 | void of_parse_dma_window(struct device_node *dn, const void *dma_window_prop, |
Jeremy Kerr | d4ad66f | 2006-05-18 18:05:15 +1000 | [diff] [blame] | 94 | unsigned long *busno, unsigned long *phys, unsigned long *size); |
| 95 | |
Michael Ellerman | b68239e | 2006-02-03 19:05:47 +1100 | [diff] [blame] | 96 | extern void kdump_move_device_tree(void); |
| 97 | |
Benjamin Herrenschmidt | acf7d76 | 2006-06-19 20:33:16 +0200 | [diff] [blame] | 98 | /* CPU OF node matching */ |
| 99 | struct device_node *of_get_cpu_node(int cpu, unsigned int *thread); |
| 100 | |
Nathan Lynch | e523f72 | 2008-12-10 14:46:04 +0000 | [diff] [blame] | 101 | /* cache lookup */ |
| 102 | struct device_node *of_find_next_cache_node(struct device_node *np); |
| 103 | |
Timur Tabi | 29cfe6f | 2007-02-16 12:01:29 -0600 | [diff] [blame] | 104 | /* Get the MAC address */ |
| 105 | extern const void *of_get_mac_address(struct device_node *np); |
Benjamin Herrenschmidt | cc9fd71 | 2006-07-03 19:35:17 +1000 | [diff] [blame] | 106 | |
| 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 | |
| 117 | struct 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 Ellerman | 40681b9 | 2006-08-02 11:13:50 +1000 | [diff] [blame] | 123 | /** |
Benjamin Herrenschmidt | cc9fd71 | 2006-07-03 19:35:17 +1000 | [diff] [blame] | 124 | * 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 | |
| 134 | extern void of_irq_map_init(unsigned int flags); |
| 135 | |
Michael Ellerman | 40681b9 | 2006-08-02 11:13:50 +1000 | [diff] [blame] | 136 | /** |
Benjamin Herrenschmidt | cc9fd71 | 2006-07-03 19:35:17 +1000 | [diff] [blame] | 137 | * 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 Herrenschmidt | 006b64d | 2006-08-25 14:46:23 +1000 | [diff] [blame] | 140 | * @ointsize: size of the passed in interrupt specifier |
Benjamin Herrenschmidt | cc9fd71 | 2006-07-03 19:35:17 +1000 | [diff] [blame] | 141 | * @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 Kerr | a7f67bd | 2006-07-12 15:35:54 +1000 | [diff] [blame] | 153 | extern int of_irq_map_raw(struct device_node *parent, const u32 *intspec, |
Paul Mackerras | aa43f77 | 2006-08-31 15:45:48 +1000 | [diff] [blame] | 154 | u32 ointsize, const u32 *addr, |
Benjamin Herrenschmidt | cc9fd71 | 2006-07-03 19:35:17 +1000 | [diff] [blame] | 155 | struct of_irq *out_irq); |
| 156 | |
| 157 | |
Michael Ellerman | 40681b9 | 2006-08-02 11:13:50 +1000 | [diff] [blame] | 158 | /** |
Benjamin Herrenschmidt | cc9fd71 | 2006-07-03 19:35:17 +1000 | [diff] [blame] | 159 | * 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 | */ |
| 168 | extern int of_irq_map_one(struct device_node *device, int index, |
| 169 | struct of_irq *out_irq); |
| 170 | |
Michael Ellerman | 40681b9 | 2006-08-02 11:13:50 +1000 | [diff] [blame] | 171 | /** |
Benjamin Herrenschmidt | cc9fd71 | 2006-07-03 19:35:17 +1000 | [diff] [blame] | 172 | * 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 | */ |
| 182 | struct pci_dev; |
| 183 | extern int of_irq_map_pci(struct pci_dev *pdev, struct of_irq *out_irq); |
| 184 | |
Mathieu Desnoyers | c0b3ae1 | 2007-02-06 12:03:31 +1100 | [diff] [blame] | 185 | extern int of_irq_to_resource(struct device_node *dev, int index, |
| 186 | struct resource *r); |
Andy Fleming | a9b1497 | 2006-10-19 19:52:26 -0500 | [diff] [blame] | 187 | |
Christian Krafft | c3e8011 | 2007-04-25 01:32:02 +1000 | [diff] [blame] | 188 | /** |
| 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 | */ |
| 195 | extern void __iomem *of_iomap(struct device_node *device, int index); |
Benjamin Herrenschmidt | cc9fd71 | 2006-07-03 19:35:17 +1000 | [diff] [blame] | 196 | |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 197 | #endif /* __KERNEL__ */ |
| 198 | #endif /* _POWERPC_PROM_H */ |