1 /* Copyright 2013-2014 IBM Corp.
2  *
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
6  *
7  * 	http://www.apache.org/licenses/LICENSE-2.0
8  *
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
12  * implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 #include <stdlib.h>
17 #include <stdio.h>
18 #include <stdarg.h>
19 #include <string.h>
20 #include <malloc.h>
21 #include <stdint.h>
22 
23 #include <compiler.h>
24 
25 #include "../../ccan/list/list.c"
26 
27 void _prlog(int log_level __attribute__((unused)), const char* fmt, ...) __attribute__((format (printf, 2, 3)));
28 
29 #ifndef pr_fmt
30 #define pr_fmt(fmt) fmt
31 #endif
32 #define prlog(l, f, ...) do { _prlog(l, pr_fmt(f), ##__VA_ARGS__); } while(0)
33 
_prlog(int log_level,const char * fmt,...)34 void _prlog(int log_level __attribute__((unused)), const char* fmt, ...)
35 {
36 	va_list ap;
37 
38 	va_start(ap, fmt);
39 	if (log_level <= 7)
40 		vfprintf(stderr, fmt, ap);
41 	va_end(ap);
42 }
43 
44 /*
45  * Skiboot malloc stubs
46  *
47  * The actual prototypes for these are defined in mem_region-malloc.h,
48  * but that file also #defines malloc, and friends so we don't pull that in
49  * directly.
50  */
51 
52 #define DEFAULT_ALIGN __alignof__(long)
53 
54 void *__memalign(size_t blocksize, size_t bytes, const char *location __unused);
__memalign(size_t blocksize,size_t bytes,const char * location __unused)55 void *__memalign(size_t blocksize, size_t bytes, const char *location __unused)
56 {
57 	return memalign(blocksize, bytes);
58 }
59 
60 void *__malloc(size_t bytes, const char *location);
__malloc(size_t bytes,const char * location)61 void *__malloc(size_t bytes, const char *location)
62 {
63 	return __memalign(DEFAULT_ALIGN, bytes, location);
64 }
65 
66 void __free(void *p, const char *location __unused);
__free(void * p,const char * location __unused)67 void __free(void *p, const char *location __unused)
68 {
69 	free(p);
70 }
71 
72 void *__realloc(void *ptr, size_t size, const char *location __unused);
__realloc(void * ptr,size_t size,const char * location __unused)73 void *__realloc(void *ptr, size_t size, const char *location __unused)
74 {
75 	return realloc(ptr, size);
76 }
77 
78 void *__zalloc(size_t bytes, const char *location);
__zalloc(size_t bytes,const char * location)79 void *__zalloc(size_t bytes, const char *location)
80 {
81 	void *p = __malloc(bytes, location);
82 
83 	if (p)
84 		memset(p, 0, bytes);
85 	return p;
86 }
87 
88 struct cpu_thread;
89 
90 struct cpu_job *__cpu_queue_job(struct cpu_thread *cpu,
91 				const char *name,
92 				void (*func)(void *data), void *data,
93 				bool no_return);
94 
95 struct cpu_job *cpu_queue_job_on_node(uint32_t chip_id,
96 				      const char *name,
97 				      void (*func)(void *data), void *data);
98 
cpu_queue_job_on_node(uint32_t chip_id,const char * name,void (* func)(void * data),void * data)99 struct cpu_job *cpu_queue_job_on_node(uint32_t chip_id,
100 				       const char *name,
101 				       void (*func)(void *data), void *data)
102 {
103 	(void)chip_id;
104 	return __cpu_queue_job(NULL, name, func, data, false);
105 }
106 
__cpu_queue_job(struct cpu_thread * cpu,const char * name,void (* func)(void * data),void * data,bool no_return)107 struct cpu_job *__cpu_queue_job(struct cpu_thread *cpu,
108 				const char *name,
109 				void (*func)(void *data), void *data,
110 				bool no_return)
111 {
112 	(void)cpu;
113 	(void)name;
114 	(func)(data);
115 	(void)no_return;
116 	return NULL;
117 }
118 
119 void cpu_wait_job(struct cpu_job *job, bool free_it);
120 
cpu_wait_job(struct cpu_job * job,bool free_it)121 void __attrconst cpu_wait_job(struct cpu_job *job, bool free_it)
122 {
123 	(void)job;
124 	(void)free_it;
125 	return;
126 }
127 
128 void cpu_process_local_jobs(void);
129 
cpu_process_local_jobs(void)130 void __attrconst cpu_process_local_jobs(void)
131 {
132 }
133 
134 /* Add any stub functions required for linking here. */
stub_function(void)135 static void stub_function(void)
136 {
137 	abort();
138 }
139 
140 #define STUB(fnname) \
141 	void fnname(void) __attribute__((weak, alias ("stub_function")))
142 
143 STUB(fsp_preload_lid);
144 STUB(fsp_wait_lid_loaded);
145 STUB(fsp_adjust_lid_side);
146 
147 /* Add HW specific stubs here */
true_stub(void)148 static bool true_stub(void) { return true; }
false_stub(void)149 static bool false_stub(void) { return false; }
150 
151 #define TRUE_STUB(fnname) \
152 	bool fnname(void) __attribute__((weak, alias ("true_stub")))
153 #define FALSE_STUB(fnname) \
154 	bool fnname(void) __attribute__((weak, alias ("false_stub")))
155 #define NOOP_STUB FALSE_STUB
156 
157 TRUE_STUB(lock_held_by_me);
158 NOOP_STUB(lock_caller);
159 NOOP_STUB(unlock);
160 NOOP_STUB(early_uart_init);
161 NOOP_STUB(mem_reserve_fw);
162 NOOP_STUB(mem_reserve_hwbuf);
163 NOOP_STUB(add_chip_dev_associativity);
164 NOOP_STUB(enable_mambo_console);
165 NOOP_STUB(backtrace);
166 
167