1515#include <linux/errno.h>
1616#include <linux/bug.h>
1717#include <asm/page.h>
18+ #include <asm/gmap.h>
1819
1920#define UVC_RC_EXECUTED 0x0001
2021#define UVC_RC_INV_CMD 0x0002
2324#define UVC_RC_NO_RESUME 0x0007
2425
2526#define UVC_CMD_QUI 0x0001
27+ #define UVC_CMD_INIT_UV 0x000f
28+ #define UVC_CMD_CONV_TO_SEC_STOR 0x0200
29+ #define UVC_CMD_CONV_FROM_SEC_STOR 0x0201
30+ #define UVC_CMD_PIN_PAGE_SHARED 0x0341
31+ #define UVC_CMD_UNPIN_PAGE_SHARED 0x0342
2632#define UVC_CMD_SET_SHARED_ACCESS 0x1000
2733#define UVC_CMD_REMOVE_SHARED_ACCESS 0x1001
2834
2935/* Bits in installed uv calls */
3036enum uv_cmds_inst {
3137 BIT_UVC_CMD_QUI = 0 ,
38+ BIT_UVC_CMD_INIT_UV = 1 ,
39+ BIT_UVC_CMD_CONV_TO_SEC_STOR = 6 ,
40+ BIT_UVC_CMD_CONV_FROM_SEC_STOR = 7 ,
3241 BIT_UVC_CMD_SET_SHARED_ACCESS = 8 ,
3342 BIT_UVC_CMD_REMOVE_SHARED_ACCESS = 9 ,
43+ BIT_UVC_CMD_PIN_PAGE_SHARED = 21 ,
44+ BIT_UVC_CMD_UNPIN_PAGE_SHARED = 22 ,
3445};
3546
3647struct uv_cb_header {
@@ -44,7 +55,40 @@ struct uv_cb_qui {
4455 struct uv_cb_header header ;
4556 u64 reserved08 ;
4657 u64 inst_calls_list [4 ];
47- u64 reserved30 [15 ];
58+ u64 reserved30 [2 ];
59+ u64 uv_base_stor_len ;
60+ u64 reserved48 ;
61+ u64 conf_base_phys_stor_len ;
62+ u64 conf_base_virt_stor_len ;
63+ u64 conf_virt_var_stor_len ;
64+ u64 cpu_stor_len ;
65+ u32 reserved70 [3 ];
66+ u32 max_num_sec_conf ;
67+ u64 max_guest_stor_addr ;
68+ u8 reserved88 [158 - 136 ];
69+ u16 max_guest_cpus ;
70+ u8 reserveda0 [200 - 160 ];
71+ } __packed __aligned (8 );
72+
73+ struct uv_cb_init {
74+ struct uv_cb_header header ;
75+ u64 reserved08 [2 ];
76+ u64 stor_origin ;
77+ u64 stor_len ;
78+ u64 reserved28 [4 ];
79+ } __packed __aligned (8 );
80+
81+ struct uv_cb_cts {
82+ struct uv_cb_header header ;
83+ u64 reserved08 [2 ];
84+ u64 guest_handle ;
85+ u64 gaddr ;
86+ } __packed __aligned (8 );
87+
88+ struct uv_cb_cfs {
89+ struct uv_cb_header header ;
90+ u64 reserved08 [2 ];
91+ u64 paddr ;
4892} __packed __aligned (8 );
4993
5094struct uv_cb_share {
@@ -69,6 +113,20 @@ static inline int uv_call(unsigned long r1, unsigned long r2)
69113 return cc ;
70114}
71115
116+ struct uv_info {
117+ unsigned long inst_calls_list [4 ];
118+ unsigned long uv_base_stor_len ;
119+ unsigned long guest_base_stor_len ;
120+ unsigned long guest_virt_base_stor_len ;
121+ unsigned long guest_virt_var_stor_len ;
122+ unsigned long guest_cpu_stor_len ;
123+ unsigned long max_sec_stor_addr ;
124+ unsigned int max_num_sec_conf ;
125+ unsigned short max_guest_cpus ;
126+ };
127+
128+ extern struct uv_info uv_info ;
129+
72130#ifdef CONFIG_PROTECTED_VIRTUALIZATION_GUEST
73131extern int prot_virt_guest ;
74132
@@ -121,11 +179,40 @@ static inline int uv_remove_shared(unsigned long addr)
121179 return share (addr , UVC_CMD_REMOVE_SHARED_ACCESS );
122180}
123181
124- void uv_query_info (void );
125182#else
126183#define is_prot_virt_guest () 0
127184static inline int uv_set_shared (unsigned long addr ) { return 0 ; }
128185static inline int uv_remove_shared (unsigned long addr ) { return 0 ; }
186+ #endif
187+
188+ #if IS_ENABLED (CONFIG_KVM )
189+ extern int prot_virt_host ;
190+
191+ static inline int is_prot_virt_host (void )
192+ {
193+ return prot_virt_host ;
194+ }
195+
196+ int gmap_make_secure (struct gmap * gmap , unsigned long gaddr , void * uvcb );
197+ int uv_convert_from_secure (unsigned long paddr );
198+ int gmap_convert_to_secure (struct gmap * gmap , unsigned long gaddr );
199+
200+ void setup_uv (void );
201+ void adjust_to_uv_max (unsigned long * vmax );
202+ #else
203+ #define is_prot_virt_host () 0
204+ static inline void setup_uv (void ) {}
205+ static inline void adjust_to_uv_max (unsigned long * vmax ) {}
206+
207+ static inline int uv_convert_from_secure (unsigned long paddr )
208+ {
209+ return 0 ;
210+ }
211+ #endif
212+
213+ #if defined(CONFIG_PROTECTED_VIRTUALIZATION_GUEST ) || IS_ENABLED (CONFIG_KVM )
214+ void uv_query_info (void );
215+ #else
129216static inline void uv_query_info (void ) {}
130217#endif
131218
0 commit comments