forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-12-19 9370bb92b2d16684ee45cf24e879c93c509162da
kernel/arch/powerpc/platforms/powermac/nvram.c
....@@ -1,10 +1,6 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 * Copyright (C) 2002 Benjamin Herrenschmidt (benh@kernel.crashing.org)
3
- *
4
- * This program is free software; you can redistribute it and/or
5
- * modify it under the terms of the GNU General Public License
6
- * as published by the Free Software Foundation; either version
7
- * 2 of the License, or (at your option) any later version.
84 *
95 * Todo: - add support for the OF persistent properties
106 */
....@@ -18,7 +14,7 @@
1814 #include <linux/errno.h>
1915 #include <linux/adb.h>
2016 #include <linux/pmu.h>
21
-#include <linux/bootmem.h>
17
+#include <linux/memblock.h>
2218 #include <linux/completion.h>
2319 #include <linux/spinlock.h>
2420 #include <asm/sections.h>
....@@ -59,7 +55,7 @@
5955 u8 cksum;
6056 u16 len;
6157 char name[12];
62
- u8 data[0];
58
+ u8 data[];
6359 };
6460
6561 struct core99_header {
....@@ -146,6 +142,11 @@
146142 #ifdef CONFIG_PPC32
147143 static volatile unsigned char __iomem *nvram_addr;
148144 static int nvram_mult;
145
+
146
+static ssize_t ppc32_nvram_size(void)
147
+{
148
+ return NVRAM_SIZE;
149
+}
149150
150151 static unsigned char direct_nvram_read_byte(int addr)
151152 {
....@@ -513,7 +514,10 @@
513514 printk(KERN_ERR "nvram: no address\n");
514515 return -EINVAL;
515516 }
516
- nvram_image = memblock_virt_alloc(NVRAM_SIZE, 0);
517
+ nvram_image = memblock_alloc(NVRAM_SIZE, SMP_CACHE_BYTES);
518
+ if (!nvram_image)
519
+ panic("%s: Failed to allocate %u bytes\n", __func__,
520
+ NVRAM_SIZE);
517521 nvram_data = ioremap(addr, NVRAM_SIZE*2);
518522 nvram_naddrs = 1; /* Make sure we get the correct case */
519523
....@@ -590,21 +594,25 @@
590594 nvram_mult = 1;
591595 ppc_md.nvram_read_val = direct_nvram_read_byte;
592596 ppc_md.nvram_write_val = direct_nvram_write_byte;
597
+ ppc_md.nvram_size = ppc32_nvram_size;
593598 } else if (nvram_naddrs == 1) {
594599 nvram_data = ioremap(r1.start, s1);
595600 nvram_mult = (s1 + NVRAM_SIZE - 1) / NVRAM_SIZE;
596601 ppc_md.nvram_read_val = direct_nvram_read_byte;
597602 ppc_md.nvram_write_val = direct_nvram_write_byte;
603
+ ppc_md.nvram_size = ppc32_nvram_size;
598604 } else if (nvram_naddrs == 2) {
599605 nvram_addr = ioremap(r1.start, s1);
600606 nvram_data = ioremap(r2.start, s2);
601607 ppc_md.nvram_read_val = indirect_nvram_read_byte;
602608 ppc_md.nvram_write_val = indirect_nvram_write_byte;
609
+ ppc_md.nvram_size = ppc32_nvram_size;
603610 } else if (nvram_naddrs == 0 && sys_ctrler == SYS_CTRLER_PMU) {
604611 #ifdef CONFIG_ADB_PMU
605612 nvram_naddrs = -1;
606613 ppc_md.nvram_read_val = pmu_nvram_read_byte;
607614 ppc_md.nvram_write_val = pmu_nvram_write_byte;
615
+ ppc_md.nvram_size = ppc32_nvram_size;
608616 #endif /* CONFIG_ADB_PMU */
609617 } else {
610618 printk(KERN_ERR "Incompatible type of NVRAM\n");