| b.liu | e958203 | 2025-04-17 19:18:16 +0800 | [diff] [blame] | 1 | From 298923cf999cecd2ef06df126f85a3d68da8c4d8 Mon Sep 17 00:00:00 2001 |
| 2 | From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= <rafal@milecki.pl> |
| 3 | Date: Mon, 8 Mar 2021 10:03:18 +0100 |
| 4 | Subject: [PATCH] firmware: bcm47xx_nvram: extract code copying NVRAM |
| 5 | MIME-Version: 1.0 |
| 6 | Content-Type: text/plain; charset=UTF-8 |
| 7 | Content-Transfer-Encoding: 8bit |
| 8 | |
| 9 | This simplifies function finding NVRAM. It doesn't directly deal with |
| 10 | NVRAM structure anymore and is a bit smaller. |
| 11 | |
| 12 | Signed-off-by: Rafał Miłecki <rafal@milecki.pl> |
| 13 | Signed-off-by: Thomas Bogendoerfer <tsbogend@alpha.franken.de> |
| 14 | --- |
| 15 | drivers/firmware/broadcom/bcm47xx_nvram.c | 43 +++++++++++++---------- |
| 16 | 1 file changed, 25 insertions(+), 18 deletions(-) |
| 17 | |
| 18 | --- a/drivers/firmware/broadcom/bcm47xx_nvram.c |
| 19 | +++ b/drivers/firmware/broadcom/bcm47xx_nvram.c |
| 20 | @@ -55,11 +55,34 @@ static u32 find_nvram_size(void __iomem |
| 21 | } |
| 22 | |
| 23 | /** |
| 24 | + * bcm47xx_nvram_copy - copy NVRAM to internal buffer |
| 25 | + */ |
| 26 | +static void bcm47xx_nvram_copy(void __iomem *nvram_start, size_t res_size) |
| 27 | +{ |
| 28 | + struct nvram_header __iomem *header = nvram_start; |
| 29 | + size_t copy_size; |
| 30 | + |
| 31 | + copy_size = header->len; |
| 32 | + if (copy_size > res_size) { |
| 33 | + pr_err("The nvram size according to the header seems to be bigger than the partition on flash\n"); |
| 34 | + copy_size = res_size; |
| 35 | + } |
| 36 | + if (copy_size >= NVRAM_SPACE) { |
| 37 | + pr_err("nvram on flash (%zu bytes) is bigger than the reserved space in memory, will just copy the first %i bytes\n", |
| 38 | + copy_size, NVRAM_SPACE - 1); |
| 39 | + copy_size = NVRAM_SPACE - 1; |
| 40 | + } |
| 41 | + |
| 42 | + __ioread32_copy(nvram_buf, nvram_start, DIV_ROUND_UP(copy_size, 4)); |
| 43 | + nvram_buf[NVRAM_SPACE - 1] = '\0'; |
| 44 | + nvram_len = copy_size; |
| 45 | +} |
| 46 | + |
| 47 | +/** |
| 48 | * bcm47xx_nvram_find_and_copy - find NVRAM on flash mapping & copy it |
| 49 | */ |
| 50 | static int bcm47xx_nvram_find_and_copy(void __iomem *flash_start, size_t res_size) |
| 51 | { |
| 52 | - struct nvram_header __iomem *header; |
| 53 | size_t flash_size; |
| 54 | size_t offset; |
| 55 | u32 size; |
| 56 | @@ -95,23 +118,7 @@ static int bcm47xx_nvram_find_and_copy(v |
| 57 | return -ENXIO; |
| 58 | |
| 59 | found: |
| 60 | - header = (struct nvram_header *)(flash_start + offset); |
| 61 | - __ioread32_copy(nvram_buf, header, sizeof(*header) / 4); |
| 62 | - nvram_len = ((struct nvram_header *)(nvram_buf))->len; |
| 63 | - size = res_size - offset; |
| 64 | - if (nvram_len > size) { |
| 65 | - pr_err("The nvram size according to the header seems to be bigger than the partition on flash\n"); |
| 66 | - nvram_len = size; |
| 67 | - } |
| 68 | - if (nvram_len >= NVRAM_SPACE) { |
| 69 | - pr_err("nvram on flash (%zu bytes) is bigger than the reserved space in memory, will just copy the first %i bytes\n", |
| 70 | - nvram_len, NVRAM_SPACE - 1); |
| 71 | - nvram_len = NVRAM_SPACE - 1; |
| 72 | - } |
| 73 | - /* proceed reading data after header */ |
| 74 | - __ioread32_copy(nvram_buf + sizeof(*header), header + 1, |
| 75 | - DIV_ROUND_UP(nvram_len, 4)); |
| 76 | - nvram_buf[NVRAM_SPACE - 1] = '\0'; |
| 77 | + bcm47xx_nvram_copy(flash_start + offset, res_size - offset); |
| 78 | |
| 79 | return 0; |
| 80 | } |