2019-05-27 06:55:01 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2005-09-26 06:04:21 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2002 Benjamin Herrenschmidt (benh@kernel.crashing.org)
|
|
|
|
*
|
|
|
|
* Todo: - add support for the OF persistent properties
|
|
|
|
*/
|
2011-07-22 22:24:23 +00:00
|
|
|
#include <linux/export.h>
|
2005-09-26 06:04:21 +00:00
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/stddef.h>
|
|
|
|
#include <linux/string.h>
|
|
|
|
#include <linux/nvram.h>
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/delay.h>
|
|
|
|
#include <linux/errno.h>
|
|
|
|
#include <linux/adb.h>
|
|
|
|
#include <linux/pmu.h>
|
2018-10-30 22:09:49 +00:00
|
|
|
#include <linux/memblock.h>
|
2005-09-26 06:04:21 +00:00
|
|
|
#include <linux/completion.h>
|
|
|
|
#include <linux/spinlock.h>
|
2022-03-08 19:20:25 +00:00
|
|
|
#include <linux/of_address.h>
|
2005-09-26 06:04:21 +00:00
|
|
|
#include <asm/sections.h>
|
|
|
|
#include <asm/io.h>
|
|
|
|
#include <asm/machdep.h>
|
|
|
|
#include <asm/nvram.h>
|
|
|
|
|
2006-07-03 11:36:01 +00:00
|
|
|
#include "pmac.h"
|
|
|
|
|
2005-09-26 06:04:21 +00:00
|
|
|
#define DEBUG
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
#define DBG(x...) printk(x)
|
|
|
|
#else
|
|
|
|
#define DBG(x...)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define NVRAM_SIZE 0x2000 /* 8kB of non-volatile RAM */
|
|
|
|
|
|
|
|
#define CORE99_SIGNATURE 0x5a
|
|
|
|
#define CORE99_ADLER_START 0x14
|
|
|
|
|
|
|
|
/* On Core99, nvram is either a sharp, a micron or an AMD flash */
|
|
|
|
#define SM_FLASH_STATUS_DONE 0x80
|
2005-10-22 06:02:39 +00:00
|
|
|
#define SM_FLASH_STATUS_ERR 0x38
|
|
|
|
|
2005-09-26 06:04:21 +00:00
|
|
|
#define SM_FLASH_CMD_ERASE_CONFIRM 0xd0
|
|
|
|
#define SM_FLASH_CMD_ERASE_SETUP 0x20
|
|
|
|
#define SM_FLASH_CMD_RESET 0xff
|
|
|
|
#define SM_FLASH_CMD_WRITE_SETUP 0x40
|
|
|
|
#define SM_FLASH_CMD_CLEAR_STATUS 0x50
|
|
|
|
#define SM_FLASH_CMD_READ_STATUS 0x70
|
|
|
|
|
|
|
|
/* CHRP NVRAM header */
|
|
|
|
struct chrp_header {
|
|
|
|
u8 signature;
|
|
|
|
u8 cksum;
|
|
|
|
u16 len;
|
|
|
|
char name[12];
|
2020-05-07 18:57:49 +00:00
|
|
|
u8 data[];
|
2005-09-26 06:04:21 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct core99_header {
|
|
|
|
struct chrp_header hdr;
|
|
|
|
u32 adler;
|
|
|
|
u32 generation;
|
|
|
|
u32 reserved[2];
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Read and write the non-volatile RAM on PowerMacs and CHRP machines.
|
|
|
|
*/
|
|
|
|
static int nvram_naddrs;
|
2006-03-23 06:38:10 +00:00
|
|
|
static volatile unsigned char __iomem *nvram_data;
|
2005-10-22 06:02:39 +00:00
|
|
|
static int is_core_99;
|
2021-12-21 03:34:23 +00:00
|
|
|
static int core99_bank;
|
2005-09-26 06:04:21 +00:00
|
|
|
static int nvram_partitions[3];
|
2005-10-22 06:02:39 +00:00
|
|
|
// XXX Turn that into a sem
|
2010-02-18 02:22:59 +00:00
|
|
|
static DEFINE_RAW_SPINLOCK(nv_lock);
|
2005-09-26 06:04:21 +00:00
|
|
|
|
|
|
|
static int (*core99_write_bank)(int bank, u8* datas);
|
|
|
|
static int (*core99_erase_bank)(int bank);
|
|
|
|
|
|
|
|
static char *nvram_image;
|
|
|
|
|
|
|
|
|
|
|
|
static unsigned char core99_nvram_read_byte(int addr)
|
|
|
|
{
|
|
|
|
if (nvram_image == NULL)
|
|
|
|
return 0xff;
|
|
|
|
return nvram_image[addr];
|
|
|
|
}
|
|
|
|
|
|
|
|
static void core99_nvram_write_byte(int addr, unsigned char val)
|
|
|
|
{
|
|
|
|
if (nvram_image == NULL)
|
|
|
|
return;
|
|
|
|
nvram_image[addr] = val;
|
|
|
|
}
|
|
|
|
|
2005-10-22 06:02:39 +00:00
|
|
|
static ssize_t core99_nvram_read(char *buf, size_t count, loff_t *index)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (nvram_image == NULL)
|
|
|
|
return -ENODEV;
|
|
|
|
if (*index > NVRAM_SIZE)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
i = *index;
|
|
|
|
if (i + count > NVRAM_SIZE)
|
|
|
|
count = NVRAM_SIZE - i;
|
|
|
|
|
|
|
|
memcpy(buf, &nvram_image[i], count);
|
|
|
|
*index = i + count;
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ssize_t core99_nvram_write(char *buf, size_t count, loff_t *index)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (nvram_image == NULL)
|
|
|
|
return -ENODEV;
|
|
|
|
if (*index > NVRAM_SIZE)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
i = *index;
|
|
|
|
if (i + count > NVRAM_SIZE)
|
|
|
|
count = NVRAM_SIZE - i;
|
|
|
|
|
|
|
|
memcpy(&nvram_image[i], buf, count);
|
|
|
|
*index = i + count;
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ssize_t core99_nvram_size(void)
|
|
|
|
{
|
|
|
|
if (nvram_image == NULL)
|
|
|
|
return -ENODEV;
|
|
|
|
return NVRAM_SIZE;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef CONFIG_PPC32
|
2006-03-23 06:38:10 +00:00
|
|
|
static volatile unsigned char __iomem *nvram_addr;
|
2005-10-22 06:02:39 +00:00
|
|
|
static int nvram_mult;
|
2005-09-26 06:04:21 +00:00
|
|
|
|
2019-01-15 04:18:56 +00:00
|
|
|
static ssize_t ppc32_nvram_size(void)
|
|
|
|
{
|
|
|
|
return NVRAM_SIZE;
|
|
|
|
}
|
|
|
|
|
2005-09-26 06:04:21 +00:00
|
|
|
static unsigned char direct_nvram_read_byte(int addr)
|
|
|
|
{
|
|
|
|
return in_8(&nvram_data[(addr & (NVRAM_SIZE - 1)) * nvram_mult]);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void direct_nvram_write_byte(int addr, unsigned char val)
|
|
|
|
{
|
|
|
|
out_8(&nvram_data[(addr & (NVRAM_SIZE - 1)) * nvram_mult], val);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static unsigned char indirect_nvram_read_byte(int addr)
|
|
|
|
{
|
|
|
|
unsigned char val;
|
|
|
|
unsigned long flags;
|
|
|
|
|
2010-02-18 02:22:59 +00:00
|
|
|
raw_spin_lock_irqsave(&nv_lock, flags);
|
2005-09-26 06:04:21 +00:00
|
|
|
out_8(nvram_addr, addr >> 5);
|
|
|
|
val = in_8(&nvram_data[(addr & 0x1f) << 4]);
|
2010-02-18 02:22:59 +00:00
|
|
|
raw_spin_unlock_irqrestore(&nv_lock, flags);
|
2005-09-26 06:04:21 +00:00
|
|
|
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void indirect_nvram_write_byte(int addr, unsigned char val)
|
|
|
|
{
|
|
|
|
unsigned long flags;
|
|
|
|
|
2010-02-18 02:22:59 +00:00
|
|
|
raw_spin_lock_irqsave(&nv_lock, flags);
|
2005-09-26 06:04:21 +00:00
|
|
|
out_8(nvram_addr, addr >> 5);
|
|
|
|
out_8(&nvram_data[(addr & 0x1f) << 4], val);
|
2010-02-18 02:22:59 +00:00
|
|
|
raw_spin_unlock_irqrestore(&nv_lock, flags);
|
2005-09-26 06:04:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef CONFIG_ADB_PMU
|
|
|
|
|
|
|
|
static void pmu_nvram_complete(struct adb_request *req)
|
|
|
|
{
|
|
|
|
if (req->arg)
|
|
|
|
complete((struct completion *)req->arg);
|
|
|
|
}
|
|
|
|
|
|
|
|
static unsigned char pmu_nvram_read_byte(int addr)
|
|
|
|
{
|
|
|
|
struct adb_request req;
|
2006-10-01 06:28:10 +00:00
|
|
|
DECLARE_COMPLETION_ONSTACK(req_complete);
|
2005-09-26 06:04:21 +00:00
|
|
|
|
|
|
|
req.arg = system_state == SYSTEM_RUNNING ? &req_complete : NULL;
|
|
|
|
if (pmu_request(&req, pmu_nvram_complete, 3, PMU_READ_NVRAM,
|
|
|
|
(addr >> 8) & 0xff, addr & 0xff))
|
|
|
|
return 0xff;
|
|
|
|
if (system_state == SYSTEM_RUNNING)
|
|
|
|
wait_for_completion(&req_complete);
|
|
|
|
while (!req.complete)
|
|
|
|
pmu_poll();
|
|
|
|
return req.reply[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
static void pmu_nvram_write_byte(int addr, unsigned char val)
|
|
|
|
{
|
|
|
|
struct adb_request req;
|
2006-10-01 06:28:10 +00:00
|
|
|
DECLARE_COMPLETION_ONSTACK(req_complete);
|
2005-09-26 06:04:21 +00:00
|
|
|
|
|
|
|
req.arg = system_state == SYSTEM_RUNNING ? &req_complete : NULL;
|
|
|
|
if (pmu_request(&req, pmu_nvram_complete, 4, PMU_WRITE_NVRAM,
|
|
|
|
(addr >> 8) & 0xff, addr & 0xff, val))
|
|
|
|
return;
|
|
|
|
if (system_state == SYSTEM_RUNNING)
|
|
|
|
wait_for_completion(&req_complete);
|
|
|
|
while (!req.complete)
|
|
|
|
pmu_poll();
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* CONFIG_ADB_PMU */
|
2005-10-22 06:02:39 +00:00
|
|
|
#endif /* CONFIG_PPC32 */
|
2005-09-26 06:04:21 +00:00
|
|
|
|
|
|
|
static u8 chrp_checksum(struct chrp_header* hdr)
|
|
|
|
{
|
|
|
|
u8 *ptr;
|
|
|
|
u16 sum = hdr->signature;
|
|
|
|
for (ptr = (u8 *)&hdr->len; ptr < hdr->data; ptr++)
|
|
|
|
sum += *ptr;
|
|
|
|
while (sum > 0xFF)
|
|
|
|
sum = (sum & 0xFF) + (sum>>8);
|
|
|
|
return sum;
|
|
|
|
}
|
|
|
|
|
|
|
|
static u32 core99_calc_adler(u8 *buffer)
|
|
|
|
{
|
|
|
|
int cnt;
|
|
|
|
u32 low, high;
|
|
|
|
|
|
|
|
buffer += CORE99_ADLER_START;
|
|
|
|
low = 1;
|
|
|
|
high = 0;
|
|
|
|
for (cnt=0; cnt<(NVRAM_SIZE-CORE99_ADLER_START); cnt++) {
|
|
|
|
if ((cnt % 5000) == 0) {
|
|
|
|
high %= 65521UL;
|
|
|
|
high %= 65521UL;
|
|
|
|
}
|
|
|
|
low += buffer[cnt];
|
|
|
|
high += low;
|
|
|
|
}
|
|
|
|
low %= 65521UL;
|
|
|
|
high %= 65521UL;
|
|
|
|
|
|
|
|
return (high << 16) | low;
|
|
|
|
}
|
|
|
|
|
2021-12-16 22:00:25 +00:00
|
|
|
static u32 __init core99_check(u8 *datas)
|
2005-09-26 06:04:21 +00:00
|
|
|
{
|
|
|
|
struct core99_header* hdr99 = (struct core99_header*)datas;
|
|
|
|
|
|
|
|
if (hdr99->hdr.signature != CORE99_SIGNATURE) {
|
|
|
|
DBG("Invalid signature\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (hdr99->hdr.cksum != chrp_checksum(&hdr99->hdr)) {
|
|
|
|
DBG("Invalid checksum\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (hdr99->adler != core99_calc_adler(datas)) {
|
|
|
|
DBG("Invalid adler\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return hdr99->generation;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int sm_erase_bank(int bank)
|
|
|
|
{
|
2012-01-27 04:24:48 +00:00
|
|
|
int stat;
|
2005-09-26 06:04:21 +00:00
|
|
|
unsigned long timeout;
|
|
|
|
|
2006-03-23 06:38:10 +00:00
|
|
|
u8 __iomem *base = (u8 __iomem *)nvram_data + core99_bank*NVRAM_SIZE;
|
2005-09-26 06:04:21 +00:00
|
|
|
|
|
|
|
DBG("nvram: Sharp/Micron Erasing bank %d...\n", bank);
|
|
|
|
|
|
|
|
out_8(base, SM_FLASH_CMD_ERASE_SETUP);
|
|
|
|
out_8(base, SM_FLASH_CMD_ERASE_CONFIRM);
|
|
|
|
timeout = 0;
|
|
|
|
do {
|
|
|
|
if (++timeout > 1000000) {
|
2005-10-22 06:02:39 +00:00
|
|
|
printk(KERN_ERR "nvram: Sharp/Micron flash erase timeout !\n");
|
2005-09-26 06:04:21 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
out_8(base, SM_FLASH_CMD_READ_STATUS);
|
|
|
|
stat = in_8(base);
|
|
|
|
} while (!(stat & SM_FLASH_STATUS_DONE));
|
|
|
|
|
|
|
|
out_8(base, SM_FLASH_CMD_CLEAR_STATUS);
|
|
|
|
out_8(base, SM_FLASH_CMD_RESET);
|
|
|
|
|
2012-01-27 04:24:48 +00:00
|
|
|
if (memchr_inv(base, 0xff, NVRAM_SIZE)) {
|
|
|
|
printk(KERN_ERR "nvram: Sharp/Micron flash erase failed !\n");
|
|
|
|
return -ENXIO;
|
|
|
|
}
|
2005-09-26 06:04:21 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int sm_write_bank(int bank, u8* datas)
|
|
|
|
{
|
|
|
|
int i, stat = 0;
|
|
|
|
unsigned long timeout;
|
|
|
|
|
2006-03-23 06:38:10 +00:00
|
|
|
u8 __iomem *base = (u8 __iomem *)nvram_data + core99_bank*NVRAM_SIZE;
|
2005-09-26 06:04:21 +00:00
|
|
|
|
|
|
|
DBG("nvram: Sharp/Micron Writing bank %d...\n", bank);
|
|
|
|
|
|
|
|
for (i=0; i<NVRAM_SIZE; i++) {
|
|
|
|
out_8(base+i, SM_FLASH_CMD_WRITE_SETUP);
|
|
|
|
udelay(1);
|
|
|
|
out_8(base+i, datas[i]);
|
|
|
|
timeout = 0;
|
|
|
|
do {
|
|
|
|
if (++timeout > 1000000) {
|
|
|
|
printk(KERN_ERR "nvram: Sharp/Micron flash write timeout !\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
out_8(base, SM_FLASH_CMD_READ_STATUS);
|
|
|
|
stat = in_8(base);
|
|
|
|
} while (!(stat & SM_FLASH_STATUS_DONE));
|
|
|
|
if (!(stat & SM_FLASH_STATUS_DONE))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
out_8(base, SM_FLASH_CMD_CLEAR_STATUS);
|
|
|
|
out_8(base, SM_FLASH_CMD_RESET);
|
2012-01-27 04:24:48 +00:00
|
|
|
if (memcmp(base, datas, NVRAM_SIZE)) {
|
|
|
|
printk(KERN_ERR "nvram: Sharp/Micron flash write failed !\n");
|
|
|
|
return -ENXIO;
|
|
|
|
}
|
2005-09-26 06:04:21 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int amd_erase_bank(int bank)
|
|
|
|
{
|
2012-01-27 04:24:48 +00:00
|
|
|
int stat = 0;
|
2005-09-26 06:04:21 +00:00
|
|
|
unsigned long timeout;
|
|
|
|
|
2006-03-23 06:38:10 +00:00
|
|
|
u8 __iomem *base = (u8 __iomem *)nvram_data + core99_bank*NVRAM_SIZE;
|
2005-09-26 06:04:21 +00:00
|
|
|
|
|
|
|
DBG("nvram: AMD Erasing bank %d...\n", bank);
|
|
|
|
|
|
|
|
/* Unlock 1 */
|
|
|
|
out_8(base+0x555, 0xaa);
|
|
|
|
udelay(1);
|
|
|
|
/* Unlock 2 */
|
|
|
|
out_8(base+0x2aa, 0x55);
|
|
|
|
udelay(1);
|
|
|
|
|
|
|
|
/* Sector-Erase */
|
|
|
|
out_8(base+0x555, 0x80);
|
|
|
|
udelay(1);
|
|
|
|
out_8(base+0x555, 0xaa);
|
|
|
|
udelay(1);
|
|
|
|
out_8(base+0x2aa, 0x55);
|
|
|
|
udelay(1);
|
|
|
|
out_8(base, 0x30);
|
|
|
|
udelay(1);
|
|
|
|
|
|
|
|
timeout = 0;
|
|
|
|
do {
|
|
|
|
if (++timeout > 1000000) {
|
|
|
|
printk(KERN_ERR "nvram: AMD flash erase timeout !\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
stat = in_8(base) ^ in_8(base);
|
|
|
|
} while (stat != 0);
|
|
|
|
|
|
|
|
/* Reset */
|
|
|
|
out_8(base, 0xf0);
|
|
|
|
udelay(1);
|
2012-01-27 04:24:48 +00:00
|
|
|
|
|
|
|
if (memchr_inv(base, 0xff, NVRAM_SIZE)) {
|
|
|
|
printk(KERN_ERR "nvram: AMD flash erase failed !\n");
|
|
|
|
return -ENXIO;
|
|
|
|
}
|
2005-09-26 06:04:21 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int amd_write_bank(int bank, u8* datas)
|
|
|
|
{
|
|
|
|
int i, stat = 0;
|
|
|
|
unsigned long timeout;
|
|
|
|
|
2006-03-23 06:38:10 +00:00
|
|
|
u8 __iomem *base = (u8 __iomem *)nvram_data + core99_bank*NVRAM_SIZE;
|
2005-09-26 06:04:21 +00:00
|
|
|
|
|
|
|
DBG("nvram: AMD Writing bank %d...\n", bank);
|
|
|
|
|
|
|
|
for (i=0; i<NVRAM_SIZE; i++) {
|
|
|
|
/* Unlock 1 */
|
|
|
|
out_8(base+0x555, 0xaa);
|
|
|
|
udelay(1);
|
|
|
|
/* Unlock 2 */
|
|
|
|
out_8(base+0x2aa, 0x55);
|
|
|
|
udelay(1);
|
|
|
|
|
|
|
|
/* Write single word */
|
|
|
|
out_8(base+0x555, 0xa0);
|
|
|
|
udelay(1);
|
|
|
|
out_8(base+i, datas[i]);
|
|
|
|
|
|
|
|
timeout = 0;
|
|
|
|
do {
|
|
|
|
if (++timeout > 1000000) {
|
|
|
|
printk(KERN_ERR "nvram: AMD flash write timeout !\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
stat = in_8(base) ^ in_8(base);
|
|
|
|
} while (stat != 0);
|
|
|
|
if (stat != 0)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Reset */
|
|
|
|
out_8(base, 0xf0);
|
|
|
|
udelay(1);
|
|
|
|
|
2012-01-27 04:24:48 +00:00
|
|
|
if (memcmp(base, datas, NVRAM_SIZE)) {
|
|
|
|
printk(KERN_ERR "nvram: AMD flash write failed !\n");
|
|
|
|
return -ENXIO;
|
|
|
|
}
|
2005-09-26 06:04:21 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void __init lookup_partitions(void)
|
|
|
|
{
|
|
|
|
u8 buffer[17];
|
|
|
|
int i, offset;
|
|
|
|
struct chrp_header* hdr;
|
|
|
|
|
|
|
|
if (pmac_newworld) {
|
|
|
|
nvram_partitions[pmac_nvram_OF] = -1;
|
|
|
|
nvram_partitions[pmac_nvram_XPRAM] = -1;
|
|
|
|
nvram_partitions[pmac_nvram_NR] = -1;
|
|
|
|
hdr = (struct chrp_header *)buffer;
|
|
|
|
|
|
|
|
offset = 0;
|
|
|
|
buffer[16] = 0;
|
|
|
|
do {
|
|
|
|
for (i=0;i<16;i++)
|
2005-10-22 06:02:39 +00:00
|
|
|
buffer[i] = ppc_md.nvram_read_val(offset+i);
|
2005-09-26 06:04:21 +00:00
|
|
|
if (!strcmp(hdr->name, "common"))
|
|
|
|
nvram_partitions[pmac_nvram_OF] = offset + 0x10;
|
|
|
|
if (!strcmp(hdr->name, "APL,MacOS75")) {
|
|
|
|
nvram_partitions[pmac_nvram_XPRAM] = offset + 0x10;
|
|
|
|
nvram_partitions[pmac_nvram_NR] = offset + 0x110;
|
|
|
|
}
|
|
|
|
offset += (hdr->len * 0x10);
|
|
|
|
} while(offset < NVRAM_SIZE);
|
|
|
|
} else {
|
|
|
|
nvram_partitions[pmac_nvram_OF] = 0x1800;
|
|
|
|
nvram_partitions[pmac_nvram_XPRAM] = 0x1300;
|
|
|
|
nvram_partitions[pmac_nvram_NR] = 0x1400;
|
|
|
|
}
|
|
|
|
DBG("nvram: OF partition at 0x%x\n", nvram_partitions[pmac_nvram_OF]);
|
|
|
|
DBG("nvram: XP partition at 0x%x\n", nvram_partitions[pmac_nvram_XPRAM]);
|
|
|
|
DBG("nvram: NR partition at 0x%x\n", nvram_partitions[pmac_nvram_NR]);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void core99_nvram_sync(void)
|
|
|
|
{
|
|
|
|
struct core99_header* hdr99;
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
if (!is_core_99 || !nvram_data || !nvram_image)
|
|
|
|
return;
|
|
|
|
|
2010-02-18 02:22:59 +00:00
|
|
|
raw_spin_lock_irqsave(&nv_lock, flags);
|
2005-09-26 06:04:21 +00:00
|
|
|
if (!memcmp(nvram_image, (u8*)nvram_data + core99_bank*NVRAM_SIZE,
|
|
|
|
NVRAM_SIZE))
|
|
|
|
goto bail;
|
|
|
|
|
|
|
|
DBG("Updating nvram...\n");
|
|
|
|
|
|
|
|
hdr99 = (struct core99_header*)nvram_image;
|
|
|
|
hdr99->generation++;
|
|
|
|
hdr99->hdr.signature = CORE99_SIGNATURE;
|
|
|
|
hdr99->hdr.cksum = chrp_checksum(&hdr99->hdr);
|
|
|
|
hdr99->adler = core99_calc_adler(nvram_image);
|
|
|
|
core99_bank = core99_bank ? 0 : 1;
|
|
|
|
if (core99_erase_bank)
|
|
|
|
if (core99_erase_bank(core99_bank)) {
|
|
|
|
printk("nvram: Error erasing bank %d\n", core99_bank);
|
|
|
|
goto bail;
|
|
|
|
}
|
|
|
|
if (core99_write_bank)
|
|
|
|
if (core99_write_bank(core99_bank, nvram_image))
|
|
|
|
printk("nvram: Error writing bank %d\n", core99_bank);
|
|
|
|
bail:
|
2010-02-18 02:22:59 +00:00
|
|
|
raw_spin_unlock_irqrestore(&nv_lock, flags);
|
2005-09-26 06:04:21 +00:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
mdelay(2000);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2005-12-13 07:01:21 +00:00
|
|
|
static int __init core99_nvram_setup(struct device_node *dp, unsigned long addr)
|
2005-10-22 06:02:39 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
u32 gen_bank0, gen_bank1;
|
|
|
|
|
|
|
|
if (nvram_naddrs < 1) {
|
|
|
|
printk(KERN_ERR "nvram: no address\n");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
memblock: stop using implicit alignment to SMP_CACHE_BYTES
When a memblock allocation APIs are called with align = 0, the alignment
is implicitly set to SMP_CACHE_BYTES.
Implicit alignment is done deep in the memblock allocator and it can
come as a surprise. Not that such an alignment would be wrong even
when used incorrectly but it is better to be explicit for the sake of
clarity and the prinicple of the least surprise.
Replace all such uses of memblock APIs with the 'align' parameter
explicitly set to SMP_CACHE_BYTES and stop implicit alignment assignment
in the memblock internal allocation functions.
For the case when memblock APIs are used via helper functions, e.g. like
iommu_arena_new_node() in Alpha, the helper functions were detected with
Coccinelle's help and then manually examined and updated where
appropriate.
The direct memblock APIs users were updated using the semantic patch below:
@@
expression size, min_addr, max_addr, nid;
@@
(
|
- memblock_alloc_try_nid_raw(size, 0, min_addr, max_addr, nid)
+ memblock_alloc_try_nid_raw(size, SMP_CACHE_BYTES, min_addr, max_addr,
nid)
|
- memblock_alloc_try_nid_nopanic(size, 0, min_addr, max_addr, nid)
+ memblock_alloc_try_nid_nopanic(size, SMP_CACHE_BYTES, min_addr, max_addr,
nid)
|
- memblock_alloc_try_nid(size, 0, min_addr, max_addr, nid)
+ memblock_alloc_try_nid(size, SMP_CACHE_BYTES, min_addr, max_addr, nid)
|
- memblock_alloc(size, 0)
+ memblock_alloc(size, SMP_CACHE_BYTES)
|
- memblock_alloc_raw(size, 0)
+ memblock_alloc_raw(size, SMP_CACHE_BYTES)
|
- memblock_alloc_from(size, 0, min_addr)
+ memblock_alloc_from(size, SMP_CACHE_BYTES, min_addr)
|
- memblock_alloc_nopanic(size, 0)
+ memblock_alloc_nopanic(size, SMP_CACHE_BYTES)
|
- memblock_alloc_low(size, 0)
+ memblock_alloc_low(size, SMP_CACHE_BYTES)
|
- memblock_alloc_low_nopanic(size, 0)
+ memblock_alloc_low_nopanic(size, SMP_CACHE_BYTES)
|
- memblock_alloc_from_nopanic(size, 0, min_addr)
+ memblock_alloc_from_nopanic(size, SMP_CACHE_BYTES, min_addr)
|
- memblock_alloc_node(size, 0, nid)
+ memblock_alloc_node(size, SMP_CACHE_BYTES, nid)
)
[mhocko@suse.com: changelog update]
[akpm@linux-foundation.org: coding-style fixes]
[rppt@linux.ibm.com: fix missed uses of implicit alignment]
Link: http://lkml.kernel.org/r/20181016133656.GA10925@rapoport-lnx
Link: http://lkml.kernel.org/r/1538687224-17535-1-git-send-email-rppt@linux.vnet.ibm.com
Signed-off-by: Mike Rapoport <rppt@linux.vnet.ibm.com>
Suggested-by: Michal Hocko <mhocko@suse.com>
Acked-by: Paul Burton <paul.burton@mips.com> [MIPS]
Acked-by: Michael Ellerman <mpe@ellerman.id.au> [powerpc]
Acked-by: Michal Hocko <mhocko@suse.com>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Chris Zankel <chris@zankel.net>
Cc: Geert Uytterhoeven <geert@linux-m68k.org>
Cc: Guan Xuetao <gxt@pku.edu.cn>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Matt Turner <mattst88@gmail.com>
Cc: Michal Simek <monstr@monstr.eu>
Cc: Richard Weinberger <richard@nod.at>
Cc: Russell King <linux@armlinux.org.uk>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Tony Luck <tony.luck@intel.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2018-10-30 22:09:57 +00:00
|
|
|
nvram_image = memblock_alloc(NVRAM_SIZE, SMP_CACHE_BYTES);
|
2019-03-12 06:30:31 +00:00
|
|
|
if (!nvram_image)
|
|
|
|
panic("%s: Failed to allocate %u bytes\n", __func__,
|
|
|
|
NVRAM_SIZE);
|
2005-12-13 07:01:21 +00:00
|
|
|
nvram_data = ioremap(addr, NVRAM_SIZE*2);
|
2005-10-22 06:02:39 +00:00
|
|
|
nvram_naddrs = 1; /* Make sure we get the correct case */
|
|
|
|
|
|
|
|
DBG("nvram: Checking bank 0...\n");
|
|
|
|
|
|
|
|
gen_bank0 = core99_check((u8 *)nvram_data);
|
|
|
|
gen_bank1 = core99_check((u8 *)nvram_data + NVRAM_SIZE);
|
|
|
|
core99_bank = (gen_bank0 < gen_bank1) ? 1 : 0;
|
|
|
|
|
|
|
|
DBG("nvram: gen0=%d, gen1=%d\n", gen_bank0, gen_bank1);
|
|
|
|
DBG("nvram: Active bank is: %d\n", core99_bank);
|
|
|
|
|
|
|
|
for (i=0; i<NVRAM_SIZE; i++)
|
|
|
|
nvram_image[i] = nvram_data[i + core99_bank*NVRAM_SIZE];
|
|
|
|
|
|
|
|
ppc_md.nvram_read_val = core99_nvram_read_byte;
|
|
|
|
ppc_md.nvram_write_val = core99_nvram_write_byte;
|
|
|
|
ppc_md.nvram_read = core99_nvram_read;
|
|
|
|
ppc_md.nvram_write = core99_nvram_write;
|
|
|
|
ppc_md.nvram_size = core99_nvram_size;
|
|
|
|
ppc_md.nvram_sync = core99_nvram_sync;
|
[PATCH] powerpc: Merge kexec
This patch merges, to some extent, the PPC32 and PPC64 kexec implementations.
We adopt the PPC32 approach of having ppc_md callbacks for the kexec functions.
The current PPC64 implementation becomes the "default" implementation for PPC64
which platforms can select if they need no special treatment.
I've added these default callbacks to pseries/maple/cell/powermac, this means
iSeries no longer supports kexec - but it never worked anyway.
I've renamed PPC32's machine_kexec_simple to default_machine_kexec, inline with
PPC64. Judging by the comments it might be better named machine_kexec_non_of,
or something, but at the moment it's the only implementation for PPC32 so it's
the "default".
Kexec requires machine_shutdown(), which is in machine_kexec.c on PPC32, but we
already have in setup-common.c on powerpc. All this does is call
ppc_md.nvram_sync, which only powermac implements, so instead make
machine_shutdown a ppc_md member and have it call core99_nvram_sync directly
on powermac.
I've also stuck relocate_kernel.S into misc_32.S for powerpc.
Built for ARCH=ppc, and 32 & 64 bit ARCH=powerpc, with KEXEC=y/n. Booted on
P5 LPAR and successfully kexec'ed.
Should apply on top of 493f25ef4087395891c99fcfe2c72e62e293e89f.
Signed-off-by: Michael Ellerman <michael@ellerman.id.au>
Signed-off-by: Paul Mackerras <paulus@samba.org>
2005-11-14 12:35:00 +00:00
|
|
|
ppc_md.machine_shutdown = core99_nvram_sync;
|
2005-10-22 06:02:39 +00:00
|
|
|
/*
|
|
|
|
* Maybe we could be smarter here though making an exclusive list
|
|
|
|
* of known flash chips is a bit nasty as older OF didn't provide us
|
|
|
|
* with a useful "compatible" entry. A solution would be to really
|
|
|
|
* identify the chip using flash id commands and base ourselves on
|
|
|
|
* a list of known chips IDs
|
|
|
|
*/
|
2007-05-03 07:26:52 +00:00
|
|
|
if (of_device_is_compatible(dp, "amd-0137")) {
|
2005-10-22 06:02:39 +00:00
|
|
|
core99_erase_bank = amd_erase_bank;
|
|
|
|
core99_write_bank = amd_write_bank;
|
|
|
|
} else {
|
|
|
|
core99_erase_bank = sm_erase_bank;
|
|
|
|
core99_write_bank = sm_write_bank;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int __init pmac_nvram_init(void)
|
2005-09-26 06:04:21 +00:00
|
|
|
{
|
|
|
|
struct device_node *dp;
|
2005-12-13 07:01:21 +00:00
|
|
|
struct resource r1, r2;
|
|
|
|
unsigned int s1 = 0, s2 = 0;
|
2005-10-22 06:02:39 +00:00
|
|
|
int err = 0;
|
2005-09-26 06:04:21 +00:00
|
|
|
|
|
|
|
nvram_naddrs = 0;
|
|
|
|
|
2005-12-13 07:01:21 +00:00
|
|
|
dp = of_find_node_by_name(NULL, "nvram");
|
2005-09-26 06:04:21 +00:00
|
|
|
if (dp == NULL) {
|
|
|
|
printk(KERN_ERR "Can't find NVRAM device\n");
|
2005-10-22 06:02:39 +00:00
|
|
|
return -ENODEV;
|
2005-09-26 06:04:21 +00:00
|
|
|
}
|
2005-12-13 07:01:21 +00:00
|
|
|
|
|
|
|
/* Try to obtain an address */
|
|
|
|
if (of_address_to_resource(dp, 0, &r1) == 0) {
|
|
|
|
nvram_naddrs = 1;
|
2011-06-09 16:13:32 +00:00
|
|
|
s1 = resource_size(&r1);
|
2005-12-13 07:01:21 +00:00
|
|
|
if (of_address_to_resource(dp, 1, &r2) == 0) {
|
|
|
|
nvram_naddrs = 2;
|
2011-06-09 16:13:32 +00:00
|
|
|
s2 = resource_size(&r2);
|
2005-12-13 07:01:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-05-03 07:26:52 +00:00
|
|
|
is_core_99 = of_device_is_compatible(dp, "nvram,flash");
|
2005-12-13 07:01:21 +00:00
|
|
|
if (is_core_99) {
|
|
|
|
err = core99_nvram_setup(dp, r1.start);
|
|
|
|
goto bail;
|
|
|
|
}
|
|
|
|
|
2005-10-22 06:02:39 +00:00
|
|
|
#ifdef CONFIG_PPC32
|
2006-03-28 12:15:54 +00:00
|
|
|
if (machine_is(chrp) && nvram_naddrs == 1) {
|
2005-12-13 07:01:21 +00:00
|
|
|
nvram_data = ioremap(r1.start, s1);
|
2005-09-26 06:04:21 +00:00
|
|
|
nvram_mult = 1;
|
|
|
|
ppc_md.nvram_read_val = direct_nvram_read_byte;
|
|
|
|
ppc_md.nvram_write_val = direct_nvram_write_byte;
|
2019-01-15 04:18:56 +00:00
|
|
|
ppc_md.nvram_size = ppc32_nvram_size;
|
2005-09-26 06:04:21 +00:00
|
|
|
} else if (nvram_naddrs == 1) {
|
2005-12-13 07:01:21 +00:00
|
|
|
nvram_data = ioremap(r1.start, s1);
|
|
|
|
nvram_mult = (s1 + NVRAM_SIZE - 1) / NVRAM_SIZE;
|
2005-09-26 06:04:21 +00:00
|
|
|
ppc_md.nvram_read_val = direct_nvram_read_byte;
|
|
|
|
ppc_md.nvram_write_val = direct_nvram_write_byte;
|
2019-01-15 04:18:56 +00:00
|
|
|
ppc_md.nvram_size = ppc32_nvram_size;
|
2005-09-26 06:04:21 +00:00
|
|
|
} else if (nvram_naddrs == 2) {
|
2005-12-13 07:01:21 +00:00
|
|
|
nvram_addr = ioremap(r1.start, s1);
|
|
|
|
nvram_data = ioremap(r2.start, s2);
|
2005-09-26 06:04:21 +00:00
|
|
|
ppc_md.nvram_read_val = indirect_nvram_read_byte;
|
|
|
|
ppc_md.nvram_write_val = indirect_nvram_write_byte;
|
2019-01-15 04:18:56 +00:00
|
|
|
ppc_md.nvram_size = ppc32_nvram_size;
|
2005-09-26 06:04:21 +00:00
|
|
|
} else if (nvram_naddrs == 0 && sys_ctrler == SYS_CTRLER_PMU) {
|
|
|
|
#ifdef CONFIG_ADB_PMU
|
|
|
|
nvram_naddrs = -1;
|
|
|
|
ppc_md.nvram_read_val = pmu_nvram_read_byte;
|
|
|
|
ppc_md.nvram_write_val = pmu_nvram_write_byte;
|
2019-01-15 04:18:56 +00:00
|
|
|
ppc_md.nvram_size = ppc32_nvram_size;
|
2005-09-26 06:04:21 +00:00
|
|
|
#endif /* CONFIG_ADB_PMU */
|
2005-12-13 07:01:21 +00:00
|
|
|
} else {
|
2005-10-22 06:02:39 +00:00
|
|
|
printk(KERN_ERR "Incompatible type of NVRAM\n");
|
2005-12-13 07:01:21 +00:00
|
|
|
err = -ENXIO;
|
2005-09-26 06:04:21 +00:00
|
|
|
}
|
2005-12-13 07:01:21 +00:00
|
|
|
#endif /* CONFIG_PPC32 */
|
|
|
|
bail:
|
|
|
|
of_node_put(dp);
|
|
|
|
if (err == 0)
|
|
|
|
lookup_partitions();
|
2005-10-22 06:02:39 +00:00
|
|
|
return err;
|
2005-09-26 06:04:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int pmac_get_partition(int partition)
|
|
|
|
{
|
|
|
|
return nvram_partitions[partition];
|
|
|
|
}
|
|
|
|
|
|
|
|
u8 pmac_xpram_read(int xpaddr)
|
|
|
|
{
|
2005-10-22 06:02:39 +00:00
|
|
|
int offset = pmac_get_partition(pmac_nvram_XPRAM);
|
2005-09-26 06:04:21 +00:00
|
|
|
|
2005-10-22 06:02:39 +00:00
|
|
|
if (offset < 0 || xpaddr < 0 || xpaddr > 0x100)
|
2005-09-26 06:04:21 +00:00
|
|
|
return 0xff;
|
|
|
|
|
|
|
|
return ppc_md.nvram_read_val(xpaddr + offset);
|
|
|
|
}
|
|
|
|
|
|
|
|
void pmac_xpram_write(int xpaddr, u8 data)
|
|
|
|
{
|
2005-10-22 06:02:39 +00:00
|
|
|
int offset = pmac_get_partition(pmac_nvram_XPRAM);
|
2005-09-26 06:04:21 +00:00
|
|
|
|
2005-10-22 06:02:39 +00:00
|
|
|
if (offset < 0 || xpaddr < 0 || xpaddr > 0x100)
|
2005-09-26 06:04:21 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
ppc_md.nvram_write_val(xpaddr + offset, data);
|
|
|
|
}
|
|
|
|
|
|
|
|
EXPORT_SYMBOL(pmac_get_partition);
|
|
|
|
EXPORT_SYMBOL(pmac_xpram_read);
|
|
|
|
EXPORT_SYMBOL(pmac_xpram_write);
|