devicetree.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. /*
  2. * Architecture specific OF callbacks.
  3. */
  4. #include <linux/bootmem.h>
  5. #include <linux/io.h>
  6. #include <linux/interrupt.h>
  7. #include <linux/list.h>
  8. #include <linux/of.h>
  9. #include <linux/of_fdt.h>
  10. #include <linux/of_address.h>
  11. #include <linux/of_platform.h>
  12. #include <linux/slab.h>
  13. #include <asm/hpet.h>
  14. #include <asm/irq_controller.h>
  15. #include <asm/apic.h>
  16. __initdata u64 initial_dtb;
  17. char __initdata cmd_line[COMMAND_LINE_SIZE];
  18. static LIST_HEAD(irq_domains);
  19. static DEFINE_RAW_SPINLOCK(big_irq_lock);
  20. int __initdata of_ioapic;
  21. void add_interrupt_host(struct irq_domain *ih)
  22. {
  23. unsigned long flags;
  24. raw_spin_lock_irqsave(&big_irq_lock, flags);
  25. list_add(&ih->l, &irq_domains);
  26. raw_spin_unlock_irqrestore(&big_irq_lock, flags);
  27. }
  28. static struct irq_domain *get_ih_from_node(struct device_node *controller)
  29. {
  30. struct irq_domain *ih, *found = NULL;
  31. unsigned long flags;
  32. raw_spin_lock_irqsave(&big_irq_lock, flags);
  33. list_for_each_entry(ih, &irq_domains, l) {
  34. if (ih->controller == controller) {
  35. found = ih;
  36. break;
  37. }
  38. }
  39. raw_spin_unlock_irqrestore(&big_irq_lock, flags);
  40. return found;
  41. }
  42. unsigned int irq_create_of_mapping(struct device_node *controller,
  43. const u32 *intspec, unsigned int intsize)
  44. {
  45. struct irq_domain *ih;
  46. u32 virq, type;
  47. int ret;
  48. ih = get_ih_from_node(controller);
  49. if (!ih)
  50. return 0;
  51. ret = ih->xlate(ih, intspec, intsize, &virq, &type);
  52. if (ret)
  53. return ret;
  54. if (type == IRQ_TYPE_NONE)
  55. return virq;
  56. /* set the mask if it is different from current */
  57. if (type == (irq_to_desc(virq)->status & IRQF_TRIGGER_MASK))
  58. set_irq_type(virq, type);
  59. return virq;
  60. }
  61. EXPORT_SYMBOL_GPL(irq_create_of_mapping);
  62. unsigned long pci_address_to_pio(phys_addr_t address)
  63. {
  64. /*
  65. * The ioport address can be directly used by inX / outX
  66. */
  67. BUG_ON(address >= (1 << 16));
  68. return (unsigned long)address;
  69. }
  70. EXPORT_SYMBOL_GPL(pci_address_to_pio);
  71. void __init early_init_dt_scan_chosen_arch(unsigned long node)
  72. {
  73. BUG();
  74. }
  75. void __init early_init_dt_add_memory_arch(u64 base, u64 size)
  76. {
  77. BUG();
  78. }
  79. void * __init early_init_dt_alloc_memory_arch(u64 size, u64 align)
  80. {
  81. return __alloc_bootmem(size, align, __pa(MAX_DMA_ADDRESS));
  82. }
  83. void __init add_dtb(u64 data)
  84. {
  85. initial_dtb = data + offsetof(struct setup_data, data);
  86. }
  87. static void __init dtb_setup_hpet(void)
  88. {
  89. struct device_node *dn;
  90. struct resource r;
  91. int ret;
  92. dn = of_find_compatible_node(NULL, NULL, "intel,ce4100-hpet");
  93. if (!dn)
  94. return;
  95. ret = of_address_to_resource(dn, 0, &r);
  96. if (ret) {
  97. WARN_ON(1);
  98. return;
  99. }
  100. hpet_address = r.start;
  101. }
  102. static void __init dtb_lapic_setup(void)
  103. {
  104. #ifdef CONFIG_X86_LOCAL_APIC
  105. if (apic_force_enable())
  106. return;
  107. smp_found_config = 1;
  108. pic_mode = 1;
  109. /* Required for ioapic registration */
  110. set_fixmap_nocache(FIX_APIC_BASE, mp_lapic_addr);
  111. if (boot_cpu_physical_apicid == -1U)
  112. boot_cpu_physical_apicid = read_apic_id();
  113. generic_processor_info(boot_cpu_physical_apicid,
  114. GET_APIC_VERSION(apic_read(APIC_LVR)));
  115. #endif
  116. }
  117. #ifdef CONFIG_X86_IO_APIC
  118. static unsigned int ioapic_id;
  119. static void __init dtb_add_ioapic(struct device_node *dn)
  120. {
  121. struct resource r;
  122. int ret;
  123. ret = of_address_to_resource(dn, 0, &r);
  124. if (ret) {
  125. printk(KERN_ERR "Can't obtain address from node %s.\n",
  126. dn->full_name);
  127. return;
  128. }
  129. mp_register_ioapic(++ioapic_id, r.start, gsi_top);
  130. }
  131. static void __init dtb_ioapic_setup(void)
  132. {
  133. struct device_node *dn;
  134. if (!smp_found_config)
  135. return;
  136. for_each_compatible_node(dn, NULL, "intel,ce4100-ioapic")
  137. dtb_add_ioapic(dn);
  138. if (nr_ioapics) {
  139. of_ioapic = 1;
  140. return;
  141. }
  142. printk(KERN_ERR "Error: No information about IO-APIC in OF.\n");
  143. smp_found_config = 0;
  144. }
  145. #else
  146. static void __init dtb_ioapic_setup(void) {}
  147. #endif
  148. static void __init dtb_apic_setup(void)
  149. {
  150. dtb_lapic_setup();
  151. dtb_ioapic_setup();
  152. }
  153. void __init x86_dtb_find_config(void)
  154. {
  155. if (initial_dtb)
  156. smp_found_config = 1;
  157. else
  158. printk(KERN_ERR "Missing device tree!.\n");
  159. }
  160. void __init x86_dtb_get_config(unsigned int unused)
  161. {
  162. u32 size, map_len;
  163. void *new_dtb;
  164. if (!initial_dtb)
  165. return;
  166. map_len = max(PAGE_SIZE - (initial_dtb & ~PAGE_MASK),
  167. (u64)sizeof(struct boot_param_header));
  168. initial_boot_params = early_memremap(initial_dtb, map_len);
  169. size = be32_to_cpu(initial_boot_params->totalsize);
  170. if (map_len < size) {
  171. early_iounmap(initial_boot_params, map_len);
  172. initial_boot_params = early_memremap(initial_dtb, size);
  173. map_len = size;
  174. }
  175. new_dtb = alloc_bootmem(size);
  176. memcpy(new_dtb, initial_boot_params, size);
  177. early_iounmap(initial_boot_params, map_len);
  178. initial_boot_params = new_dtb;
  179. /* root level address cells */
  180. of_scan_flat_dt(early_init_dt_scan_root, NULL);
  181. unflatten_device_tree();
  182. dtb_setup_hpet();
  183. dtb_apic_setup();
  184. }