memory.c 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. int node, size, num_ents, i;
  29. node = prom_searchsiblings(prom_getchild(prom_root_node), "memory");
  30. size = prom_getproperty(node, "available", (char *) reg, sizeof(reg));
  31. num_ents = size / sizeof(struct linux_prom_registers);
  32. for (i = 0; i < num_ents; i++) {
  33. sp_banks[i].base_addr = reg[i].phys_addr;
  34. sp_banks[i].num_bytes = reg[i].reg_size;
  35. }
  36. return num_ents;
  37. }
  38. static int sp_banks_cmp(const void *a, const void *b)
  39. {
  40. const struct sparc_phys_banks *x = a, *y = b;
  41. if (x->base_addr > y->base_addr)
  42. return 1;
  43. if (x->base_addr < y->base_addr)
  44. return -1;
  45. return 0;
  46. }
  47. /* Initialize the memory lists based upon the prom version. */
  48. void __init prom_meminit(void)
  49. {
  50. int i, num_ents = 0;
  51. switch (prom_vers) {
  52. case PROM_V0:
  53. num_ents = prom_meminit_v0();
  54. break;
  55. case PROM_V2:
  56. case PROM_V3:
  57. num_ents = prom_meminit_v2();
  58. break;
  59. default:
  60. break;
  61. }
  62. sort(sp_banks, num_ents, sizeof(struct sparc_phys_banks),
  63. sp_banks_cmp, NULL);
  64. /* Sentinel. */
  65. sp_banks[num_ents].base_addr = 0xdeadbeef;
  66. sp_banks[num_ents].num_bytes = 0;
  67. for (i = 0; i < num_ents; i++)
  68. sp_banks[i].num_bytes &= PAGE_MASK;
  69. }