Linux Audio

Check our new training course

Loading...
v6.8
  1// SPDX-License-Identifier: GPL-2.0
  2/*
  3 * OS info memory interface
  4 *
  5 * Copyright IBM Corp. 2012
  6 * Author(s): Michael Holzheu <holzheu@linux.vnet.ibm.com>
  7 */
  8
  9#define KMSG_COMPONENT "os_info"
 10#define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
 11
 12#include <linux/crash_dump.h>
 13#include <linux/kernel.h>
 14#include <linux/slab.h>
 15#include <asm/checksum.h>
 16#include <asm/abs_lowcore.h>
 17#include <asm/os_info.h>
 18#include <asm/maccess.h>
 19#include <asm/asm-offsets.h>
 20
 21/*
 22 * OS info structure has to be page aligned
 23 */
 24static struct os_info os_info __page_aligned_data;
 25
 26/*
 27 * Compute checksum over OS info structure
 28 */
 29u32 os_info_csum(struct os_info *os_info)
 30{
 31	int size = sizeof(*os_info) - offsetof(struct os_info, version_major);
 32	return (__force u32)csum_partial(&os_info->version_major, size, 0);
 33}
 34
 35/*
 36 * Add crashkernel info to OS info and update checksum
 37 */
 38void os_info_crashkernel_add(unsigned long base, unsigned long size)
 39{
 40	os_info.crashkernel_addr = (u64)(unsigned long)base;
 41	os_info.crashkernel_size = (u64)(unsigned long)size;
 42	os_info.csum = os_info_csum(&os_info);
 43}
 44
 45/*
 46 * Add OS info entry and update checksum
 47 */
 48void os_info_entry_add(int nr, void *ptr, u64 size)
 49{
 50	os_info.entry[nr].addr = __pa(ptr);
 51	os_info.entry[nr].size = size;
 52	os_info.entry[nr].csum = (__force u32)csum_partial(ptr, size, 0);
 53	os_info.csum = os_info_csum(&os_info);
 54}
 55
 56/*
 57 * Initialize OS info structure and set lowcore pointer
 58 */
 59void __init os_info_init(void)
 60{
 61	struct lowcore *abs_lc;
 62
 63	os_info.version_major = OS_INFO_VERSION_MAJOR;
 64	os_info.version_minor = OS_INFO_VERSION_MINOR;
 65	os_info.magic = OS_INFO_MAGIC;
 66	os_info.csum = os_info_csum(&os_info);
 67	abs_lc = get_abs_lowcore();
 68	abs_lc->os_info = __pa(&os_info);
 69	put_abs_lowcore(abs_lc);
 70}
 71
 72#ifdef CONFIG_CRASH_DUMP
 73
 74static struct os_info *os_info_old;
 75
 76/*
 77 * Allocate and copy OS info entry from oldmem
 78 */
 79static void os_info_old_alloc(int nr, int align)
 80{
 81	unsigned long addr, size = 0;
 82	char *buf, *buf_align, *msg;
 83	u32 csum;
 84
 85	addr = os_info_old->entry[nr].addr;
 86	if (!addr) {
 87		msg = "not available";
 88		goto fail;
 89	}
 90	size = os_info_old->entry[nr].size;
 91	buf = kmalloc(size + align - 1, GFP_KERNEL);
 92	if (!buf) {
 93		msg = "alloc failed";
 94		goto fail;
 95	}
 96	buf_align = PTR_ALIGN(buf, align);
 97	if (copy_oldmem_kernel(buf_align, addr, size)) {
 98		msg = "copy failed";
 99		goto fail_free;
100	}
101	csum = (__force u32)csum_partial(buf_align, size, 0);
102	if (csum != os_info_old->entry[nr].csum) {
103		msg = "checksum failed";
104		goto fail_free;
105	}
106	os_info_old->entry[nr].addr = (u64)(unsigned long)buf_align;
107	msg = "copied";
108	goto out;
109fail_free:
110	kfree(buf);
111fail:
112	os_info_old->entry[nr].addr = 0;
113out:
114	pr_info("entry %i: %s (addr=0x%lx size=%lu)\n",
115		nr, msg, addr, size);
116}
117
118/*
119 * Initialize os info and os info entries from oldmem
120 */
121static void os_info_old_init(void)
122{
123	static int os_info_init;
124	unsigned long addr;
125
126	if (os_info_init)
127		return;
128	if (!oldmem_data.start)
129		goto fail;
130	if (copy_oldmem_kernel(&addr, __LC_OS_INFO, sizeof(addr)))
131		goto fail;
132	if (addr == 0 || addr % PAGE_SIZE)
133		goto fail;
134	os_info_old = kzalloc(sizeof(*os_info_old), GFP_KERNEL);
135	if (!os_info_old)
136		goto fail;
137	if (copy_oldmem_kernel(os_info_old, addr, sizeof(*os_info_old)))
 
138		goto fail_free;
139	if (os_info_old->magic != OS_INFO_MAGIC)
140		goto fail_free;
141	if (os_info_old->csum != os_info_csum(os_info_old))
142		goto fail_free;
143	if (os_info_old->version_major > OS_INFO_VERSION_MAJOR)
144		goto fail_free;
145	os_info_old_alloc(OS_INFO_VMCOREINFO, 1);
146	os_info_old_alloc(OS_INFO_REIPL_BLOCK, 1);
147	pr_info("crashkernel: addr=0x%lx size=%lu\n",
148		(unsigned long) os_info_old->crashkernel_addr,
149		(unsigned long) os_info_old->crashkernel_size);
150	os_info_init = 1;
151	return;
152fail_free:
153	kfree(os_info_old);
154fail:
155	os_info_init = 1;
156	os_info_old = NULL;
157}
158
159/*
160 * Return pointer to os infor entry and its size
161 */
162void *os_info_old_entry(int nr, unsigned long *size)
163{
164	os_info_old_init();
165
166	if (!os_info_old)
167		return NULL;
168	if (!os_info_old->entry[nr].addr)
169		return NULL;
170	*size = (unsigned long) os_info_old->entry[nr].size;
171	return (void *)(unsigned long)os_info_old->entry[nr].addr;
172}
173#endif
v4.6
 
  1/*
  2 * OS info memory interface
  3 *
  4 * Copyright IBM Corp. 2012
  5 * Author(s): Michael Holzheu <holzheu@linux.vnet.ibm.com>
  6 */
  7
  8#define KMSG_COMPONENT "os_info"
  9#define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
 10
 11#include <linux/crash_dump.h>
 12#include <linux/kernel.h>
 13#include <linux/slab.h>
 14#include <asm/checksum.h>
 15#include <asm/lowcore.h>
 16#include <asm/os_info.h>
 
 
 17
 18/*
 19 * OS info structure has to be page aligned
 20 */
 21static struct os_info os_info __page_aligned_data;
 22
 23/*
 24 * Compute checksum over OS info structure
 25 */
 26u32 os_info_csum(struct os_info *os_info)
 27{
 28	int size = sizeof(*os_info) - offsetof(struct os_info, version_major);
 29	return csum_partial(&os_info->version_major, size, 0);
 30}
 31
 32/*
 33 * Add crashkernel info to OS info and update checksum
 34 */
 35void os_info_crashkernel_add(unsigned long base, unsigned long size)
 36{
 37	os_info.crashkernel_addr = (u64)(unsigned long)base;
 38	os_info.crashkernel_size = (u64)(unsigned long)size;
 39	os_info.csum = os_info_csum(&os_info);
 40}
 41
 42/*
 43 * Add OS info entry and update checksum
 44 */
 45void os_info_entry_add(int nr, void *ptr, u64 size)
 46{
 47	os_info.entry[nr].addr = (u64)(unsigned long)ptr;
 48	os_info.entry[nr].size = size;
 49	os_info.entry[nr].csum = csum_partial(ptr, size, 0);
 50	os_info.csum = os_info_csum(&os_info);
 51}
 52
 53/*
 54 * Initialize OS info struture and set lowcore pointer
 55 */
 56void __init os_info_init(void)
 57{
 58	void *ptr = &os_info;
 59
 60	os_info.version_major = OS_INFO_VERSION_MAJOR;
 61	os_info.version_minor = OS_INFO_VERSION_MINOR;
 62	os_info.magic = OS_INFO_MAGIC;
 63	os_info.csum = os_info_csum(&os_info);
 64	mem_assign_absolute(S390_lowcore.os_info, (unsigned long) ptr);
 
 
 65}
 66
 67#ifdef CONFIG_CRASH_DUMP
 68
 69static struct os_info *os_info_old;
 70
 71/*
 72 * Allocate and copy OS info entry from oldmem
 73 */
 74static void os_info_old_alloc(int nr, int align)
 75{
 76	unsigned long addr, size = 0;
 77	char *buf, *buf_align, *msg;
 78	u32 csum;
 79
 80	addr = os_info_old->entry[nr].addr;
 81	if (!addr) {
 82		msg = "not available";
 83		goto fail;
 84	}
 85	size = os_info_old->entry[nr].size;
 86	buf = kmalloc(size + align - 1, GFP_KERNEL);
 87	if (!buf) {
 88		msg = "alloc failed";
 89		goto fail;
 90	}
 91	buf_align = PTR_ALIGN(buf, align);
 92	if (copy_oldmem_kernel(buf_align, (void *) addr, size)) {
 93		msg = "copy failed";
 94		goto fail_free;
 95	}
 96	csum = csum_partial(buf_align, size, 0);
 97	if (csum != os_info_old->entry[nr].csum) {
 98		msg = "checksum failed";
 99		goto fail_free;
100	}
101	os_info_old->entry[nr].addr = (u64)(unsigned long)buf_align;
102	msg = "copied";
103	goto out;
104fail_free:
105	kfree(buf);
106fail:
107	os_info_old->entry[nr].addr = 0;
108out:
109	pr_info("entry %i: %s (addr=0x%lx size=%lu)\n",
110		nr, msg, addr, size);
111}
112
113/*
114 * Initialize os info and os info entries from oldmem
115 */
116static void os_info_old_init(void)
117{
118	static int os_info_init;
119	unsigned long addr;
120
121	if (os_info_init)
122		return;
123	if (!OLDMEM_BASE)
124		goto fail;
125	if (copy_oldmem_kernel(&addr, &S390_lowcore.os_info, sizeof(addr)))
126		goto fail;
127	if (addr == 0 || addr % PAGE_SIZE)
128		goto fail;
129	os_info_old = kzalloc(sizeof(*os_info_old), GFP_KERNEL);
130	if (!os_info_old)
131		goto fail;
132	if (copy_oldmem_kernel(os_info_old, (void *) addr,
133			       sizeof(*os_info_old)))
134		goto fail_free;
135	if (os_info_old->magic != OS_INFO_MAGIC)
136		goto fail_free;
137	if (os_info_old->csum != os_info_csum(os_info_old))
138		goto fail_free;
139	if (os_info_old->version_major > OS_INFO_VERSION_MAJOR)
140		goto fail_free;
141	os_info_old_alloc(OS_INFO_VMCOREINFO, 1);
142	os_info_old_alloc(OS_INFO_REIPL_BLOCK, 1);
143	pr_info("crashkernel: addr=0x%lx size=%lu\n",
144		(unsigned long) os_info_old->crashkernel_addr,
145		(unsigned long) os_info_old->crashkernel_size);
146	os_info_init = 1;
147	return;
148fail_free:
149	kfree(os_info_old);
150fail:
151	os_info_init = 1;
152	os_info_old = NULL;
153}
154
155/*
156 * Return pointer to os infor entry and its size
157 */
158void *os_info_old_entry(int nr, unsigned long *size)
159{
160	os_info_old_init();
161
162	if (!os_info_old)
163		return NULL;
164	if (!os_info_old->entry[nr].addr)
165		return NULL;
166	*size = (unsigned long) os_info_old->entry[nr].size;
167	return (void *)(unsigned long)os_info_old->entry[nr].addr;
168}
169#endif