]> xenbits.xensource.com Git - xenclient/xen-pq.git/commitdiff
Load base vga bios for display pass-through.
authorKamala Narasimhan <kamala.narasimhan@citrix.com>
Mon, 6 Apr 2009 17:41:46 +0000 (13:41 -0400)
committerKamala Narasimhan <kamala.narasimhan@citrix.com>
Mon, 6 Apr 2009 17:41:46 +0000 (13:41 -0400)
Nothing new - Backport from existing branch.

xen-3.4/pt-load-vga-bios [new file with mode: 0644]
xen-3.4/series

diff --git a/xen-3.4/pt-load-vga-bios b/xen-3.4/pt-load-vga-bios
new file mode 100644 (file)
index 0000000..e16f263
--- /dev/null
@@ -0,0 +1,199 @@
+diff --git a/tools/libxc/xc_hvm_build.c b/tools/libxc/xc_hvm_build.c
+index e20f5ac..0ba8c44 100644
+--- a/tools/libxc/xc_hvm_build.c
++++ b/tools/libxc/xc_hvm_build.c
+@@ -66,6 +66,54 @@ static void build_hvm_info(void *hvm_info_page, uint64_t mem_size)
+     hvm_info->checksum = -sum;
+ }
++static int  setup_vga_pt(int            xc_handle,
++                         uint32_t       dom)
++{
++    int                 rc = 0;
++    unsigned char       *bios = NULL;
++    int                 bios_size = 0;
++    char                *va_bios = NULL;
++    uint32_t            va_size = 0;
++    char                *c = NULL;
++    char                checksum = 0;
++
++    /* Allocated 64K for the vga bios */
++    if (!(bios = malloc(64 * 1024)))
++        return -1;
++
++#ifdef __linux__
++    bios_size = xc_get_vgabios(bios, 64 * 1024);
++#else
++    bios_size = 0;
++#endif /* __linux__ */
++
++    va_size = bios_size + bios_size % XC_PAGE_SIZE;
++    if (bios_size == 0)
++    {
++        rc = -1;
++        goto error;
++    }
++    va_bios = xc_map_foreign_range(xc_handle, dom, va_size,
++                                   PROT_READ | PROT_WRITE, 0xC0);
++    if (!va_bios)
++    {
++        rc = -1;
++        goto error;
++    }
++
++    /* Adjust the bios checksum */
++    for ( c = (char*)bios; c < ((char*)bios + bios_size); c++ )
++        checksum += *c;
++    if (checksum)
++        bios[bios_size - 1] -= checksum;
++
++    memcpy(va_bios, bios, bios_size);
++    munmap(va_bios, va_size);
++error:
++    free(bios);
++    return rc;
++}
++
+ static int loadelfimage(
+     struct elf_binary *elf, int xch, uint32_t dom, unsigned long *parray)
+ {
+@@ -354,7 +402,8 @@ static inline int is_loadable_phdr(Elf32_Phdr *phdr)
+ int xc_hvm_build(int xc_handle,
+                  uint32_t domid,
+                  int memsize,
+-                 const char *image_name)
++                 const char *image_name,
++                 int vga_pt_enabled)
+ {
+     char *image;
+     int  sts;
+@@ -365,6 +414,8 @@ int xc_hvm_build(int xc_handle,
+         return -1;
+     sts = xc_hvm_build_internal(xc_handle, domid, memsize, memsize, image, image_size);
++    if ( vga_pt_enabled )
++        sts |= setup_vga_pt(xc_handle, domid);
+     free(image);
+diff --git a/tools/libxc/xc_linux.c b/tools/libxc/xc_linux.c
+index 2480b3c..6068960 100644
+--- a/tools/libxc/xc_linux.c
++++ b/tools/libxc/xc_linux.c
+@@ -562,6 +562,57 @@ int xc_gnttab_set_max_grants(int xcg_handle,
+     return 0;
+ }
++int xc_get_vgabios(unsigned char        *buf,
++                   int                  len)
++{
++    int         mem;
++    uint32_t    start, size = 0;
++    uint16_t    magic = 0;
++
++    start = 0xC0000;
++    if (len < size)
++        return 0;
++    if ((mem = open("/dev/mem", O_RDONLY)) < 0)
++        return 0;
++
++    /*
++    ** Check if it a real bios extension.
++    ** The magic number is 0xAA55.
++    */
++    if (start != lseek(mem, start, SEEK_SET))
++        goto out;
++    if (read(mem, &magic, 2) != 2)
++        goto out;
++    if (magic != 0xAA55)
++        goto out;
++
++    /* Find the size of the rom extension */
++    if (start != lseek(mem, start, SEEK_SET))
++        goto out;
++    if (lseek(mem, 2, SEEK_CUR) != (start + 2))
++        goto out;
++    if (read(mem, &size, 1) != 1)
++        goto out;
++    /* This size is in 512K */
++    size *= 512;
++
++    /*
++    ** Set the file to the begining of the rombios,
++    ** to start the copy.
++    */
++    if (start != lseek(mem, start, SEEK_SET))
++    {
++        size = 0;
++        goto out;
++    }
++    if (size != read(mem, buf, size))
++        size = 0;
++
++out:
++    close(mem);
++    return size;
++}
++
+ /*
+  * Local variables:
+  * mode: C
+diff --git a/tools/libxc/xenctrl.h b/tools/libxc/xenctrl.h
+index 9ce2286..dfd6fa4 100644
+--- a/tools/libxc/xenctrl.h
++++ b/tools/libxc/xenctrl.h
+@@ -145,6 +145,10 @@ int xc_waitdomain(
+     int *status,
+     int options);
++int xc_get_vgabios(
++    unsigned char       *bios,
++    int                 len);
++
+ #endif /* __linux__ */
+ /*
+diff --git a/tools/libxc/xenguest.h b/tools/libxc/xenguest.h
+index d64fc45..e58302b 100644
+--- a/tools/libxc/xenguest.h
++++ b/tools/libxc/xenguest.h
+@@ -125,10 +125,12 @@ int xc_linux_build_mem(int xc_handle,
+                        unsigned int console_evtchn,
+                        unsigned long *console_mfn);
++#define USE_VGA_PASSTHROUGH_IN_HVM_BUILD
+ int xc_hvm_build(int xc_handle,
+                  uint32_t domid,
+                  int memsize,
+-                 const char *image_name);
++                 const char *image_name,
++                 int vga_pt_enabled);
+ int xc_hvm_build_target_mem(int xc_handle,
+                             uint32_t domid,
+diff --git a/tools/libxc/xg_private.c b/tools/libxc/xg_private.c
+index 4dc3a5c..2a3706e 100644
+--- a/tools/libxc/xg_private.c
++++ b/tools/libxc/xg_private.c
+@@ -177,7 +177,8 @@ __attribute__((weak))
+     int xc_hvm_build(int xc_handle,
+                      uint32_t domid,
+                      int memsize,
+-                     const char *image_name)
++                     const char *image_name,
++                     int vga_pt_enabled)
+ {
+     errno = ENOSYS;
+     return -1;
+diff --git a/xen/include/public/hvm/hvm_info_table.h b/xen/include/public/hvm/hvm_info_table.h
+index eb965dc..774a7d5 100644
+--- a/xen/include/public/hvm/hvm_info_table.h
++++ b/xen/include/public/hvm/hvm_info_table.h
+@@ -36,6 +36,7 @@
+ #define HVM_ACINFO_PADDR     ((HVM_INFO_PFN << 12) + HVM_ACINFO_OFFSET)
+ #define HVM_ACINFO_MAX       0x400
++#define XEN_BRANCH_3_4
+ #define HVM_SMINFO_EXTENSIONS 1
+ #define HVM_ACINFO_EXTENSIONS 1
index 097522e25623a49e2ef986a197b8aa3868859a00..dfdb1c6da4477c8d188e79cb44e0ebad55b4d452 100644 (file)
@@ -4,3 +4,4 @@ smbios
 acpi-slic
 oem-features
 thermal-management
+pt-load-vga-bios