loader: remove shouting from ORB's variable name
[hvf.git] / cp / include / dat.h
blob1d23c99e79501404aca7907e3c6c034f3ccac8e2
1 /*
2 * (C) Copyright 2007-2010 Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
4 * This file is released under the GPLv2. See the COPYING file for more
5 * details.
6 */
8 #ifndef __DAT_H
9 #define __DAT_H
11 struct address_space {
12 struct dat_rte *region_table;
13 struct dat_ste *segment_table;
16 /* region/segment-table destination */
17 struct dat_td {
18 u64 origin:52, /* region/segment table origin */
19 __reserved0:2,
20 g:1, /* subspace-group control */
21 p:1, /* private-space control */
22 s:1, /* storage-alteration-event ctl */
23 x:1, /* space-switch-event control */
24 r:1, /* real-space control */
25 __reserved1:1,
26 dt:2, /* designation-type control */
27 tl:2; /* table length */
28 } __attribute__((packed));
30 #define DAT_TD_DT_RFT 3 /* region-first */
31 #define DAT_TD_DT_RST 2 /* region-second */
32 #define DAT_TD_DT_RTT 1 /* region-third */
33 #define DAT_TD_DT_ST 0 /* segment */
35 /* region-table entries (first, second, and third) */
36 struct dat_rte {
37 u64 origin:52, /* next-level-table origin */
38 __reserved0:4,
39 tf:2, /* table offset (next lower tbl) */
40 i:1, /* region invalid */
41 __reserved1:1,
42 tt:2, /* table-type bits (current tbl) */
43 tl:2; /* table length (next lower tbl) */
44 } __attribute__((packed));
47 * Constants for struct rte
49 #define DAT_RTE_TT_RFT 3 /* region-first */
50 #define DAT_RTE_TT_RST 2 /* region-second */
51 #define DAT_RTE_TT_RTT 1 /* region-third */
53 #define ADDR_TO_RTE_ORIGIN(a) ((a) >> 12)
54 #define RTE_ORIGIN_TO_ADDR(o) ((void*)(((u64)(o)) << 12))
56 /* segment-table entries */
57 struct dat_ste {
58 u64 origin:53, /* page-table origin */
59 __reserved0:1,
60 p:1, /* page-protection bit */
61 __reserved1:3,
62 i:1, /* segment-invalid bit */
63 c:1, /* common-segment bit */
64 tt:2, /* table-type bits */
65 __reserved2:2;
66 } __attribute__((packed));
68 #define DAT_STE_TT_ST 0 /* segment-table */
70 #define ADDR_TO_STE_ORIGIN(a) ((a) >> 11)
71 #define STE_ORIGIN_TO_ADDR(o) ((void*)(((u64)(o)) << 11))
73 /* page-table entries */
74 struct dat_pte {
75 u64 pfra:52, /* page-frame real address */
76 __zero0:1,
77 i:1, /* page-invalid bit */
78 p:1, /* page-protection bit */
79 __zero1:1,
80 __reserved:8;
81 } __attribute__((packed));
83 #define DAT_RX(addr) (((u64)(addr)) >> 31)
84 #define DAT_SX(addr) ((((u64)(addr)) >> 20) & 0x7ff)
85 #define DAT_PX(addr) ((((u64)(addr)) >> 12) & 0xff)
86 #define DAT_BX(addr) (((u64)(addr))& 0xfff)
88 extern int dat_insert_page(struct address_space *as, u64 phy, u64 virt);
89 extern void setup_dat(void);
90 extern void load_as(struct address_space *as);
92 extern int virt2phy(struct address_space *as, u64 virt, u64 *phy);
94 static inline void store_pasce(u64 *pasce)
96 asm volatile(
97 " stctg 1,1,0(%0)\n"
98 : /* output */
99 : /* input */
100 "a" (pasce)
104 static inline void load_pasce(u64 pasce)
106 if (!pasce)
107 return;
109 asm volatile(
110 " lctlg 1,1,%0\n"
111 : /* output */
112 : /* input */
113 "m" (pasce)
117 /* get host real address from guest real, using the currently loaded ASCE */
118 static inline int virt2phy_current(u64 virt, u64 *phy)
120 u64 result;
121 int cc;
123 asm volatile(
124 " lrag %0,0(%%r0,%2)\n"
125 " ipm %1\n"
126 " srl %1,28\n"
127 : /* output */
128 "=d" (result),
129 "=d" (cc)
130 : /* input */
131 "a" (virt)
132 : /* clobber */
133 "cc"
136 if (cc != 0)
137 return -EFAULT;
139 *phy = result;
140 return 0;
143 #define memcpy_to_guest(gaddr, ptr, len) __memcpy_tofrom_guest((gaddr), (ptr), (len), 0)
144 #define memcpy_from_guest(gaddr, ptr, len) __memcpy_tofrom_guest((gaddr), (ptr), (len), 1)
146 extern int __memcpy_tofrom_guest(u64 guest_addr, void *data, u64 *len, int from);
148 #endif