devicetree.c 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  1. /*
  2. * Architecture specific OF callbacks.
  3. */
  4. #include <linux/bootmem.h>
  5. #include <linux/export.h>
  6. #include <linux/io.h>
  7. #include <linux/irqdomain.h>
  8. #include <linux/interrupt.h>
  9. #include <linux/list.h>
  10. #include <linux/of.h>
  11. #include <linux/of_fdt.h>
  12. #include <linux/of_address.h>
  13. #include <linux/of_platform.h>
  14. #include <linux/of_irq.h>
  15. #include <linux/slab.h>
  16. #include <linux/pci.h>
  17. #include <linux/of_pci.h>
  18. #include <linux/initrd.h>
  19. #include <asm/hpet.h>
  20. #include <asm/apic.h>
  21. #include <asm/pci_x86.h>
  22. #include <asm/setup.h>
  23. #include <asm/i8259.h>
  24. __initdata u64 initial_dtb;
  25. char __initdata cmd_line[COMMAND_LINE_SIZE];
  26. int __initdata of_ioapic;
  27. void __init early_init_dt_scan_chosen_arch(unsigned long node)
  28. {
  29. BUG();
  30. }
  31. void __init early_init_dt_add_memory_arch(u64 base, u64 size)
  32. {
  33. BUG();
  34. }
  35. void * __init early_init_dt_alloc_memory_arch(u64 size, u64 align)
  36. {
  37. return __alloc_bootmem(size, align, __pa(MAX_DMA_ADDRESS));
  38. }
  39. void __init add_dtb(u64 data)
  40. {
  41. initial_dtb = data + offsetof(struct setup_data, data);
  42. }
  43. /*
  44. * CE4100 ids. Will be moved to machine_device_initcall() once we have it.
  45. */
  46. static struct of_device_id __initdata ce4100_ids[] = {
  47. { .compatible = "intel,ce4100-cp", },
  48. { .compatible = "isa", },
  49. { .compatible = "pci", },
  50. {},
  51. };
  52. static int __init add_bus_probe(void)
  53. {
  54. if (!of_have_populated_dt())
  55. return 0;
  56. return of_platform_bus_probe(NULL, ce4100_ids, NULL);
  57. }
  58. module_init(add_bus_probe);
  59. #ifdef CONFIG_PCI
  60. struct device_node *pcibios_get_phb_of_node(struct pci_bus *bus)
  61. {
  62. struct device_node *np;
  63. for_each_node_by_type(np, "pci") {
  64. const void *prop;
  65. unsigned int bus_min;
  66. prop = of_get_property(np, "bus-range", NULL);
  67. if (!prop)
  68. continue;
  69. bus_min = be32_to_cpup(prop);
  70. if (bus->number == bus_min)
  71. return np;
  72. }
  73. return NULL;
  74. }
  75. static int x86_of_pci_irq_enable(struct pci_dev *dev)
  76. {
  77. u32 virq;
  78. int ret;
  79. u8 pin;
  80. ret = pci_read_config_byte(dev, PCI_INTERRUPT_PIN, &pin);
  81. if (ret)
  82. return ret;
  83. if (!pin)
  84. return 0;
  85. virq = of_irq_parse_and_map_pci(dev, 0, 0);
  86. if (virq == 0)
  87. return -EINVAL;
  88. dev->irq = virq;
  89. return 0;
  90. }
  91. static void x86_of_pci_irq_disable(struct pci_dev *dev)
  92. {
  93. }
  94. void x86_of_pci_init(void)
  95. {
  96. pcibios_enable_irq = x86_of_pci_irq_enable;
  97. pcibios_disable_irq = x86_of_pci_irq_disable;
  98. }
  99. #endif
  100. static void __init dtb_setup_hpet(void)
  101. {
  102. #ifdef CONFIG_HPET_TIMER
  103. struct device_node *dn;
  104. struct resource r;
  105. int ret;
  106. dn = of_find_compatible_node(NULL, NULL, "intel,ce4100-hpet");
  107. if (!dn)
  108. return;
  109. ret = of_address_to_resource(dn, 0, &r);
  110. if (ret) {
  111. WARN_ON(1);
  112. return;
  113. }
  114. hpet_address = r.start;
  115. #endif
  116. }
  117. static void __init dtb_lapic_setup(void)
  118. {
  119. #ifdef CONFIG_X86_LOCAL_APIC
  120. struct device_node *dn;
  121. struct resource r;
  122. int ret;
  123. dn = of_find_compatible_node(NULL, NULL, "intel,ce4100-lapic");
  124. if (!dn)
  125. return;
  126. ret = of_address_to_resource(dn, 0, &r);
  127. if (WARN_ON(ret))
  128. return;
  129. /* Did the boot loader setup the local APIC ? */
  130. if (!cpu_has_apic) {
  131. if (apic_force_enable(r.start))
  132. return;
  133. }
  134. smp_found_config = 1;
  135. pic_mode = 1;
  136. register_lapic_address(r.start);
  137. generic_processor_info(boot_cpu_physical_apicid,
  138. GET_APIC_VERSION(apic_read(APIC_LVR)));
  139. #endif
  140. }
  141. #ifdef CONFIG_X86_IO_APIC
  142. static unsigned int ioapic_id;
  143. struct of_ioapic_type {
  144. u32 out_type;
  145. u32 trigger;
  146. u32 polarity;
  147. };
  148. static struct of_ioapic_type of_ioapic_type[] =
  149. {
  150. {
  151. .out_type = IRQ_TYPE_EDGE_RISING,
  152. .trigger = IOAPIC_EDGE,
  153. .polarity = 1,
  154. },
  155. {
  156. .out_type = IRQ_TYPE_LEVEL_LOW,
  157. .trigger = IOAPIC_LEVEL,
  158. .polarity = 0,
  159. },
  160. {
  161. .out_type = IRQ_TYPE_LEVEL_HIGH,
  162. .trigger = IOAPIC_LEVEL,
  163. .polarity = 1,
  164. },
  165. {
  166. .out_type = IRQ_TYPE_EDGE_FALLING,
  167. .trigger = IOAPIC_EDGE,
  168. .polarity = 0,
  169. },
  170. };
  171. static int ioapic_xlate(struct irq_domain *domain,
  172. struct device_node *controller,
  173. const u32 *intspec, u32 intsize,
  174. irq_hw_number_t *out_hwirq, u32 *out_type)
  175. {
  176. struct of_ioapic_type *it;
  177. u32 line, idx, gsi;
  178. if (WARN_ON(intsize < 2))
  179. return -EINVAL;
  180. line = intspec[0];
  181. if (intspec[1] >= ARRAY_SIZE(of_ioapic_type))
  182. return -EINVAL;
  183. it = &of_ioapic_type[intspec[1]];
  184. idx = (u32)(long)domain->host_data;
  185. gsi = mp_pin_to_gsi(idx, line);
  186. if (mp_set_gsi_attr(gsi, it->trigger, it->polarity, cpu_to_node(0)))
  187. return -EBUSY;
  188. *out_hwirq = line;
  189. *out_type = it->out_type;
  190. return 0;
  191. }
  192. const struct irq_domain_ops ioapic_irq_domain_ops = {
  193. .map = mp_irqdomain_map,
  194. .unmap = mp_irqdomain_unmap,
  195. .xlate = ioapic_xlate,
  196. };
  197. static void __init dtb_add_ioapic(struct device_node *dn)
  198. {
  199. struct resource r;
  200. int ret;
  201. struct ioapic_domain_cfg cfg = {
  202. .type = IOAPIC_DOMAIN_DYNAMIC,
  203. .ops = &ioapic_irq_domain_ops,
  204. .dev = dn,
  205. };
  206. ret = of_address_to_resource(dn, 0, &r);
  207. if (ret) {
  208. printk(KERN_ERR "Can't obtain address from node %s.\n",
  209. dn->full_name);
  210. return;
  211. }
  212. mp_register_ioapic(++ioapic_id, r.start, gsi_top, &cfg);
  213. }
  214. static void __init dtb_ioapic_setup(void)
  215. {
  216. struct device_node *dn;
  217. for_each_compatible_node(dn, NULL, "intel,ce4100-ioapic")
  218. dtb_add_ioapic(dn);
  219. if (nr_ioapics) {
  220. of_ioapic = 1;
  221. return;
  222. }
  223. printk(KERN_ERR "Error: No information about IO-APIC in OF.\n");
  224. }
  225. #else
  226. static void __init dtb_ioapic_setup(void) {}
  227. #endif
  228. static void __init dtb_apic_setup(void)
  229. {
  230. dtb_lapic_setup();
  231. dtb_ioapic_setup();
  232. }
  233. #ifdef CONFIG_OF_FLATTREE
  234. static void __init x86_flattree_get_config(void)
  235. {
  236. u32 size, map_len;
  237. void *dt;
  238. if (!initial_dtb)
  239. return;
  240. map_len = max(PAGE_SIZE - (initial_dtb & ~PAGE_MASK), (u64)128);
  241. initial_boot_params = dt = early_memremap(initial_dtb, map_len);
  242. size = of_get_flat_dt_size();
  243. if (map_len < size) {
  244. early_iounmap(dt, map_len);
  245. initial_boot_params = dt = early_memremap(initial_dtb, size);
  246. map_len = size;
  247. }
  248. unflatten_and_copy_device_tree();
  249. early_iounmap(dt, map_len);
  250. }
  251. #else
  252. static inline void x86_flattree_get_config(void) { }
  253. #endif
  254. void __init x86_dtb_init(void)
  255. {
  256. x86_flattree_get_config();
  257. if (!of_have_populated_dt())
  258. return;
  259. dtb_setup_hpet();
  260. dtb_apic_setup();
  261. }