dyn_array.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. #include <linux/types.h>
  2. #include <linux/kernel.h>
  3. #include <linux/kallsyms.h>
  4. #include <linux/init.h>
  5. #include <linux/bootmem.h>
  6. #include <linux/irq.h>
  7. void __init pre_alloc_dyn_array(void)
  8. {
  9. #ifdef CONFIG_HAVE_DYN_ARRAY
  10. unsigned long total_size = 0, size, phys;
  11. unsigned long max_align = 1;
  12. struct dyn_array **daa;
  13. char *ptr;
  14. /* get the total size at first */
  15. for (daa = __dyn_array_start ; daa < __dyn_array_end; daa++) {
  16. struct dyn_array *da = *daa;
  17. size = da->size * (*da->nr);
  18. print_fn_descriptor_symbol("dyn_array %s ", da->name);
  19. printk(KERN_CONT "size:%#lx nr:%d align:%#lx\n",
  20. da->size, *da->nr, da->align);
  21. total_size += roundup(size, da->align);
  22. if (da->align > max_align)
  23. max_align = da->align;
  24. }
  25. if (total_size)
  26. printk(KERN_DEBUG "dyn_array total_size: %#lx\n",
  27. total_size);
  28. else
  29. return;
  30. /* allocate them all together */
  31. max_align = max_t(unsigned long, max_align, PAGE_SIZE);
  32. ptr = __alloc_bootmem(total_size, max_align, 0);
  33. phys = virt_to_phys(ptr);
  34. for (daa = __dyn_array_start ; daa < __dyn_array_end; daa++) {
  35. struct dyn_array *da = *daa;
  36. size = da->size * (*da->nr);
  37. print_fn_descriptor_symbol("dyn_array %s ", da->name);
  38. phys = roundup(phys, da->align);
  39. *da->name = phys_to_virt(phys);
  40. printk(KERN_CONT " ==> [%#lx - %#lx]\n", phys, phys + size);
  41. phys += size;
  42. if (da->init_work)
  43. da->init_work(da);
  44. }
  45. #else
  46. #ifdef CONFIG_GENERIC_HARDIRQS
  47. unsigned int i;
  48. for (i = 0; i < NR_IRQS; i++)
  49. irq_desc[i].irq = i;
  50. #endif
  51. #endif
  52. }
  53. unsigned long __init per_cpu_dyn_array_size(unsigned long *align)
  54. {
  55. unsigned long total_size = 0;
  56. #ifdef CONFIG_HAVE_DYN_ARRAY
  57. unsigned long size;
  58. struct dyn_array **daa;
  59. unsigned max_align = 1;
  60. for (daa = __per_cpu_dyn_array_start ; daa < __per_cpu_dyn_array_end; daa++) {
  61. struct dyn_array *da = *daa;
  62. size = da->size * (*da->nr);
  63. print_fn_descriptor_symbol("per_cpu_dyn_array %s ", da->name);
  64. printk(KERN_CONT "size:%#lx nr:%d align:%#lx\n",
  65. da->size, *da->nr, da->align);
  66. total_size += roundup(size, da->align);
  67. if (da->align > max_align)
  68. max_align = da->align;
  69. }
  70. if (total_size) {
  71. printk(KERN_DEBUG "per_cpu_dyn_array total_size: %#lx\n",
  72. total_size);
  73. *align = max_align;
  74. }
  75. #endif
  76. return total_size;
  77. }
  78. #ifdef CONFIG_SMP
  79. void __init per_cpu_alloc_dyn_array(int cpu, char *ptr)
  80. {
  81. #ifdef CONFIG_HAVE_DYN_ARRAY
  82. unsigned long size, phys;
  83. struct dyn_array **daa;
  84. unsigned long addr;
  85. void **array;
  86. phys = virt_to_phys(ptr);
  87. for (daa = __per_cpu_dyn_array_start ; daa < __per_cpu_dyn_array_end; daa++) {
  88. struct dyn_array *da = *daa;
  89. size = da->size * (*da->nr);
  90. print_fn_descriptor_symbol("per_cpu_dyn_array %s ", da->name);
  91. phys = roundup(phys, da->align);
  92. addr = (unsigned long)da->name;
  93. addr += per_cpu_offset(cpu);
  94. array = (void **)addr;
  95. *array = phys_to_virt(phys);
  96. *da->name = *array; /* so init_work could use it directly */
  97. printk(KERN_CONT " ==> [%#lx - %#lx]\n", phys, phys + size);
  98. phys += size;
  99. if (da->init_work)
  100. da->init_work(da);
  101. }
  102. #endif
  103. }
  104. #endif