iPXE
vmware.h
Go to the documentation of this file.
00001 #ifndef _IPXE_VMWARE_H
00002 #define _IPXE_VMWARE_H
00003 
00004 /** @file
00005  *
00006  * VMware backdoor mechanism
00007  *
00008  */
00009 
00010 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
00011 
00012 #include <stdint.h>
00013 
00014 /** VMware backdoor I/O port */
00015 #define VMW_PORT 0x5658
00016 
00017 /** VMware backdoor magic value */
00018 #define VMW_MAGIC 0x564d5868 /* "VMXh" */
00019 
00020 /** VMware backdoor magic instruction */
00021 #define VMW_BACKDOOR "inl %%dx, %%eax"
00022 
00023 /** Get VMware version */
00024 #define VMW_CMD_GET_VERSION 0x0a
00025 
00026 /** Issue GuestRPC command */
00027 #define VMW_CMD_GUESTRPC 0x1e
00028 
00029 /**
00030  * Get VMware version
00031  *
00032  * @ret version         VMware version(?)
00033  * @ret magic           VMware magic number, if present
00034  * @ret product_type    VMware product type
00035  */
00036 static inline __attribute__ (( always_inline )) void
00037 vmware_cmd_get_version ( uint32_t *version, uint32_t *magic,
00038                          uint32_t *product_type ) {
00039         uint32_t discard_d;
00040 
00041         /* Perform backdoor call */
00042         __asm__ __volatile__ ( VMW_BACKDOOR
00043                                : "=a" ( *version ), "=b" ( *magic ),
00044                                  "=c" ( *product_type ), "=d" ( discard_d )
00045                                : "0" ( VMW_MAGIC ), "1" ( 0 ),
00046                                  "2" ( VMW_CMD_GET_VERSION ),
00047                                  "3" ( VMW_PORT ) );
00048 }
00049 
00050 /**
00051  * Issue GuestRPC command
00052  *
00053  * @v channel           Channel number
00054  * @v subcommand        GuestRPC subcommand
00055  * @v parameter         Subcommand-specific parameter
00056  * @ret edxhi           Subcommand-specific result
00057  * @ret ebx             Subcommand-specific result
00058  * @ret status          Command status
00059  */
00060 static inline __attribute__ (( always_inline )) uint32_t
00061 vmware_cmd_guestrpc ( int channel, uint16_t subcommand, uint32_t parameter,
00062                       uint16_t *edxhi, uint32_t *ebx ) {
00063         uint32_t discard_a;
00064         uint32_t status;
00065         uint32_t edx;
00066 
00067         /* Perform backdoor call */
00068         __asm__ __volatile__ ( VMW_BACKDOOR
00069                                : "=a" ( discard_a ), "=b" ( *ebx ),
00070                                  "=c" ( status ), "=d" ( edx )
00071                                : "0" ( VMW_MAGIC ), "1" ( parameter ),
00072                                  "2" ( VMW_CMD_GUESTRPC | ( subcommand << 16 )),
00073                                  "3" ( VMW_PORT | ( channel << 16 ) ) );
00074         *edxhi = ( edx >> 16 );
00075 
00076         return status;
00077 }
00078 
00079 extern int vmware_present ( void );
00080 
00081 #endif /* _IPXE_VMWARE_H */