increased usleep pause after HV call
[common.git] / source / lv1_map.c
bloba23c2a638fc77f79074602812c3ed013f12e5215
2 /*
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; version 2 of the License.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 #include <lv1_map.h>
19 #include <stdlib.h>
21 #include <lv1_hvcall.h>
22 #include <lv2_syscall.h>
23 #include <mm.h>
25 #define LV1_PA 0x0000000000000000ull
26 #define LV1_EA 0x8000000014000000ull
27 #define LV1_SIZE (16 * 1024 * 1024)
29 static uint64_t lv1_lpar;
32 * lv1_peek
34 uint64_t lv1_peek(uint64_t addr)
36 return lv2_peek(LV1_EA + addr);
40 * lv1_poke
42 void lv1_poke(uint64_t addr, uint64_t val)
44 lv2_poke(LV1_EA + addr, val);
48 * lv1_poke_8
50 void lv1_poke_8(uint64_t addr, uint8_t val)
52 uint64_t val_64;
54 val_64 = lv1_peek(addr & ~0x7ull);
56 val_64 &= ~(0xffull << ((sizeof(uint64_t) - (addr & 0x7ull) - 1) * 8));
57 val_64 |= ((uint64_t) val) << ((sizeof(uint64_t) - (addr & 0x7ull) - 1) * 8);
59 lv1_poke(addr & ~0x7ull, val_64);
63 * lv1_memcpy_to
65 void lv1_memcpy_to(uint64_t addr, const void *data, unsigned int size)
67 uint8_t *ptr;
68 unsigned int nbytes;
70 ptr = (uint8_t *) data;
72 if (addr & 0x7ull) {
73 nbytes = sizeof(uint64_t) - (addr & 0x7ull);
75 size -= nbytes;
77 while (nbytes--)
78 lv1_poke_8(addr++, *ptr++);
81 while (size >= sizeof(uint64_t)) {
82 lv1_poke(addr, *(uint64_t *) ptr);
84 addr += sizeof(uint64_t);
85 ptr += sizeof(uint64_t);
86 size -= sizeof(uint64_t);
89 while (size--)
90 lv1_poke_8(addr++, *ptr++);
94 * lv1_map
96 int lv1_map(void)
98 int result;
100 if (lv1_lpar)
101 return 0;
103 result = lv1_undocumented_function_114(LV1_PA, PAGE_SIZE_4KB, LV1_SIZE, &lv1_lpar);
104 if (result)
105 return result;
107 result = mm_map_lpar_memory_region(0, MM_EA2VA(LV1_EA), lv1_lpar, LV1_SIZE, PAGE_SIZE_4KB, 0, 0);
108 if (result) {
109 lv1_undocumented_function_115(lv1_lpar);
110 lv1_lpar = 0;
111 return result;
114 return 0;
118 * lv1_unmap
120 int lv1_unmap(void)
122 int result;
124 if (!lv1_lpar)
125 return 0;
127 result = lv1_undocumented_function_115(lv1_lpar);
128 if (result)
129 return result;
131 lv1_lpar = 0;
133 return 0;