summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDave Airlie <airlied@redhat.com>2009-07-20 13:26:41 +1000
committerDave Airlie <airlied@redhat.com>2009-07-20 13:32:20 +1000
commite360c11c37a219534bfd7266caf163870dddced0 (patch)
tree6940a9ed566d4c44e2114f5ccd3fc23892a70832 /src
parent5d1bdf0cb51c19efd6e2b2c0a463ace9443c48d9 (diff)
vgaarb: fixup api for new count reporting + decodes interface was wrong.
decodes is a information setting interface so it takes new decodes and sends them to the kernel
Diffstat (limited to 'src')
-rw-r--r--src/common_vgaarb.c48
-rw-r--r--src/pciaccess_private.h1
2 files changed, 43 insertions, 6 deletions
diff --git a/src/common_vgaarb.c b/src/common_vgaarb.c
index 232d4ac..55b3868 100644
--- a/src/common_vgaarb.c
+++ b/src/common_vgaarb.c
@@ -30,11 +30,13 @@
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
+#include <stdlib.h>
+#include <limits.h>
#include "pciaccess.h"
#include "pciaccess_private.h"
-#define BUFSIZE 32
+#define BUFSIZE 64
int
pci_device_vgaarb_init(void)
@@ -97,9 +99,28 @@ vgaarb_write(int fd, char *buf, int len)
}
static int
-parse_string_to_decodes_rsrc(char *input)
+parse_string_to_decodes_rsrc(char *input, int *vga_count)
{
char *tok;
+ char count[16];
+
+ strncpy(count, input, 10);
+ count[11] = 0;
+
+ tok = strtok(count,":");
+ if (!tok)
+ goto fail;
+ tok = strtok(NULL, "");
+ if (!tok)
+ goto fail;
+
+ *vga_count = strtoul(tok, NULL, 10);
+ if (*vga_count == LONG_MAX)
+ goto fail;
+
+#ifdef DEBUG
+ fprintf(stderr,"vga count is %d\n", *vga_count);
+#endif
tok = strtok(input, ",");
if (!tok)
@@ -158,19 +179,25 @@ pci_device_vgaarb_set_target(struct pci_device *dev)
if (ret <= 0)
return -1;
- dev->vgaarb_rsrc = parse_string_to_decodes_rsrc(buf);
+ dev->vgaarb_rsrc = parse_string_to_decodes_rsrc(buf, &pci_sys->vga_count);
return 0;
}
int
-pci_device_vgaarb_decodes(struct pci_device *dev)
+pci_device_vgaarb_decodes(struct pci_device *dev, int new_vgaarb_rsrc)
{
int len;
char buf[BUFSIZE];
+ int ret;
- len = snprintf(buf, BUFSIZE, "decodes %s", rsrc_to_str(dev->vgaarb_rsrc));
+ if (dev->vgaarb_rsrc == new_vgaarb_rsrc)
+ return 0;
- return vgaarb_write(pci_sys->vgaarb_fd, buf, len);
+ len = snprintf(buf, BUFSIZE, "decodes %s", rsrc_to_str(dev->vgaarb_rsrc));
+ ret = vgaarb_write(pci_sys->vgaarb_fd, buf, len);
+ if (ret == 0)
+ dev->vgaarb_rsrc = new_vgaarb_rsrc;
+ return ret;
}
int
@@ -179,6 +206,9 @@ pci_device_vgaarb_lock(struct pci_device *dev)
int len;
char buf[BUFSIZE];
+ if (dev->vgaarb_rsrc == 0 || pci_sys->vga_count == 1)
+ return 0;
+
len = snprintf(buf, BUFSIZE, "lock %s", rsrc_to_str(dev->vgaarb_rsrc));
return vgaarb_write(pci_sys->vgaarb_fd, buf, len);
@@ -190,6 +220,9 @@ pci_device_vgaarb_trylock(struct pci_device *dev)
int len;
char buf[BUFSIZE];
+ if (dev->vgaarb_rsrc == 0 || pci_sys->vga_count == 1)
+ return 0;
+
len = snprintf(buf, BUFSIZE, "trylock %s", rsrc_to_str(dev->vgaarb_rsrc));
return vgaarb_write(pci_sys->vgaarb_fd, buf, len);
@@ -201,6 +234,9 @@ pci_device_vgaarb_unlock(struct pci_device *dev)
int len;
char buf[BUFSIZE];
+ if (dev->vgaarb_rsrc == 0 || pci_sys->vga_count == 1)
+ return 0;
+
len = snprintf(buf, BUFSIZE, "unlock %s", rsrc_to_str(dev->vgaarb_rsrc));
return vgaarb_write(pci_sys->vgaarb_fd, buf, len);
diff --git a/src/pciaccess_private.h b/src/pciaccess_private.h
index a45fa8f..b97d31b 100644
--- a/src/pciaccess_private.h
+++ b/src/pciaccess_private.h
@@ -133,6 +133,7 @@ struct pci_system {
int mtrr_fd;
#endif
int vgaarb_fd;
+ int vga_count;
};
extern struct pci_system * pci_sys;