devicetree.c 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  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/interrupt.h>
  8. #include <linux/list.h>
  9. #include <linux/of.h>
  10. #include <linux/of_fdt.h>
  11. #include <linux/of_address.h>
  12. #include <linux/of_platform.h>
  13. #include <linux/of_irq.h>
  14. #include <linux/slab.h>
  15. #include <linux/pci.h>
  16. #include <linux/of_pci.h>
  17. #include <linux/initrd.h>
  18. #include <asm/irqdomain.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. device_initcall(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 (!boot_cpu_has(X86_FEATURE_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 dt_irqdomain_alloc(struct irq_domain *domain, unsigned int virq,
  172. unsigned int nr_irqs, void *arg)
  173. {
  174. struct of_phandle_args *irq_data = (void *)arg;
  175. struct of_ioapic_type *it;
  176. struct irq_alloc_info tmp;
  177. if (WARN_ON(irq_data->args_count < 2))
  178. return -EINVAL;
  179. if (irq_data->args[1] >= ARRAY_SIZE(of_ioapic_type))
  180. return -EINVAL;
  181. it = &of_ioapic_type[irq_data->args[1]];
  182. ioapic_set_alloc_attr(&tmp, NUMA_NO_NODE, it->trigger, it->polarity);
  183. tmp.ioapic_id = mpc_ioapic_id(mp_irqdomain_ioapic_idx(domain));
  184. tmp.ioapic_pin = irq_data->args[0];
  185. return mp_irqdomain_alloc(domain, virq, nr_irqs, &tmp);
  186. }
  187. static const struct irq_domain_ops ioapic_irq_domain_ops = {
  188. .alloc = dt_irqdomain_alloc,
  189. .free = mp_irqdomain_free,
  190. .activate = mp_irqdomain_activate,
  191. .deactivate = mp_irqdomain_deactivate,
  192. };
  193. static void __init dtb_add_ioapic(struct device_node *dn)
  194. {
  195. struct resource r;
  196. int ret;
  197. struct ioapic_domain_cfg cfg = {
  198. .type = IOAPIC_DOMAIN_DYNAMIC,
  199. .ops = &ioapic_irq_domain_ops,
  200. .dev = dn,
  201. };
  202. ret = of_address_to_resource(dn, 0, &r);
  203. if (ret) {
  204. printk(KERN_ERR "Can't obtain address from node %s.\n",
  205. dn->full_name);
  206. return;
  207. }
  208. mp_register_ioapic(++ioapic_id, r.start, gsi_top, &cfg);
  209. }
  210. static void __init dtb_ioapic_setup(void)
  211. {
  212. struct device_node *dn;
  213. for_each_compatible_node(dn, NULL, "intel,ce4100-ioapic")
  214. dtb_add_ioapic(dn);
  215. if (nr_ioapics) {
  216. of_ioapic = 1;
  217. return;
  218. }
  219. printk(KERN_ERR "Error: No information about IO-APIC in OF.\n");
  220. }
  221. #else
  222. static void __init dtb_ioapic_setup(void) {}
  223. #endif
  224. static void __init dtb_apic_setup(void)
  225. {
  226. dtb_lapic_setup();
  227. dtb_ioapic_setup();
  228. }
  229. #ifdef CONFIG_OF_FLATTREE
  230. static void __init x86_flattree_get_config(void)
  231. {
  232. u32 size, map_len;
  233. void *dt;
  234. if (!initial_dtb)
  235. return;
  236. map_len = max(PAGE_SIZE - (initial_dtb & ~PAGE_MASK), (u64)128);
  237. initial_boot_params = dt = early_memremap(initial_dtb, map_len);
  238. size = of_get_flat_dt_size();
  239. if (map_len < size) {
  240. early_memunmap(dt, map_len);
  241. initial_boot_params = dt = early_memremap(initial_dtb, size);
  242. map_len = size;
  243. }
  244. unflatten_and_copy_device_tree();
  245. early_memunmap(dt, map_len);
  246. }
  247. #else
  248. static inline void x86_flattree_get_config(void) { }
  249. #endif
  250. void __init x86_dtb_init(void)
  251. {
  252. x86_flattree_get_config();
  253. if (!of_have_populated_dt())
  254. return;
  255. dtb_setup_hpet();
  256. dtb_apic_setup();
  257. }