030-01-MIPS-BCM47XX-Get-rid-of-calls-to-KSEG1ADDR.patch 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. From 8d602dd0f984e8488ab891344ebdb6e1f3128c4a Mon Sep 17 00:00:00 2001
  2. From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= <zajec5@gmail.com>
  3. Date: Wed, 3 Sep 2014 22:51:06 +0200
  4. Subject: [PATCH 154/158] MIPS: BCM47XX: Get rid of calls to KSEG1ADDR
  5. MIME-Version: 1.0
  6. Content-Type: text/plain; charset=UTF-8
  7. Content-Transfer-Encoding: 8bit
  8. We should be using ioremap_nocache helper which handles remaps in a
  9. smarter way.
  10. Signed-off-by: Rafał Miłecki <zajec5@gmail.com>
  11. Cc: linux-mips@linux-mips.org
  12. Cc: Hauke Mehrtens <hauke@hauke-m.de>
  13. Patchwork: http://patchwork.linux-mips.org/patch/7611/
  14. Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
  15. ---
  16. arch/mips/bcm47xx/nvram.c | 44 ++++++++++++++++++++++++++++++++------------
  17. 1 file changed, 32 insertions(+), 12 deletions(-)
  18. --- a/arch/mips/bcm47xx/nvram.c
  19. +++ b/arch/mips/bcm47xx/nvram.c
  20. @@ -23,13 +23,13 @@
  21. static char nvram_buf[NVRAM_SPACE];
  22. static const u32 nvram_sizes[] = {0x8000, 0xF000, 0x10000};
  23. -static u32 find_nvram_size(u32 end)
  24. +static u32 find_nvram_size(void __iomem *end)
  25. {
  26. - struct nvram_header *header;
  27. + struct nvram_header __iomem *header;
  28. int i;
  29. for (i = 0; i < ARRAY_SIZE(nvram_sizes); i++) {
  30. - header = (struct nvram_header *)KSEG1ADDR(end - nvram_sizes[i]);
  31. + header = (struct nvram_header *)(end - nvram_sizes[i]);
  32. if (header->magic == NVRAM_HEADER)
  33. return nvram_sizes[i];
  34. }
  35. @@ -38,35 +38,39 @@ static u32 find_nvram_size(u32 end)
  36. }
  37. /* Probe for NVRAM header */
  38. -static int nvram_find_and_copy(u32 base, u32 lim)
  39. +static int nvram_find_and_copy(void __iomem *iobase, u32 lim)
  40. {
  41. - struct nvram_header *header;
  42. + struct nvram_header __iomem *header;
  43. int i;
  44. u32 off;
  45. u32 *src, *dst;
  46. u32 size;
  47. + if (nvram_buf[0]) {
  48. + pr_warn("nvram already initialized\n");
  49. + return -EEXIST;
  50. + }
  51. +
  52. /* TODO: when nvram is on nand flash check for bad blocks first. */
  53. off = FLASH_MIN;
  54. while (off <= lim) {
  55. /* Windowed flash access */
  56. - size = find_nvram_size(base + off);
  57. + size = find_nvram_size(iobase + off);
  58. if (size) {
  59. - header = (struct nvram_header *)KSEG1ADDR(base + off -
  60. - size);
  61. + header = (struct nvram_header *)(iobase + off - size);
  62. goto found;
  63. }
  64. off <<= 1;
  65. }
  66. /* Try embedded NVRAM at 4 KB and 1 KB as last resorts */
  67. - header = (struct nvram_header *) KSEG1ADDR(base + 4096);
  68. + header = (struct nvram_header *)(iobase + 4096);
  69. if (header->magic == NVRAM_HEADER) {
  70. size = NVRAM_SPACE;
  71. goto found;
  72. }
  73. - header = (struct nvram_header *) KSEG1ADDR(base + 1024);
  74. + header = (struct nvram_header *)(iobase + 1024);
  75. if (header->magic == NVRAM_HEADER) {
  76. size = NVRAM_SPACE;
  77. goto found;
  78. @@ -94,6 +98,22 @@ found:
  79. return 0;
  80. }
  81. +static int bcm47xx_nvram_init_from_mem(u32 base, u32 lim)
  82. +{
  83. + void __iomem *iobase;
  84. + int err;
  85. +
  86. + iobase = ioremap_nocache(base, lim);
  87. + if (!iobase)
  88. + return -ENOMEM;
  89. +
  90. + err = nvram_find_and_copy(iobase, lim);
  91. +
  92. + iounmap(iobase);
  93. +
  94. + return err;
  95. +}
  96. +
  97. #ifdef CONFIG_BCM47XX_SSB
  98. static int nvram_init_ssb(void)
  99. {
  100. @@ -109,7 +129,7 @@ static int nvram_init_ssb(void)
  101. return -ENXIO;
  102. }
  103. - return nvram_find_and_copy(base, lim);
  104. + return bcm47xx_nvram_init_from_mem(base, lim);
  105. }
  106. #endif
  107. @@ -139,7 +159,7 @@ static int nvram_init_bcma(void)
  108. return -ENXIO;
  109. }
  110. - return nvram_find_and_copy(base, lim);
  111. + return bcm47xx_nvram_init_from_mem(base, lim);
  112. }
  113. #endif