memory.c 1.9 KB

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