#include <stdlib.h>
#include <limits.h>
+#include "config.h"
#include "pciaccess.h"
#include "pciaccess_private.h"
parse_string_to_decodes_rsrc(char *input, int *vga_count, struct pci_slot_match *match)
{
char *tok;
- char *input_sp, *count_sp, *pci_sp;
+ char *input_sp = NULL, *count_sp, *pci_sp;
char tmp[32];
tok = strtok_r(input,",",&input_sp);
struct pci_slot_match match;
char buf[BUFSIZE];
int ret, rsrc;
+
+ if (!pci_sys)
+ return -1;
+
if ((pci_sys->vgaarb_fd = open ("/dev/vga_arbiter", O_RDWR)) < 0) {
return errno;
}
void
pci_device_vgaarb_fini(void)
{
+ if (!pci_sys)
+ return;
+
close(pci_sys->vgaarb_fd);
}
if (dev->vgaarb_rsrc == new_vgaarb_rsrc)
return 0;
- len = snprintf(buf, BUFSIZE, "decodes %s", rsrc_to_str(dev->vgaarb_rsrc));
+ len = snprintf(buf, BUFSIZE, "decodes %s", rsrc_to_str(new_vgaarb_rsrc));
ret = vgaarb_write(pci_sys->vgaarb_fd, buf, len);
if (ret == 0)
dev->vgaarb_rsrc = new_vgaarb_rsrc;
+
+ ret = read(pci_sys->vgaarb_fd, buf, BUFSIZE);
+ if (ret <= 0)
+ return -1;
+
+ parse_string_to_decodes_rsrc(buf, &pci_sys->vga_count, NULL);
+
return ret;
}
{
*vga_count = pci_sys->vga_count;
if (!dev)
- return -1;
+ return 0;
*rsrc_decodes = dev->vgaarb_rsrc;
return 0;