1
/* Copyright 2013-2014 IBM Corp.
3
* Licensed under the Apache License, Version 2.0 (the "License");
4
* you may not use this file except in compliance with the License.
5
* You may obtain a copy of the License at
7
* http://www.apache.org/licenses/LICENSE-2.0
9
* Unless required by applicable law or agreed to in writing, software
10
* distributed under the License is distributed on an "AS IS" BASIS,
11
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
13
* See the License for the specific language governing permissions and
14
* limitations under the License.
19
#define BITS_PER_LONG (sizeof(long) * 8)
20
/* Don't include this, it's PPC-specific */
22
static unsigned int cpu_max_pir = 1;
29
static void *__malloc(size_t size, const char *location __attribute__((unused)))
34
static void *__realloc(void *ptr, size_t size, const char *location __attribute__((unused)))
36
return realloc(ptr, size);
39
static void *__zalloc(size_t size, const char *location __attribute__((unused)))
41
return calloc(size, 1);
44
static inline void __free(void *p, const char *location __attribute__((unused)))
51
/* We need mem_region to accept __location__ */
52
#define is_rodata(p) true
53
#include "../mem_region.c"
55
/* But we need device tree to make copies of names. */
57
#define is_rodata(p) false
59
#include "../device.c"
63
void lock(struct lock *l)
68
void unlock(struct lock *l)
73
bool lock_held_by_me(struct lock *l)
78
#define TEST_HEAP_ORDER 12
79
#define TEST_HEAP_SIZE (1ULL << TEST_HEAP_ORDER)
81
static void add_mem_node(uint64_t start, uint64_t len)
87
name = (char*)malloc(sizeof("memory@") + STR_MAX_CHARS(reg[0]));
90
/* reg contains start and length */
91
reg[0] = cpu_to_be64(start);
92
reg[1] = cpu_to_be64(len);
94
sprintf(name, "memory@%llx", (long long)start);
96
mem = dt_new(dt_root, name);
97
dt_add_property_string(mem, "device_type", "memory");
98
dt_add_property(mem, "reg", reg, sizeof(reg));
102
void add_chip_dev_associativity(struct dt_node *dev __attribute__((unused)))
109
struct mem_region *r;
112
/* Use malloc for the heap, so valgrind can find issues. */
113
skiboot_heap.start = (unsigned long)malloc(TEST_HEAP_SIZE);
114
skiboot_heap.len = TEST_HEAP_SIZE;
115
skiboot_os_reserve.len = skiboot_heap.start;
117
dt_root = dt_new_root("");
118
dt_add_property_cells(dt_root, "#address-cells", 2);
119
dt_add_property_cells(dt_root, "#size-cells", 2);
121
add_mem_node(0, 0x100000000ULL);
122
add_mem_node(0x100000000ULL, 0x100000000ULL);
126
mem_region_release_unused();
128
assert(mem_check(&skiboot_heap));
130
/* Now we expect it to be split. */
132
list_for_each(®ions, r, list) {
133
assert(mem_check(r));
135
if (r == &skiboot_os_reserve)
137
if (r == &skiboot_code_and_text)
139
if (r == &skiboot_heap)
141
if (r == &skiboot_after_heap)
143
if (r == &skiboot_cpu_stacks)
146
/* the memory nodes should all be available to the OS now */
147
assert(r->type == REGION_OS);
152
list_for_each(®ions, r, list) {
153
if (last != r->name &&
154
strncmp(r->name, NODE_REGION_PREFIX,
155
strlen(NODE_REGION_PREFIX)) == 0) {
156
/* It's safe to cast away the const as
157
* this never happens at runtime,
158
* only in test and only for valgrind
160
free((void*)r->name);
166
free((void *)(long)skiboot_heap.start);