mdesc.c (f790c0ca6fad60b544bb73eda8cc841a6436725b) mdesc.c (95f72d1ed41a66f1c1c29c24d479de81a0bea36f)
1/* mdesc.c: Sun4V machine description handling.
2 *
3 * Copyright (C) 2007, 2008 David S. Miller <davem@davemloft.net>
4 */
5#include <linux/kernel.h>
6#include <linux/types.h>
1/* mdesc.c: Sun4V machine description handling.
2 *
3 * Copyright (C) 2007, 2008 David S. Miller <davem@davemloft.net>
4 */
5#include <linux/kernel.h>
6#include <linux/types.h>
7#include <linux/lmb.h>
7#include <linux/memblock.h>
8#include <linux/log2.h>
9#include <linux/list.h>
10#include <linux/slab.h>
11#include <linux/mm.h>
12#include <linux/miscdevice.h>
13#include <linux/bootmem.h>
14
15#include <asm/cpudata.h>

--- 65 unchanged lines hidden (view full) ---

81
82 memset(hp, 0, handle_size);
83 INIT_LIST_HEAD(&hp->list);
84 hp->self_base = base;
85 atomic_set(&hp->refcnt, 1);
86 hp->handle_size = handle_size;
87}
88
8#include <linux/log2.h>
9#include <linux/list.h>
10#include <linux/slab.h>
11#include <linux/mm.h>
12#include <linux/miscdevice.h>
13#include <linux/bootmem.h>
14
15#include <asm/cpudata.h>

--- 65 unchanged lines hidden (view full) ---

81
82 memset(hp, 0, handle_size);
83 INIT_LIST_HEAD(&hp->list);
84 hp->self_base = base;
85 atomic_set(&hp->refcnt, 1);
86 hp->handle_size = handle_size;
87}
88
89static struct mdesc_handle * __init mdesc_lmb_alloc(unsigned int mdesc_size)
89static struct mdesc_handle * __init mdesc_memblock_alloc(unsigned int mdesc_size)
90{
91 unsigned int handle_size, alloc_size;
92 struct mdesc_handle *hp;
93 unsigned long paddr;
94
95 handle_size = (sizeof(struct mdesc_handle) -
96 sizeof(struct mdesc_hdr) +
97 mdesc_size);
98 alloc_size = PAGE_ALIGN(handle_size);
99
90{
91 unsigned int handle_size, alloc_size;
92 struct mdesc_handle *hp;
93 unsigned long paddr;
94
95 handle_size = (sizeof(struct mdesc_handle) -
96 sizeof(struct mdesc_hdr) +
97 mdesc_size);
98 alloc_size = PAGE_ALIGN(handle_size);
99
100 paddr = lmb_alloc(alloc_size, PAGE_SIZE);
100 paddr = memblock_alloc(alloc_size, PAGE_SIZE);
101
102 hp = NULL;
103 if (paddr) {
104 hp = __va(paddr);
105 mdesc_handle_init(hp, handle_size, hp);
106 }
107 return hp;
108}
109
101
102 hp = NULL;
103 if (paddr) {
104 hp = __va(paddr);
105 mdesc_handle_init(hp, handle_size, hp);
106 }
107 return hp;
108}
109
110static void mdesc_lmb_free(struct mdesc_handle *hp)
110static void mdesc_memblock_free(struct mdesc_handle *hp)
111{
112 unsigned int alloc_size;
113 unsigned long start;
114
115 BUG_ON(atomic_read(&hp->refcnt) != 0);
116 BUG_ON(!list_empty(&hp->list));
117
118 alloc_size = PAGE_ALIGN(hp->handle_size);
119 start = __pa(hp);
120 free_bootmem_late(start, alloc_size);
121}
122
111{
112 unsigned int alloc_size;
113 unsigned long start;
114
115 BUG_ON(atomic_read(&hp->refcnt) != 0);
116 BUG_ON(!list_empty(&hp->list));
117
118 alloc_size = PAGE_ALIGN(hp->handle_size);
119 start = __pa(hp);
120 free_bootmem_late(start, alloc_size);
121}
122
123static struct mdesc_mem_ops lmb_mdesc_ops = {
124 .alloc = mdesc_lmb_alloc,
125 .free = mdesc_lmb_free,
123static struct mdesc_mem_ops memblock_mdesc_ops = {
124 .alloc = mdesc_memblock_alloc,
125 .free = mdesc_memblock_free,
126};
127
128static struct mdesc_handle *mdesc_kmalloc(unsigned int mdesc_size)
129{
130 unsigned int handle_size;
131 void *base;
132
133 handle_size = (sizeof(struct mdesc_handle) -

--- 775 unchanged lines hidden (view full) ---

909{
910 struct mdesc_handle *hp;
911 unsigned long len, real_len, status;
912
913 (void) sun4v_mach_desc(0UL, 0UL, &len);
914
915 printk("MDESC: Size is %lu bytes.\n", len);
916
126};
127
128static struct mdesc_handle *mdesc_kmalloc(unsigned int mdesc_size)
129{
130 unsigned int handle_size;
131 void *base;
132
133 handle_size = (sizeof(struct mdesc_handle) -

--- 775 unchanged lines hidden (view full) ---

909{
910 struct mdesc_handle *hp;
911 unsigned long len, real_len, status;
912
913 (void) sun4v_mach_desc(0UL, 0UL, &len);
914
915 printk("MDESC: Size is %lu bytes.\n", len);
916
917 hp = mdesc_alloc(len, &lmb_mdesc_ops);
917 hp = mdesc_alloc(len, &memblock_mdesc_ops);
918 if (hp == NULL) {
919 prom_printf("MDESC: alloc of %lu bytes failed.\n", len);
920 prom_halt();
921 }
922
923 status = sun4v_mach_desc(__pa(&hp->mdesc), len, &real_len);
924 if (status != HV_EOK || real_len > len) {
925 prom_printf("sun4v_mach_desc fails, err(%lu), "
926 "len(%lu), real_len(%lu)\n",
927 status, len, real_len);
928 mdesc_free(hp);
929 prom_halt();
930 }
931
932 cur_mdesc = hp;
933
934 report_platform_properties();
935}
918 if (hp == NULL) {
919 prom_printf("MDESC: alloc of %lu bytes failed.\n", len);
920 prom_halt();
921 }
922
923 status = sun4v_mach_desc(__pa(&hp->mdesc), len, &real_len);
924 if (status != HV_EOK || real_len > len) {
925 prom_printf("sun4v_mach_desc fails, err(%lu), "
926 "len(%lu), real_len(%lu)\n",
927 status, len, real_len);
928 mdesc_free(hp);
929 prom_halt();
930 }
931
932 cur_mdesc = hp;
933
934 report_platform_properties();
935}