summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDave Airlie <airlied@redhat.com>2009-06-05 09:32:10 +1000
committerDave Airlie <airlied@redhat.com>2009-06-05 09:32:10 +1000
commit9ae22c87743c624bda593a1ef4bd4eca01c65655 (patch)
tree79e3338c68d20bbfa65c96fdaf8d71f2cc1bdc54 /src
parent9ae66143550a6aee25d9a9620c5bebf93fa196e5 (diff)
vgaarb: fixup api and decode rsrc.
This fixes up the API and stores the vga arb fd in the sys_pci structure, instead of hiding it in a random dev struct. It also reads back after setting the target and works out the decodes. Signed-off-by: Dave Airlie <airlied@redhat.com>
Diffstat (limited to 'src')
-rw-r--r--src/common_vgaarb.c61
-rw-r--r--src/pciaccess_private.h1
2 files changed, 51 insertions, 11 deletions
diff --git a/src/common_vgaarb.c b/src/common_vgaarb.c
index f75257e..232d4ac 100644
--- a/src/common_vgaarb.c
+++ b/src/common_vgaarb.c
@@ -26,20 +26,20 @@
*/
#include <stdio.h>
+#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include "pciaccess.h"
+#include "pciaccess_private.h"
#define BUFSIZE 32
int
-pci_device_vgaarb_init(struct pci_device *dev)
+pci_device_vgaarb_init(void)
{
- dev->vgaarb_rsrc = VGA_ARB_RSRC_NONE;
-
- if ((dev->vgaarb_fd = open ("/dev/vga_arbiter", O_RDWR)) < 0) {
+ if ((pci_sys->vgaarb_fd = open ("/dev/vga_arbiter", O_RDWR)) < 0) {
fprintf(stderr, "device open failed");
return errno;
}
@@ -48,9 +48,9 @@ pci_device_vgaarb_init(struct pci_device *dev)
}
void
-pci_device_vgaarb_fini(struct pci_device *dev)
+pci_device_vgaarb_fini(void)
{
- if (close(dev->vgaarb_fd) != 0)
+ if (close(pci_sys->vgaarb_fd) != 0)
fprintf(stderr, "device close failed");
}
@@ -96,6 +96,35 @@ vgaarb_write(int fd, char *buf, int len)
return 0;
}
+static int
+parse_string_to_decodes_rsrc(char *input)
+{
+ char *tok;
+
+ tok = strtok(input, ",");
+ if (!tok)
+ goto fail;
+
+ tok = strtok(NULL, ",");
+ if (!tok)
+ goto fail;
+ tok = strtok(tok, "=");
+ if (!tok)
+ goto fail;
+ tok = strtok(NULL, "=");
+ if (!tok)
+ goto fail;
+
+ if (!strncmp(tok, "io+mem", 6))
+ return VGA_ARB_RSRC_LEGACY_IO | VGA_ARB_RSRC_LEGACY_MEM;
+ if (!strncmp(tok, "io", 2))
+ return VGA_ARB_RSRC_LEGACY_IO;
+ if (!strncmp(tok, "mem", 3))
+ return VGA_ARB_RSRC_LEGACY_MEM;
+fail:
+ return VGA_ARB_RSRC_NONE;
+}
+
static const char *
rsrc_to_str(int iostate)
{
@@ -116,11 +145,21 @@ pci_device_vgaarb_set_target(struct pci_device *dev)
{
int len;
char buf[BUFSIZE];
+ int ret;
len = snprintf(buf, BUFSIZE, "target PCI:%d:%d:%d.%d",
dev->domain, dev->bus, dev->dev, dev->func);
- return vgaarb_write(dev->vgaarb_fd, buf, len);
+ ret = vgaarb_write(pci_sys->vgaarb_fd, buf, len);
+ if (ret)
+ return ret;
+
+ ret = read(pci_sys->vgaarb_fd, buf, BUFSIZE);
+ if (ret <= 0)
+ return -1;
+
+ dev->vgaarb_rsrc = parse_string_to_decodes_rsrc(buf);
+ return 0;
}
int
@@ -131,7 +170,7 @@ pci_device_vgaarb_decodes(struct pci_device *dev)
len = snprintf(buf, BUFSIZE, "decodes %s", rsrc_to_str(dev->vgaarb_rsrc));
- return vgaarb_write(dev->vgaarb_fd, buf, len);
+ return vgaarb_write(pci_sys->vgaarb_fd, buf, len);
}
int
@@ -142,7 +181,7 @@ pci_device_vgaarb_lock(struct pci_device *dev)
len = snprintf(buf, BUFSIZE, "lock %s", rsrc_to_str(dev->vgaarb_rsrc));
- return vgaarb_write(dev->vgaarb_fd, buf, len);
+ return vgaarb_write(pci_sys->vgaarb_fd, buf, len);
}
int
@@ -153,7 +192,7 @@ pci_device_vgaarb_trylock(struct pci_device *dev)
len = snprintf(buf, BUFSIZE, "trylock %s", rsrc_to_str(dev->vgaarb_rsrc));
- return vgaarb_write(dev->vgaarb_fd, buf, len);
+ return vgaarb_write(pci_sys->vgaarb_fd, buf, len);
}
int
@@ -164,5 +203,5 @@ pci_device_vgaarb_unlock(struct pci_device *dev)
len = snprintf(buf, BUFSIZE, "unlock %s", rsrc_to_str(dev->vgaarb_rsrc));
- return vgaarb_write(dev->vgaarb_fd, buf, len);
+ return vgaarb_write(pci_sys->vgaarb_fd, buf, len);
}
diff --git a/src/pciaccess_private.h b/src/pciaccess_private.h
index 769e181..220673d 100644
--- a/src/pciaccess_private.h
+++ b/src/pciaccess_private.h
@@ -131,6 +131,7 @@ struct pci_system {
#ifdef HAVE_MTRR
int mtrr_fd;
#endif
+ int vgaarb_fd;
};
extern struct pci_system * pci_sys;