summaryrefslogtreecommitdiffstats
path: root/qemu/roms/SLOF/slof/helpers.c
blob: d7c1888b46f914df1b2d29c2be8ccdb8a5766297 (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
/******************************************************************************
 * Copyright (c) 2007, 2012, 2013 IBM Corporation
 * All rights reserved.
 * This program and the accompanying materials
 * are made available under the terms of the BSD License
 * which accompanies this distribution, and is available at
 * http://www.opensource.org/licenses/bsd-license.php
 *
 * Contributors:
 *     IBM Corporation - initial implementation
 *****************************************************************************/
/*
 * All functions concerning interface to slof
 */

#include <stdio.h>
#include <string.h>
#include <cpu.h>
#include "helpers.h"
#include "paflof.h"

/**
 * get msec-timer value
 * access to HW register
 * overrun will occur if boot exceeds 1.193 hours (49 days)
 *
 * @param   -
 * @return  actual timer value in ms as 32bit
 */
uint32_t SLOF_GetTimer(void)
{
	forth_eval("get-msecs");
	return (uint32_t) forth_pop();
}

void SLOF_msleep(uint32_t time)
{
	time = SLOF_GetTimer() + time;
	while (time > SLOF_GetTimer())
		cpu_relax();
}

void SLOF_usleep(uint32_t time)
{
	forth_push(time);
	forth_eval("us");
}

void *SLOF_dma_alloc(long size)
{
	forth_push(size);
	forth_eval("dma-alloc");
	return (void *)forth_pop();
}

void SLOF_dma_free(void *virt, long size)
{
	forth_push((long)virt);
	forth_push(size);
	forth_eval("dma-free");
}

void *SLOF_alloc_mem(long size)
{
	forth_push(size);
	forth_eval("alloc-mem");
	return (void *)forth_pop();
}

void *SLOF_alloc_mem_aligned(long size, long align)
{
	unsigned long addr = (unsigned long)SLOF_alloc_mem(size + align - 1);
	addr = addr + align - 1;
	addr = addr & ~(align - 1);

	return (void *)addr;
}

void SLOF_free_mem(void *addr, long size)
{
	forth_push((long)addr);
	forth_push(size);
	forth_eval("free-mem");
}

long SLOF_dma_map_in(void *virt, long size, int cacheable)
{
	forth_push((long)virt);
	forth_push(size);
	forth_push(cacheable);
	forth_eval("dma-map-in");
	return forth_pop();
}

void SLOF_dma_map_out(long phys, void *virt, long size)
{
	forth_push((long)virt);
	forth_push((long)phys);
	forth_push(size);
	forth_eval("dma-map-out");
}

long SLOF_pci_config_read32(long offset)
{
	forth_push(offset);
	forth_eval("config-l@");
	return forth_pop();
}

long SLOF_pci_config_read16(long offset)
{
	forth_push(offset);
	forth_eval("config-w@");
	return forth_pop();
}

void SLOF_pci_config_write32(long offset, long value)
{
	forth_push(value);
	forth_push(offset);
	forth_eval("config-l!");
}

void SLOF_pci_config_write16(long offset, long value)
{
	forth_push(value);
	forth_push(offset);
	forth_eval("config-w!");
}

void *SLOF_translate_my_address(void *addr)
{
	forth_push((long)addr);
	forth_eval("translate-my-address");
	return (void *)forth_pop();
}