memory.c 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /* memory.c: Prom routine for acquiring various bits of information
  2. * about RAM on the machine, both virtual and physical.
  3. *
  4. * Copyright (C) 1995, 2008 David S. Miller (davem@davemloft.net)
  5. * Copyright (C) 1997 Michael A. Griffith (grif@acm.org)
  6. */
  7. #include <linux/kernel.h>
  8. #include <linux/sort.h>
  9. #include <linux/init.h>
  10. #include <asm/openprom.h>
  11. #include <asm/oplib.h>
  12. #include <asm/page.h>
  13. static int __init prom_meminit_v0(void)
  14. {
  15. struct linux_mlist_v0 *p;
  16. int index;
  17. index = 0;
  18. for (p = *(romvec->pv_v0mem.v0_available); p; p = p->theres_more) {
  19. sp_banks[index].base_addr = (unsigned long) p->start_adr;
  20. sp_banks[index].num_bytes = p->num_bytes;
  21. index++;
  22. }
  23. return index;
  24. }
  25. static int __init prom_meminit_v2(void)
  26. {
  27. struct linux_prom_registers reg[64];
  28. phandle node;
  29. int size, num_ents, i;
  30. node = prom_searchsiblings(prom_getchild(prom_root_node), "memory");
  31. size = prom_getproperty(node, "available", (char *) reg, sizeof(reg));
  32. num_ents = size / sizeof(struct linux_prom_registers);
  33. for (i = 0; i < num_ents; i++) {
  34. sp_banks[i].base_addr = reg[i].phys_addr;
  35. sp_banks[i].num_bytes = reg[i].reg_size;
  36. }
  37. return num_ents;
  38. }
  39. static int sp_banks_cmp(const void *a, const void *b)
  40. {
  41. const struct sparc_phys_banks *x = a, *y = b;
  42. if (x->base_addr > y->base_addr)
  43. return 1;
  44. if (x->base_addr < y->base_addr)
  45. return -1;
  46. return 0;
  47. }
  48. /* Initialize the memory lists based upon the prom version. */
  49. void __init prom_meminit(void)
  50. {
  51. int i, num_ents = 0;
  52. switch (prom_vers) {
  53. case PROM_V0:
  54. num_ents = prom_meminit_v0();
  55. break;
  56. case PROM_V2:
  57. case PROM_V3:
  58. num_ents = prom_meminit_v2();
  59. break;
  60. default:
  61. break;
  62. }
  63. sort(sp_banks, num_ents, sizeof(struct sparc_phys_banks),
  64. sp_banks_cmp, NULL);
  65. /* Sentinel. */
  66. sp_banks[num_ents].base_addr = 0xdeadbeef;
  67. sp_banks[num_ents].num_bytes = 0;
  68. for (i = 0; i < num_ents; i++)
  69. sp_banks[i].num_bytes &= PAGE_MASK;
  70. }