162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */
262306a36Sopenharmony_ci/*
362306a36Sopenharmony_ci * NVRAM definitions and access functions.
462306a36Sopenharmony_ci */
562306a36Sopenharmony_ci#ifndef _ASM_POWERPC_NVRAM_H
662306a36Sopenharmony_ci#define _ASM_POWERPC_NVRAM_H
762306a36Sopenharmony_ci
862306a36Sopenharmony_ci#include <linux/types.h>
962306a36Sopenharmony_ci#include <linux/errno.h>
1062306a36Sopenharmony_ci#include <linux/list.h>
1162306a36Sopenharmony_ci#include <uapi/asm/nvram.h>
1262306a36Sopenharmony_ci
1362306a36Sopenharmony_ci/*
1462306a36Sopenharmony_ci * Set oops header version to distinguish between old and new format header.
1562306a36Sopenharmony_ci * lnx,oops-log partition max size is 4000, header version > 4000 will
1662306a36Sopenharmony_ci * help in identifying new header.
1762306a36Sopenharmony_ci */
1862306a36Sopenharmony_ci#define OOPS_HDR_VERSION 5000
1962306a36Sopenharmony_ci
2062306a36Sopenharmony_cistruct err_log_info {
2162306a36Sopenharmony_ci	__be32 error_type;
2262306a36Sopenharmony_ci	__be32 seq_num;
2362306a36Sopenharmony_ci};
2462306a36Sopenharmony_ci
2562306a36Sopenharmony_cistruct nvram_os_partition {
2662306a36Sopenharmony_ci	const char *name;
2762306a36Sopenharmony_ci	int req_size;	/* desired size, in bytes */
2862306a36Sopenharmony_ci	int min_size;	/* minimum acceptable size (0 means req_size) */
2962306a36Sopenharmony_ci	long size;	/* size of data portion (excluding err_log_info) */
3062306a36Sopenharmony_ci	long index;	/* offset of data portion of partition */
3162306a36Sopenharmony_ci	bool os_partition; /* partition initialized by OS, not FW */
3262306a36Sopenharmony_ci};
3362306a36Sopenharmony_ci
3462306a36Sopenharmony_cistruct oops_log_info {
3562306a36Sopenharmony_ci	__be16 version;
3662306a36Sopenharmony_ci	__be16 report_length;
3762306a36Sopenharmony_ci	__be64 timestamp;
3862306a36Sopenharmony_ci} __attribute__((packed));
3962306a36Sopenharmony_ci
4062306a36Sopenharmony_ciextern struct nvram_os_partition oops_log_partition;
4162306a36Sopenharmony_ci
4262306a36Sopenharmony_ci#ifdef CONFIG_PPC_PSERIES
4362306a36Sopenharmony_ciextern struct nvram_os_partition rtas_log_partition;
4462306a36Sopenharmony_ci
4562306a36Sopenharmony_ciextern int nvram_write_error_log(char * buff, int length,
4662306a36Sopenharmony_ci					 unsigned int err_type, unsigned int err_seq);
4762306a36Sopenharmony_ciextern int nvram_read_error_log(char * buff, int length,
4862306a36Sopenharmony_ci					 unsigned int * err_type, unsigned int *err_seq);
4962306a36Sopenharmony_ciextern int nvram_clear_error_log(void);
5062306a36Sopenharmony_ciextern int pSeries_nvram_init(void);
5162306a36Sopenharmony_ci#endif /* CONFIG_PPC_PSERIES */
5262306a36Sopenharmony_ci
5362306a36Sopenharmony_ci#ifdef CONFIG_MMIO_NVRAM
5462306a36Sopenharmony_ciextern int mmio_nvram_init(void);
5562306a36Sopenharmony_ci#else
5662306a36Sopenharmony_cistatic inline int mmio_nvram_init(void)
5762306a36Sopenharmony_ci{
5862306a36Sopenharmony_ci	return -ENODEV;
5962306a36Sopenharmony_ci}
6062306a36Sopenharmony_ci#endif
6162306a36Sopenharmony_ci
6262306a36Sopenharmony_ciextern int __init nvram_scan_partitions(void);
6362306a36Sopenharmony_ciextern loff_t nvram_create_partition(const char *name, int sig,
6462306a36Sopenharmony_ci				     int req_size, int min_size);
6562306a36Sopenharmony_ciextern int nvram_remove_partition(const char *name, int sig,
6662306a36Sopenharmony_ci					const char *exceptions[]);
6762306a36Sopenharmony_ciextern int nvram_get_partition_size(loff_t data_index);
6862306a36Sopenharmony_ciextern loff_t nvram_find_partition(const char *name, int sig, int *out_size);
6962306a36Sopenharmony_ci
7062306a36Sopenharmony_ci/* Return partition offset in nvram */
7162306a36Sopenharmony_ciextern int	pmac_get_partition(int partition);
7262306a36Sopenharmony_ci
7362306a36Sopenharmony_ci/* Direct access to XPRAM on PowerMacs */
7462306a36Sopenharmony_ciextern u8	pmac_xpram_read(int xpaddr);
7562306a36Sopenharmony_ciextern void	pmac_xpram_write(int xpaddr, u8 data);
7662306a36Sopenharmony_ci
7762306a36Sopenharmony_ci/* Initialize NVRAM OS partition */
7862306a36Sopenharmony_ciextern int __init nvram_init_os_partition(struct nvram_os_partition *part);
7962306a36Sopenharmony_ci
8062306a36Sopenharmony_ci/* Initialize NVRAM oops partition */
8162306a36Sopenharmony_ciextern void __init nvram_init_oops_partition(int rtas_partition_exists);
8262306a36Sopenharmony_ci
8362306a36Sopenharmony_ci/* Read a NVRAM partition */
8462306a36Sopenharmony_ciextern int nvram_read_partition(struct nvram_os_partition *part, char *buff,
8562306a36Sopenharmony_ci				int length, unsigned int *err_type,
8662306a36Sopenharmony_ci				unsigned int *error_log_cnt);
8762306a36Sopenharmony_ci
8862306a36Sopenharmony_ci/* Write to NVRAM OS partition */
8962306a36Sopenharmony_ciextern int nvram_write_os_partition(struct nvram_os_partition *part,
9062306a36Sopenharmony_ci				    char *buff, int length,
9162306a36Sopenharmony_ci				    unsigned int err_type,
9262306a36Sopenharmony_ci				    unsigned int error_log_cnt);
9362306a36Sopenharmony_ci
9462306a36Sopenharmony_ci#endif /* _ASM_POWERPC_NVRAM_H */
95