From: "Daniel P. Berrange" <berrange@redhat.com>
To: Jean Guyader <jean.guyader@eu.citrix.com>
Cc: Ian Pratt <Ian.Pratt@eu.citrix.com>,
xen-devel@lists.xensource.com,
Keir Fraser <keir.fraser@eu.citrix.com>,
Kamala Narasimhan <Kamala.Narasimhan@citrix.com>
Subject: Re: [PATCH] Pass-through a graphic card
Date: Fri, 9 May 2008 15:25:43 +0100 [thread overview]
Message-ID: <20080509142543.GC2265@redhat.com> (raw)
In-Reply-To: <4824581F.7050904@eu.citrix.com>
On Fri, May 09, 2008 at 02:56:47PM +0100, Jean Guyader wrote:
>
> Here, a new patch with the modifications that Samuel suggested.
> +static void dom0_read(void *opaque)
> +{
> + struct input_event event[5];
> + int i = 0;
> + int read_sz = 0;
> + int fd = *(int *)opaque;
> +
> + read_sz = read(fd, event, sizeof (struct input_event) * 5);
Could simply do 'sizeof(event)' here I believe.
> +static void dom0_driver_event_init()
> +{
> + char dev_name[strlen(EVENT_PATH) + 3];
> + int fd = -1;
> + int i = 0;
> +
> + do
> + {
> + snprintf(dev_name, sizeof (dev_name), "%s%d", EVENT_PATH, i++);
> + if ((fd = open(dev_name, O_RDONLY)) == -1)
> + return;
> + printf("Using %s\n", dev_name);
> +
> + driver.event_fds = realloc(driver.event_fds,
> + driver.event_nb + 1);
Error checking on reallocs...
> + ioctl(fd, EVIOCGRAB, 1);
ioctls can fail.
> + driver.event_fds[driver.event_nb] = fd;
> + qemu_set_fd_handler(fd, dom0_read, NULL,
> + &driver.event_fds[driver.event_nb]);
> + driver.event_nb++;
> + }
> + while (1);
> +}
> diff -r 810d8c3ac992 tools/ioemu/hw/pc.c
> --- a/tools/ioemu/hw/pc.c Thu May 08 16:58:33 2008 +0100
> +++ b/tools/ioemu/hw/pc.c Fri May 09 14:53:11 2008 +0100
> @@ -814,6 +814,13 @@ static void pc_init1(uint64_t ram_size,
> CPUState *env;
> NICInfo *nd;
> int rc;
> +#ifdef CONFIG_DM
> + unsigned long vga_pt_enabled = 0;
> +#endif /* CONFIG_DM */
> +
> +#ifdef CONFIG_DM
> + xc_get_hvm_param(xc_handle, domid, HVM_PARAM_VGA_PT_ENABLED, &vga_pt_enabled);
> +#endif /* CONFIG_DM */
This API can return a failure code.
> @@ -152,9 +152,122 @@ static int loadelfimage(
> return rc;
> }
>
> +static int linux_get_vgabios(int xc_handle,
> + unsigned char *buf,
> + int len)
> +{
> + char buff[1024];
> + FILE *fd;
> + int mem;
> + char *end_ptr;
> + uint32_t start, end, size;
> +
> + if (!(fd = fopen("/proc/iomem", "r")))
> + return 0;
> +
> + while (fgets(buff, 1024, fd))
> + if (strstr(buff, "Video ROM"))
> + break;
> +
> + if (feof(fd))
Should be also checking ferror(fd)
> + {
> + fclose(fd);
> + return 0;
> + }
> +
> + fclose(fd);
> + start = strtol(buff, &end_ptr, 16);
> + end = strtol(end_ptr + 1, NULL, 16);
> + size = end - start + 1;
> +
> + if ((mem = open("/dev/mem", O_RDONLY)) < 0)
> + return 0;
> +
> + lseek(mem, start, SEEK_SET);
> + read(mem, buf, size);
Check for failure / partial reads.
> +static int linux_map_vga_ioport(int xc_handler,
> + uint32_t dom)
> +{
> + FILE *fd = NULL;
> + char buff[256];
> + uint32_t start, end;
> + char *buff_end = NULL;
> +
> + if (!(fd = fopen("/proc/ioports", "r")))
> + return -1;
> +
> + while (fgets(buff, 256, fd))
> + if (strstr(buff, "vga"))
> + break;
> +
> + if (feof(fd))
Also check ferror(fd)
> + {
> + fclose(fd);
> + return -1;
> + }
> +
> + fclose(fd);
> +
> + start = strtol(buff, &buff_end, 16);
> + end = strtol(buff_end + 1, NULL, 16);
> +
> + return xc_domain_ioport_mapping(xc_handler, dom,
> + start, start, end - start + 1, 1);
> +}
> +
> +static int setup_vga_pt(int xc_handle,
> + uint32_t dom,
> + uint32_t paddr,
> + struct hvm_info_table *hvm_info)
> +{
> + int rc = 0;
> + unsigned char *bios = NULL;
> + int bios_size = 0;
> + char *va_bios = NULL;
> + uint32_t pfn = 0;
> +
> + /* Allocated 128K for the vga bios */
> + if (!(bios = malloc(128 * 1024)))
> + return -1;
> +
> + /* Align paddr on the first next page */
> + pfn = (paddr >> XC_PAGE_SHIFT) + 1;
> +
> + bios_size = linux_get_vgabios(xc_handle, bios, 128 * 1024);
> +
> + if (bios_size <= 0)
> + {
> + free(bios);
> + return -1;
> + }
> +
> + va_bios = xc_map_foreign_range(xc_handle, dom,
> + bios_size + bios_size % XC_PAGE_SIZE,
> + PROT_READ | PROT_WRITE, pfn);
This call can fail.
> @@ -348,9 +471,10 @@ int xc_hvm_build(int xc_handle,
> int xc_hvm_build(int xc_handle,
> uint32_t domid,
> int memsize,
> - const char *image_name)
> + const char *image_name,
> + struct hvm_info_table *hvm_info)
> {
> - char *image;
> + char *image;
Needless whitespace error.
Regards,
Daniel
--
|: Red Hat, Engineering, Boston -o- http://people.redhat.com/berrange/ :|
|: http://libvirt.org -o- http://virt-manager.org -o- http://ovirt.org :|
|: http://autobuild.org -o- http://search.cpan.org/~danberr/ :|
|: GnuPG: 7D3B9505 -o- F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|
next prev parent reply other threads:[~2008-05-09 14:25 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-05-09 11:11 [PATCH] Pass-through a graphic card Jean Guyader
2008-05-09 11:18 ` Jean Guyader
2008-05-09 11:32 ` Samuel Thibault
2008-05-09 11:27 ` Samuel Thibault
2008-05-09 13:56 ` Jean Guyader
2008-05-09 14:02 ` Daniel P. Berrange
2008-05-09 14:25 ` Daniel P. Berrange [this message]
2008-05-09 15:47 ` Jean Guyader
2008-05-15 10:11 ` Jean Guyader
2008-05-15 11:13 ` Samuel Thibault
2008-05-15 11:17 ` Jean Guyader
2008-05-16 8:59 ` Jean Guyader
2008-05-16 17:15 ` Samuel Thibault
-- strict thread matches above, loose matches on Subject: below --
2008-06-13 15:08 mail mark
2008-06-13 15:25 ` Jean Guyader
2008-06-21 17:36 ` mail mark
2008-06-21 19:28 ` Jean Guyader
2008-06-23 13:20 ` mail mark
2008-06-21 17:43 ` Neo Jia
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20080509142543.GC2265@redhat.com \
--to=berrange@redhat.com \
--cc=Ian.Pratt@eu.citrix.com \
--cc=Kamala.Narasimhan@citrix.com \
--cc=jean.guyader@eu.citrix.com \
--cc=keir.fraser@eu.citrix.com \
--cc=xen-devel@lists.xensource.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.