~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/arch/sparc/kernel/of_device_common.c

Version: ~ [ linux-5.11 ] ~ [ linux-5.10.17 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.99 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.176 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.221 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.257 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.257 ] ~ [ linux-4.3.6 ] ~ [ linux-4.2.8 ] ~ [ linux-4.1.52 ] ~ [ linux-4.0.9 ] ~ [ linux-3.19.8 ] ~ [ linux-3.18.140 ] ~ [ linux-3.17.8 ] ~ [ linux-3.16.85 ] ~ [ linux-3.15.10 ] ~ [ linux-3.14.79 ] ~ [ linux-3.13.11 ] ~ [ linux-3.12.74 ] ~ [ linux-3.11.10 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.5 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 #include <linux/string.h>
  2 #include <linux/kernel.h>
  3 #include <linux/of.h>
  4 #include <linux/export.h>
  5 #include <linux/mod_devicetable.h>
  6 #include <linux/errno.h>
  7 #include <linux/irq.h>
  8 #include <linux/of_platform.h>
  9 #include <linux/of_address.h>
 10 #include <linux/of_device.h>
 11 #include <linux/of_irq.h>
 12 
 13 #include "of_device_common.h"
 14 
 15 unsigned int irq_of_parse_and_map(struct device_node *node, int index)
 16 {
 17         struct platform_device *op = of_find_device_by_node(node);
 18 
 19         if (!op || index >= op->archdata.num_irqs)
 20                 return 0;
 21 
 22         return op->archdata.irqs[index];
 23 }
 24 EXPORT_SYMBOL(irq_of_parse_and_map);
 25 
 26 int of_address_to_resource(struct device_node *node, int index,
 27                            struct resource *r)
 28 {
 29         struct platform_device *op = of_find_device_by_node(node);
 30 
 31         if (!op || index >= op->num_resources)
 32                 return -EINVAL;
 33 
 34         memcpy(r, &op->archdata.resource[index], sizeof(*r));
 35         return 0;
 36 }
 37 EXPORT_SYMBOL_GPL(of_address_to_resource);
 38 
 39 void __iomem *of_iomap(struct device_node *node, int index)
 40 {
 41         struct platform_device *op = of_find_device_by_node(node);
 42         struct resource *r;
 43 
 44         if (!op || index >= op->num_resources)
 45                 return NULL;
 46 
 47         r = &op->archdata.resource[index];
 48 
 49         return of_ioremap(r, 0, resource_size(r), (char *) r->name);
 50 }
 51 EXPORT_SYMBOL(of_iomap);
 52 
 53 /* Take the archdata values for IOMMU, STC, and HOSTDATA found in
 54  * BUS and propagate to all child platform_device objects.
 55  */
 56 void of_propagate_archdata(struct platform_device *bus)
 57 {
 58         struct dev_archdata *bus_sd = &bus->dev.archdata;
 59         struct device_node *bus_dp = bus->dev.of_node;
 60         struct device_node *dp;
 61 
 62         for (dp = bus_dp->child; dp; dp = dp->sibling) {
 63                 struct platform_device *op = of_find_device_by_node(dp);
 64 
 65                 op->dev.archdata.iommu = bus_sd->iommu;
 66                 op->dev.archdata.stc = bus_sd->stc;
 67                 op->dev.archdata.host_controller = bus_sd->host_controller;
 68                 op->dev.archdata.numa_node = bus_sd->numa_node;
 69 
 70                 if (dp->child)
 71                         of_propagate_archdata(op);
 72         }
 73 }
 74 
 75 static void get_cells(struct device_node *dp, int *addrc, int *sizec)
 76 {
 77         if (addrc)
 78                 *addrc = of_n_addr_cells(dp);
 79         if (sizec)
 80                 *sizec = of_n_size_cells(dp);
 81 }
 82 
 83 /*
 84  * Default translator (generic bus)
 85  */
 86 
 87 void of_bus_default_count_cells(struct device_node *dev, int *addrc, int *sizec)
 88 {
 89         get_cells(dev, addrc, sizec);
 90 }
 91 
 92 /* Make sure the least significant 64-bits are in-range.  Even
 93  * for 3 or 4 cell values it is a good enough approximation.
 94  */
 95 int of_out_of_range(const u32 *addr, const u32 *base,
 96                     const u32 *size, int na, int ns)
 97 {
 98         u64 a = of_read_addr(addr, na);
 99         u64 b = of_read_addr(base, na);
100 
101         if (a < b)
102                 return 1;
103 
104         b += of_read_addr(size, ns);
105         if (a >= b)
106                 return 1;
107 
108         return 0;
109 }
110 
111 int of_bus_default_map(u32 *addr, const u32 *range, int na, int ns, int pna)
112 {
113         u32 result[OF_MAX_ADDR_CELLS];
114         int i;
115 
116         if (ns > 2) {
117                 printk("of_device: Cannot handle size cells (%d) > 2.", ns);
118                 return -EINVAL;
119         }
120 
121         if (of_out_of_range(addr, range, range + na + pna, na, ns))
122                 return -EINVAL;
123 
124         /* Start with the parent range base.  */
125         memcpy(result, range + na, pna * 4);
126 
127         /* Add in the child address offset.  */
128         for (i = 0; i < na; i++)
129                 result[pna - 1 - i] +=
130                         (addr[na - 1 - i] -
131                          range[na - 1 - i]);
132 
133         memcpy(addr, result, pna * 4);
134 
135         return 0;
136 }
137 
138 unsigned long of_bus_default_get_flags(const u32 *addr, unsigned long flags)
139 {
140         if (flags)
141                 return flags;
142         return IORESOURCE_MEM;
143 }
144 
145 /*
146  * SBUS bus specific translator
147  */
148 
149 int of_bus_sbus_match(struct device_node *np)
150 {
151         struct device_node *dp = np;
152 
153         while (dp) {
154                 if (!strcmp(dp->name, "sbus") ||
155                     !strcmp(dp->name, "sbi"))
156                         return 1;
157 
158                 /* Have a look at use_1to1_mapping().  We're trying
159                  * to match SBUS if that's the top-level bus and we
160                  * don't have some intervening real bus that provides
161                  * ranges based translations.
162                  */
163                 if (of_find_property(dp, "ranges", NULL) != NULL)
164                         break;
165 
166                 dp = dp->parent;
167         }
168 
169         return 0;
170 }
171 
172 void of_bus_sbus_count_cells(struct device_node *child, int *addrc, int *sizec)
173 {
174         if (addrc)
175                 *addrc = 2;
176         if (sizec)
177                 *sizec = 1;
178 }
179 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | Wiki (Japanese) | Wiki (English) | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

osdn.jp