Blame view
drivers/pci/syscall.c
2.64 KB
1da177e4c Linux-2.6.12-rc2 |
1 2 3 4 5 6 7 8 |
/* * pci_syscall.c * * For architectures where we want to allow direct access * to the PCI config stuff - it would probably be preferable * on PCs too, but there people just do it by hand with the * magic northbridge registers.. */ |
1da177e4c Linux-2.6.12-rc2 |
9 10 |
#include <linux/errno.h> #include <linux/pci.h> |
1da177e4c Linux-2.6.12-rc2 |
11 12 |
#include <linux/syscalls.h> #include <asm/uaccess.h> |
e04b0ea2e [PATCH] PCI: Bloc... |
13 |
#include "pci.h" |
1da177e4c Linux-2.6.12-rc2 |
14 |
|
c4ea37c26 [CVE-2009-0029] S... |
15 16 |
SYSCALL_DEFINE5(pciconfig_read, unsigned long, bus, unsigned long, dfn, unsigned long, off, unsigned long, len, void __user *, buf) |
1da177e4c Linux-2.6.12-rc2 |
17 18 19 20 21 |
{ struct pci_dev *dev; u8 byte; u16 word; u32 dword; |
e4585da22 pci syscall.c: Sw... |
22 23 |
long err; long cfg_ret; |
1da177e4c Linux-2.6.12-rc2 |
24 |
|
1da177e4c Linux-2.6.12-rc2 |
25 |
if (!capable(CAP_SYS_ADMIN)) |
e4585da22 pci syscall.c: Sw... |
26 |
return -EPERM; |
1da177e4c Linux-2.6.12-rc2 |
27 28 |
err = -ENODEV; |
e4585da22 pci syscall.c: Sw... |
29 |
dev = pci_get_bus_and_slot(bus, dfn); |
1da177e4c Linux-2.6.12-rc2 |
30 31 |
if (!dev) goto error; |
1da177e4c Linux-2.6.12-rc2 |
32 33 |
switch (len) { case 1: |
e04b0ea2e [PATCH] PCI: Bloc... |
34 |
cfg_ret = pci_user_read_config_byte(dev, off, &byte); |
1da177e4c Linux-2.6.12-rc2 |
35 36 |
break; case 2: |
e04b0ea2e [PATCH] PCI: Bloc... |
37 |
cfg_ret = pci_user_read_config_word(dev, off, &word); |
1da177e4c Linux-2.6.12-rc2 |
38 39 |
break; case 4: |
e04b0ea2e [PATCH] PCI: Bloc... |
40 |
cfg_ret = pci_user_read_config_dword(dev, off, &dword); |
1da177e4c Linux-2.6.12-rc2 |
41 42 43 |
break; default: err = -EINVAL; |
1da177e4c Linux-2.6.12-rc2 |
44 45 |
goto error; }; |
1da177e4c Linux-2.6.12-rc2 |
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
err = -EIO; if (cfg_ret != PCIBIOS_SUCCESSFUL) goto error; switch (len) { case 1: err = put_user(byte, (unsigned char __user *)buf); break; case 2: err = put_user(word, (unsigned short __user *)buf); break; case 4: err = put_user(dword, (unsigned int __user *)buf); break; |
e4585da22 pci syscall.c: Sw... |
61 62 |
} pci_dev_put(dev); |
1da177e4c Linux-2.6.12-rc2 |
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
return err; error: /* ??? XFree86 doesn't even check the return value. They just look for 0xffffffff in the output, since that's what they get instead of a machine check on x86. */ switch (len) { case 1: put_user(-1, (unsigned char __user *)buf); break; case 2: put_user(-1, (unsigned short __user *)buf); break; case 4: put_user(-1, (unsigned int __user *)buf); break; |
e4585da22 pci syscall.c: Sw... |
79 80 |
} pci_dev_put(dev); |
1da177e4c Linux-2.6.12-rc2 |
81 82 |
return err; } |
c4ea37c26 [CVE-2009-0029] S... |
83 84 |
SYSCALL_DEFINE5(pciconfig_write, unsigned long, bus, unsigned long, dfn, unsigned long, off, unsigned long, len, void __user *, buf) |
1da177e4c Linux-2.6.12-rc2 |
85 86 87 88 89 90 91 92 93 |
{ struct pci_dev *dev; u8 byte; u16 word; u32 dword; int err = 0; if (!capable(CAP_SYS_ADMIN)) return -EPERM; |
e4585da22 pci syscall.c: Sw... |
94 |
dev = pci_get_bus_and_slot(bus, dfn); |
1da177e4c Linux-2.6.12-rc2 |
95 96 |
if (!dev) return -ENODEV; |
1da177e4c Linux-2.6.12-rc2 |
97 98 99 100 101 |
switch(len) { case 1: err = get_user(byte, (u8 __user *)buf); if (err) break; |
e04b0ea2e [PATCH] PCI: Bloc... |
102 |
err = pci_user_write_config_byte(dev, off, byte); |
1da177e4c Linux-2.6.12-rc2 |
103 104 105 106 107 108 109 110 |
if (err != PCIBIOS_SUCCESSFUL) err = -EIO; break; case 2: err = get_user(word, (u16 __user *)buf); if (err) break; |
e04b0ea2e [PATCH] PCI: Bloc... |
111 |
err = pci_user_write_config_word(dev, off, word); |
1da177e4c Linux-2.6.12-rc2 |
112 113 114 115 116 117 118 119 |
if (err != PCIBIOS_SUCCESSFUL) err = -EIO; break; case 4: err = get_user(dword, (u32 __user *)buf); if (err) break; |
e04b0ea2e [PATCH] PCI: Bloc... |
120 |
err = pci_user_write_config_dword(dev, off, dword); |
1da177e4c Linux-2.6.12-rc2 |
121 122 123 124 125 126 127 |
if (err != PCIBIOS_SUCCESSFUL) err = -EIO; break; default: err = -EINVAL; break; |
e4585da22 pci syscall.c: Sw... |
128 |
} |
e4585da22 pci syscall.c: Sw... |
129 |
pci_dev_put(dev); |
1da177e4c Linux-2.6.12-rc2 |
130 131 |
return err; } |