Add qemu 2.4.0
[kvmfornfv.git] / qemu / roms / SLOF / slof / helpers.c
1 /******************************************************************************
2  * Copyright (c) 2007, 2012, 2013 IBM Corporation
3  * All rights reserved.
4  * This program and the accompanying materials
5  * are made available under the terms of the BSD License
6  * which accompanies this distribution, and is available at
7  * http://www.opensource.org/licenses/bsd-license.php
8  *
9  * Contributors:
10  *     IBM Corporation - initial implementation
11  *****************************************************************************/
12 /*
13  * All functions concerning interface to slof
14  */
15
16 #include <stdio.h>
17 #include <string.h>
18 #include <cpu.h>
19 #include "helpers.h"
20 #include "paflof.h"
21
22 /**
23  * get msec-timer value
24  * access to HW register
25  * overrun will occur if boot exceeds 1.193 hours (49 days)
26  *
27  * @param   -
28  * @return  actual timer value in ms as 32bit
29  */
30 uint32_t SLOF_GetTimer(void)
31 {
32         forth_eval("get-msecs");
33         return (uint32_t) forth_pop();
34 }
35
36 void SLOF_msleep(uint32_t time)
37 {
38         time = SLOF_GetTimer() + time;
39         while (time > SLOF_GetTimer())
40                 cpu_relax();
41 }
42
43 void SLOF_usleep(uint32_t time)
44 {
45         forth_push(time);
46         forth_eval("us");
47 }
48
49 void *SLOF_dma_alloc(long size)
50 {
51         forth_push(size);
52         forth_eval("dma-alloc");
53         return (void *)forth_pop();
54 }
55
56 void SLOF_dma_free(void *virt, long size)
57 {
58         forth_push((long)virt);
59         forth_push(size);
60         forth_eval("dma-free");
61 }
62
63 void *SLOF_alloc_mem(long size)
64 {
65         forth_push(size);
66         forth_eval("alloc-mem");
67         return (void *)forth_pop();
68 }
69
70 void *SLOF_alloc_mem_aligned(long size, long align)
71 {
72         unsigned long addr = (unsigned long)SLOF_alloc_mem(size + align - 1);
73         addr = addr + align - 1;
74         addr = addr & ~(align - 1);
75
76         return (void *)addr;
77 }
78
79 void SLOF_free_mem(void *addr, long size)
80 {
81         forth_push((long)addr);
82         forth_push(size);
83         forth_eval("free-mem");
84 }
85
86 long SLOF_dma_map_in(void *virt, long size, int cacheable)
87 {
88         forth_push((long)virt);
89         forth_push(size);
90         forth_push(cacheable);
91         forth_eval("dma-map-in");
92         return forth_pop();
93 }
94
95 void SLOF_dma_map_out(long phys, void *virt, long size)
96 {
97         forth_push((long)virt);
98         forth_push((long)phys);
99         forth_push(size);
100         forth_eval("dma-map-out");
101 }
102
103 long SLOF_pci_config_read32(long offset)
104 {
105         forth_push(offset);
106         forth_eval("config-l@");
107         return forth_pop();
108 }
109
110 long SLOF_pci_config_read16(long offset)
111 {
112         forth_push(offset);
113         forth_eval("config-w@");
114         return forth_pop();
115 }
116
117 void SLOF_pci_config_write32(long offset, long value)
118 {
119         forth_push(value);
120         forth_push(offset);
121         forth_eval("config-l!");
122 }
123
124 void SLOF_pci_config_write16(long offset, long value)
125 {
126         forth_push(value);
127         forth_push(offset);
128         forth_eval("config-w!");
129 }
130
131 void *SLOF_translate_my_address(void *addr)
132 {
133         forth_push((long)addr);
134         forth_eval("translate-my-address");
135         return (void *)forth_pop();
136 }