summaryrefslogtreecommitdiff
path: root/acpica/acpi_init.c
blob: 5081b9102c7c91117283f7133a4b76d5ea4260d2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
#include "acpi_init.h"
#include <kern/timer.h>		// clock
#include <kern/printf.h>	// *printf
#include <vm/pmap.h>		// vremap hack
#include <vm/vm_kern.h>		// kmem_alloc_wired 
#include <mach/vm_param.h>	// kmem_cache
#include <i386/pio.h>
#define MACH_INCLUDE
#include <linux/delay.h>	// udelay

#define ACPI_MAX_TABLES 128

// Lets keep the ACPI tables in this module
static struct acpi_table_desc initial_tables[ACPI_MAX_TABLES];

static void *
pmap_hack (unsigned long offset, unsigned long size)
{
	vm_offset_t addr;
	kern_return_t ret;

	ret = kmem_alloc_wired (kernel_map, &addr, round_page (size));
	if (ret != KERN_SUCCESS)
		return NULL;

	(void) pmap_map_bd (addr, offset, offset + round_page (size),
			    VM_PROT_READ | VM_PROT_WRITE);

	return (void *) addr;
}

void
acpi_ds_dump_method_stack(acpi_status status, ...)
//			  struct acpi_walk_state *walk_state,
//			  union acpi_parse_object *op)
{
	return;
}

acpi_status
acpi_os_create_cache(char *cache_name,
		     u16 object_size,
		     u16 max_depth, acpi_cache_t **return_cache)
{
	return (AE_OK);
}

acpi_status
acpi_os_delete_cache(acpi_cache_t *cache)
{
	return (AE_OK);
}

acpi_status
acpi_os_release_object(acpi_cache_t *cache, void *object)
{
	return (AE_OK);
}

void
acpi_os_printf(const char *fmt, ...)
{
	va_list args;
	va_start(args, fmt);
	acpi_os_vprintf(fmt, args);
	va_end(args);
}

void
acpi_os_vprintf(const char *fmt, va_list args)
{
	static char buffer[512];

	vsnprintf(buffer, 512, fmt, args);
	printf(buffer);
}

acpi_cpu_flags
acpi_os_acquire_lock(acpi_spinlock lockp)
{
	simple_lock(lockp);
	return 0;
}

void
acpi_os_release_lock(acpi_spinlock lockp, acpi_cpu_flags flags)
{
	simple_unlock(lockp);
}

void
acpi_os_delete_lock(acpi_spinlock handle)
{
	ACPI_FREE(handle);
}

acpi_status
acpi_os_create_semaphore(u32 max_units, u32 initial_units, acpi_semaphore * handle)
{
	printf("cant create semaphore\n");
	return AE_NO_MEMORY;
}

acpi_status
acpi_os_delete_semaphore(acpi_semaphore handle)
{
	return AE_OK;
}

acpi_status
acpi_os_execute(acpi_execute_type type,
		acpi_osd_exec_callback function, void *context)
{
	printf("XXX acpi_os_execute: not implemented\n");
	return (AE_OK);
}

acpi_physical_address
acpi_os_get_root_pointer(void)
{
	acpi_physical_address pa;

	acpi_find_root_pointer(&pa);
	return pa;
}

/* XXX: Supposed to be 64 bit free-running
 * monotonic timer with 100ns granularity
 * but we just pretend for now
 */
u64
acpi_os_get_timer(void)
{
	time_value_t now;

	timer_read(current_timer[0], &now);
	return (u64)(now.microseconds * 10);
}

void *
acpi_os_map_memory(acpi_physical_address phys, acpi_size size)
{
	return pmap_hack (phys, size);
}

acpi_status
acpi_os_read_port(acpi_io_address port, u32 * value, u32 width)
{
	u32 dummy;

	if (!value)
		value = &dummy;

	*value = 0;
	if (width <= 8) {
		*(u8 *) value = inb(port);
	} else if (width <= 16) {
		*(u16 *) value = inw(port);
	} else if (width <= 32) {
		*(u32 *) value = inl(port);
	} else {
		printf("ACPI: read port invalid width\n");
	}

	return AE_OK;
}

acpi_status
acpi_os_predefined_override(const struct acpi_predefined_names *init_val,
			    acpi_string *new_val)
{
	if (!init_val || !new_val)
		return AE_BAD_PARAMETER;

	return AE_OK;
}

acpi_status
acpi_os_signal(u32 function, void *info)
{
	switch (function) {
	case ACPI_SIGNAL_FATAL:
		printf("ACPI: Fatal opcode executed\n");
		break;
	case ACPI_SIGNAL_BREAKPOINT:
		break;
	default:
		break;
	}
	return AE_OK;
}

acpi_status
acpi_os_physical_table_override(struct acpi_table_header *existing_table,
				acpi_physical_address *address,
				u32 *table_length)
{
	return AE_OK;
}

acpi_status
acpi_os_table_override(struct acpi_table_header *existing_table,
		       struct acpi_table_header **new_table)
{
	if (!existing_table || !new_table)
		return AE_BAD_PARAMETER;

	*new_table = NULL;
	return AE_OK;
}

void
acpi_os_unmap_memory(void *virt, acpi_size size)
{
	return;
}

static int
acpi_os_read_iomem(void *virt_addr, u64 *value, u32 width)
{

	switch (width) {
	case 8:
		*(u8 *) value = *((volatile u8 *)virt_addr);
		break;
	case 16:
		*(u16 *) value = *((volatile u16 *)virt_addr);
		break;
	case 32:
		*(u32 *) value = *((volatile u32 *)virt_addr);
		break;
	case 64:
		*(u64 *) value = *((volatile u64 *)virt_addr);
		break;
	default:
		return EINVAL;
	}
	return 0;
}

acpi_status
acpi_os_read_memory(acpi_physical_address phys_addr, u64 *value, u32 width)
{
	void *virt_addr;
	unsigned int size = width / 8;
	u64 dummy;
	acpi_status err = AE_BAD_ADDRESS;

	virt_addr = vremap (phys_addr, size);
	if (!virt_addr)
		return err;

	if (!value)
		value = &dummy;

	if (!acpi_os_read_iomem (virt_addr, value, width))
		err = AE_OK;

	//munmap (virt_addr, size);

	return err;
}

acpi_status
acpi_os_wait_semaphore(acpi_handle handle, u32 units, u16 timeout)
{
	return AE_OK;
}

acpi_status
acpi_os_signal_semaphore(acpi_handle handle, u32 units)
{
	return AE_OK;
}


void
acpi_os_sleep(u64 ms)
{
	udelay(1000 * ms);
}

void
acpi_os_stall(u32 us)
{
	udelay(us);
}

void acpi_os_wait_events_complete(void)
{
	return;
}

acpi_status
acpi_os_write_memory(acpi_physical_address phys_addr, u64 value, u32 width)
{
	void *virt_addr;
	unsigned int size = width / 8;
	acpi_status err = AE_OK;

	virt_addr = vremap (phys_addr, size);
	if (!virt_addr)
		return AE_BAD_ADDRESS;

	switch (width) {
	case 8:
		*((volatile u8 *)virt_addr) = (u8)value;
		break;
	case 16:
		*((volatile u16 *)virt_addr) = (u16)value;
		break;
	case 32:
		*((volatile u32 *)virt_addr) = (u32)value;
		break;
	case 64:
		*((volatile u64 *)virt_addr) = value;
		break;
	default:
		printf("ACPI: Bad write memory width\n");
		err = AE_BAD_ADDRESS;
		break;
	}

	//munmap (virt_addr, size);

	return err;
}

acpi_status
acpi_os_write_port(acpi_io_address port, u32 value, u32 width)
{
	if (width <= 8) {
		outb(port, value);
	} else if (width <= 16) {
		outw(port, value);
	} else if (width <= 32) {
		outl(port, value);
	} else {
		printf("ACPI: Bad write port width\n");
	}

	return AE_OK;
}


acpi_status
acpi_os_install_interrupt_handler(u32 gsi, acpi_osd_handler handler,
				  void *context)
{
	return AE_OK;
}

acpi_status
acpi_os_remove_interrupt_handler(u32 gsi, acpi_osd_handler handler)
{
	return AE_OK;
}

acpi_status
acpi_os_read_pci_configuration(struct acpi_pci_id * pci_id, u32 reg,
			       u64 *value, u32 width)
{
	printf("ACPI: Tried to read pci config\n");
	return AE_ERROR;
}

acpi_status
acpi_os_write_pci_configuration(struct acpi_pci_id * pci_id, u32 reg,
				u64 value, u32 width)
{
	printf("ACPI: Tried to write pci config\n");
	return AE_ERROR;
}

/*
 * Missing symbols to implement:
 *
 * isdigit
 * isprint
 * isspace
 * isxdigit
 * tolower
 * toupper
 * x acpi_ds_dump_method_stack
 * x acpi_os_acquire_lock
 * x acpi_os_create_cache
 * x acpi_os_create_semaphore
 * x acpi_os_delete_cache
 * x acpi_os_delete_lock
 * x acpi_os_delete_semaphore
 * x acpi_os_get_root_pointer
 * x acpi_os_get_timer
 * x acpi_os_map_memory
 * x acpi_os_physical_table_override
 * x acpi_os_predefined_override
 * x acpi_os_printf
 * x acpi_os_read_memory
 * x acpi_os_read_port
 * x acpi_os_release_lock
 * x acpi_os_release_object
 * x acpi_os_signal
 * x acpi_os_signal_semaphore
 * x acpi_os_sleep
 * x acpi_os_stall
 * x acpi_os_table_override
 * x acpi_os_unmap_memory
 * x acpi_os_vprintf
 * x acpi_os_wait_events_complete
 * x acpi_os_wait_semaphore
 * x acpi_os_write_memory
 * x acpi_os_write_port
 * xx acpi_os_execute
 * xx acpi_os_install_interrupt_handler
 * xx acpi_os_read_pci_configuration
 * xx acpi_os_remove_interrupt_handler
 * xx acpi_os_write_pci_configuration
 */

void acpi_init(void)
{
	acpi_initialize_tables(initial_tables, ACPI_MAX_TABLES, 0);
}