mem.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. /*
  2. * This program is free software; you can redistribute it and/or modify it
  3. * under the terms of the GNU General Public License as published by the
  4. * Free Software Foundation; either version 2 of the License, or (at your
  5. * option) any later version.
  6. */
  7. #include <linux/fs.h>
  8. #include <linux/fcntl.h>
  9. #include <linux/mm.h>
  10. #include <asm/bootinfo.h>
  11. #include <loongson.h>
  12. #include <boot_param.h>
  13. #include <mem.h>
  14. #include <pci.h>
  15. #ifndef CONFIG_LEFI_FIRMWARE_INTERFACE
  16. u32 memsize, highmemsize;
  17. void __init prom_init_memory(void)
  18. {
  19. add_memory_region(0x0, (memsize << 20), BOOT_MEM_RAM);
  20. add_memory_region(memsize << 20, LOONGSON_PCI_MEM_START - (memsize <<
  21. 20), BOOT_MEM_RESERVED);
  22. #ifdef CONFIG_CPU_SUPPORTS_ADDRWINCFG
  23. {
  24. int bit;
  25. bit = fls(memsize + highmemsize);
  26. if (bit != ffs(memsize + highmemsize))
  27. bit += 20;
  28. else
  29. bit = bit + 20 - 1;
  30. /* set cpu window3 to map CPU to DDR: 2G -> 2G */
  31. LOONGSON_ADDRWIN_CPUTODDR(ADDRWIN_WIN3, 0x80000000ul,
  32. 0x80000000ul, (1 << bit));
  33. mmiowb();
  34. }
  35. #endif /* !CONFIG_CPU_SUPPORTS_ADDRWINCFG */
  36. #ifdef CONFIG_64BIT
  37. if (highmemsize > 0)
  38. add_memory_region(LOONGSON_HIGHMEM_START,
  39. highmemsize << 20, BOOT_MEM_RAM);
  40. add_memory_region(LOONGSON_PCI_MEM_END + 1, LOONGSON_HIGHMEM_START -
  41. LOONGSON_PCI_MEM_END - 1, BOOT_MEM_RESERVED);
  42. #endif /* !CONFIG_64BIT */
  43. }
  44. #else /* CONFIG_LEFI_FIRMWARE_INTERFACE */
  45. void __init prom_init_memory(void)
  46. {
  47. int i;
  48. u32 node_id;
  49. u32 mem_type;
  50. /* parse memory information */
  51. for (i = 0; i < loongson_memmap->nr_map; i++) {
  52. node_id = loongson_memmap->map[i].node_id;
  53. mem_type = loongson_memmap->map[i].mem_type;
  54. if (node_id == 0) {
  55. switch (mem_type) {
  56. case SYSTEM_RAM_LOW:
  57. add_memory_region(loongson_memmap->map[i].mem_start,
  58. (u64)loongson_memmap->map[i].mem_size << 20,
  59. BOOT_MEM_RAM);
  60. break;
  61. case SYSTEM_RAM_HIGH:
  62. add_memory_region(loongson_memmap->map[i].mem_start,
  63. (u64)loongson_memmap->map[i].mem_size << 20,
  64. BOOT_MEM_RAM);
  65. break;
  66. case SYSTEM_RAM_RESERVED:
  67. add_memory_region(loongson_memmap->map[i].mem_start,
  68. (u64)loongson_memmap->map[i].mem_size << 20,
  69. BOOT_MEM_RESERVED);
  70. break;
  71. }
  72. }
  73. }
  74. }
  75. #endif /* CONFIG_LEFI_FIRMWARE_INTERFACE */
  76. /* override of arch/mips/mm/cache.c: __uncached_access */
  77. int __uncached_access(struct file *file, unsigned long addr)
  78. {
  79. if (file->f_flags & O_DSYNC)
  80. return 1;
  81. return addr >= __pa(high_memory) ||
  82. ((addr >= LOONGSON_MMIO_MEM_START) &&
  83. (addr < LOONGSON_MMIO_MEM_END));
  84. }
  85. #ifdef CONFIG_CPU_SUPPORTS_UNCACHED_ACCELERATED
  86. #include <linux/pci.h>
  87. #include <linux/sched.h>
  88. #include <asm/current.h>
  89. static unsigned long uca_start, uca_end;
  90. pgprot_t phys_mem_access_prot(struct file *file, unsigned long pfn,
  91. unsigned long size, pgprot_t vma_prot)
  92. {
  93. unsigned long offset = pfn << PAGE_SHIFT;
  94. unsigned long end = offset + size;
  95. if (__uncached_access(file, offset)) {
  96. if (uca_start && (offset >= uca_start) &&
  97. (end <= uca_end))
  98. return __pgprot((pgprot_val(vma_prot) &
  99. ~_CACHE_MASK) |
  100. _CACHE_UNCACHED_ACCELERATED);
  101. else
  102. return pgprot_noncached(vma_prot);
  103. }
  104. return vma_prot;
  105. }
  106. static int __init find_vga_mem_init(void)
  107. {
  108. struct pci_dev *dev = 0;
  109. struct resource *r;
  110. int idx;
  111. if (uca_start)
  112. return 0;
  113. for_each_pci_dev(dev) {
  114. if ((dev->class >> 16) == PCI_BASE_CLASS_DISPLAY) {
  115. for (idx = 0; idx < PCI_NUM_RESOURCES; idx++) {
  116. r = &dev->resource[idx];
  117. if (!r->start && r->end)
  118. continue;
  119. if (r->flags & IORESOURCE_IO)
  120. continue;
  121. if (r->flags & IORESOURCE_MEM) {
  122. uca_start = r->start;
  123. uca_end = r->end;
  124. return 0;
  125. }
  126. }
  127. }
  128. }
  129. return 0;
  130. }
  131. late_initcall(find_vga_mem_init);
  132. #endif /* !CONFIG_CPU_SUPPORTS_UNCACHED_ACCELERATED */