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> |
Grant Likely | e387344 | 2010-06-18 11:09:59 -0600 | [diff] [blame^] | 21 | #include <linux/of_irq.h> |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 22 | #include <linux/proc_fs.h> |
Andy Fleming | a9b1497 | 2006-10-19 19:52:26 -0500 | [diff] [blame] | 23 | #include <linux/platform_device.h> |
Andrew Morton | 99ddef9 | 2007-02-17 18:17:16 -0700 | [diff] [blame] | 24 | #include <asm/irq.h> |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 25 | #include <asm/atomic.h> |
| 26 | |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 27 | #define HAVE_ARCH_DEVTREE_FIXUPS |
| 28 | |
Paul Mackerras | 40ef8cb | 2005-10-10 22:50:37 +1000 | [diff] [blame] | 29 | #ifdef CONFIG_PPC32 |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 30 | /* |
| 31 | * PCI <-> OF matching functions |
| 32 | * (XXX should these be here?) |
| 33 | */ |
| 34 | struct pci_bus; |
| 35 | struct pci_dev; |
| 36 | extern int pci_device_from_OF_node(struct device_node *node, |
| 37 | u8* bus, u8* devfn); |
| 38 | extern struct device_node* pci_busdev_to_OF_node(struct pci_bus *, int); |
| 39 | extern struct device_node* pci_device_to_OF_node(struct pci_dev *); |
| 40 | extern void pci_create_OF_bus_map(void); |
Paul Mackerras | 40ef8cb | 2005-10-10 22:50:37 +1000 | [diff] [blame] | 41 | #endif |
| 42 | |
Benjamin Herrenschmidt | d1405b8 | 2005-11-23 17:53:42 +1100 | [diff] [blame] | 43 | /* |
Benjamin Herrenschmidt | d2dd482 | 2005-11-30 16:57:28 +1100 | [diff] [blame] | 44 | * OF address retreival & translation |
| 45 | */ |
| 46 | |
Benjamin Herrenschmidt | d2dd482 | 2005-11-30 16:57:28 +1100 | [diff] [blame] | 47 | /* Translate an OF address block into a CPU physical address |
Benjamin Herrenschmidt | d1405b8 | 2005-11-23 17:53:42 +1100 | [diff] [blame] | 48 | */ |
Jeremy Kerr | a7f67bd | 2006-07-12 15:35:54 +1000 | [diff] [blame] | 49 | extern u64 of_translate_address(struct device_node *np, const u32 *addr); |
Benjamin Herrenschmidt | d1405b8 | 2005-11-23 17:53:42 +1100 | [diff] [blame] | 50 | |
Benjamin Herrenschmidt | 837c54d | 2007-12-11 14:48:22 +1100 | [diff] [blame] | 51 | /* Translate a DMA address from device space to CPU space */ |
| 52 | extern u64 of_translate_dma_address(struct device_node *dev, |
| 53 | const u32 *in_addr); |
| 54 | |
Benjamin Herrenschmidt | d2dd482 | 2005-11-30 16:57:28 +1100 | [diff] [blame] | 55 | /* 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 Kerr | a7f67bd | 2006-07-12 15:35:54 +1000 | [diff] [blame] | 59 | extern const u32 *of_get_address(struct device_node *dev, int index, |
Benjamin Herrenschmidt | d2dd482 | 2005-11-30 16:57:28 +1100 | [diff] [blame] | 60 | u64 *size, unsigned int *flags); |
Anton Vorontsov | ff1f4ee | 2008-06-11 08:31:00 +1000 | [diff] [blame] | 61 | #ifdef CONFIG_PCI |
Jeremy Kerr | a7f67bd | 2006-07-12 15:35:54 +1000 | [diff] [blame] | 62 | 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] | 63 | u64 *size, unsigned int *flags); |
Anton Vorontsov | ff1f4ee | 2008-06-11 08:31:00 +1000 | [diff] [blame] | 64 | #else |
| 65 | static 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 Herrenschmidt | d2dd482 | 2005-11-30 16:57:28 +1100 | [diff] [blame] | 71 | |
| 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 | */ |
| 78 | extern int of_address_to_resource(struct device_node *dev, int index, |
| 79 | struct resource *r); |
Anton Vorontsov | ff1f4ee | 2008-06-11 08:31:00 +1000 | [diff] [blame] | 80 | #ifdef CONFIG_PCI |
Benjamin Herrenschmidt | d2dd482 | 2005-11-30 16:57:28 +1100 | [diff] [blame] | 81 | extern int of_pci_address_to_resource(struct device_node *dev, int bar, |
| 82 | struct resource *r); |
Anton Vorontsov | ff1f4ee | 2008-06-11 08:31:00 +1000 | [diff] [blame] | 83 | #else |
| 84 | static 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 Herrenschmidt | d1405b8 | 2005-11-23 17:53:42 +1100 | [diff] [blame] | 90 | |
Jeremy Kerr | d4ad66f | 2006-05-18 18:05:15 +1000 | [diff] [blame] | 91 | /* Parse the ibm,dma-window property of an OF node into the busno, phys and |
| 92 | * size parameters. |
| 93 | */ |
Jeremy Kerr | a7f67bd | 2006-07-12 15:35:54 +1000 | [diff] [blame] | 94 | 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] | 95 | unsigned long *busno, unsigned long *phys, unsigned long *size); |
| 96 | |
Michael Ellerman | b68239e | 2006-02-03 19:05:47 +1100 | [diff] [blame] | 97 | extern void kdump_move_device_tree(void); |
| 98 | |
Benjamin Herrenschmidt | acf7d76 | 2006-06-19 20:33:16 +0200 | [diff] [blame] | 99 | /* CPU OF node matching */ |
| 100 | struct device_node *of_get_cpu_node(int cpu, unsigned int *thread); |
| 101 | |
Nathan Lynch | e523f72 | 2008-12-10 14:46:04 +0000 | [diff] [blame] | 102 | /* cache lookup */ |
| 103 | struct device_node *of_find_next_cache_node(struct device_node *np); |
| 104 | |
Timur Tabi | 29cfe6f | 2007-02-16 12:01:29 -0600 | [diff] [blame] | 105 | /* Get the MAC address */ |
| 106 | extern const void *of_get_mac_address(struct device_node *np); |
Benjamin Herrenschmidt | cc9fd71 | 2006-07-03 19:35:17 +1000 | [diff] [blame] | 107 | |
| 108 | /* |
| 109 | * OF interrupt mapping |
| 110 | */ |
| 111 | |
Michael Ellerman | 40681b9 | 2006-08-02 11:13:50 +1000 | [diff] [blame] | 112 | /** |
Benjamin Herrenschmidt | cc9fd71 | 2006-07-03 19:35:17 +1000 | [diff] [blame] | 113 | * 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 | |
| 123 | extern void of_irq_map_init(unsigned int flags); |
| 124 | |
Michael Ellerman | 40681b9 | 2006-08-02 11:13:50 +1000 | [diff] [blame] | 125 | /** |
Benjamin Herrenschmidt | cc9fd71 | 2006-07-03 19:35:17 +1000 | [diff] [blame] | 126 | * 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 Herrenschmidt | 006b64d | 2006-08-25 14:46:23 +1000 | [diff] [blame] | 129 | * @ointsize: size of the passed in interrupt specifier |
Benjamin Herrenschmidt | cc9fd71 | 2006-07-03 19:35:17 +1000 | [diff] [blame] | 130 | * @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 Kerr | a7f67bd | 2006-07-12 15:35:54 +1000 | [diff] [blame] | 142 | 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] | 143 | u32 ointsize, const u32 *addr, |
Benjamin Herrenschmidt | cc9fd71 | 2006-07-03 19:35:17 +1000 | [diff] [blame] | 144 | struct of_irq *out_irq); |
| 145 | |
Michael Ellerman | 40681b9 | 2006-08-02 11:13:50 +1000 | [diff] [blame] | 146 | /** |
Benjamin Herrenschmidt | cc9fd71 | 2006-07-03 19:35:17 +1000 | [diff] [blame] | 147 | * 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 | */ |
| 157 | struct pci_dev; |
| 158 | extern int of_irq_map_pci(struct pci_dev *pdev, struct of_irq *out_irq); |
| 159 | |
Mathieu Desnoyers | c0b3ae1 | 2007-02-06 12:03:31 +1100 | [diff] [blame] | 160 | extern int of_irq_to_resource(struct device_node *dev, int index, |
| 161 | struct resource *r); |
Andy Fleming | a9b1497 | 2006-10-19 19:52:26 -0500 | [diff] [blame] | 162 | |
Christian Krafft | c3e8011 | 2007-04-25 01:32:02 +1000 | [diff] [blame] | 163 | /** |
| 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 | */ |
| 170 | extern void __iomem *of_iomap(struct device_node *device, int index); |
Benjamin Herrenschmidt | cc9fd71 | 2006-07-03 19:35:17 +1000 | [diff] [blame] | 171 | |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 172 | #endif /* __KERNEL__ */ |
| 173 | #endif /* _POWERPC_PROM_H */ |