1 // SPDX-License-Identifier: GPL-2.0
3 * For architectures where we want to allow direct access to the PCI config
4 * stuff - it would probably be preferable on PCs too, but there people
5 * just do it by hand with the magic northbridge registers.
8 #include <linux/errno.h>
10 #include <linux/security.h>
11 #include <linux/syscalls.h>
12 #include <linux/uaccess.h>
15 SYSCALL_DEFINE5(pciconfig_read, unsigned long, bus, unsigned long, dfn,
16 unsigned long, off, unsigned long, len, void __user *, buf)
26 if (!capable(CAP_SYS_ADMIN))
30 dev = pci_get_domain_bus_and_slot(0, bus, dfn);
36 cfg_ret = pci_user_read_config_byte(dev, off, &byte);
39 cfg_ret = pci_user_read_config_word(dev, off, &word);
42 cfg_ret = pci_user_read_config_dword(dev, off, &dword);
55 err = put_user(byte, (u8 __user *)buf);
58 err = put_user(word, (u16 __user *)buf);
61 err = put_user(dword, (u32 __user *)buf);
68 /* ??? XFree86 doesn't even check the return value. They
69 just look for 0xffffffff in the output, since that's what
70 they get instead of a machine check on x86. */
73 put_user(-1, (u8 __user *)buf);
76 put_user(-1, (u16 __user *)buf);
79 put_user(-1, (u32 __user *)buf);
86 SYSCALL_DEFINE5(pciconfig_write, unsigned long, bus, unsigned long, dfn,
87 unsigned long, off, unsigned long, len, void __user *, buf)
95 if (!capable(CAP_SYS_ADMIN) ||
96 security_locked_down(LOCKDOWN_PCI_ACCESS))
99 dev = pci_get_domain_bus_and_slot(0, bus, dfn);
105 err = get_user(byte, (u8 __user *)buf);
108 err = pci_user_write_config_byte(dev, off, byte);
114 err = get_user(word, (u16 __user *)buf);
117 err = pci_user_write_config_word(dev, off, word);
123 err = get_user(dword, (u32 __user *)buf);
126 err = pci_user_write_config_dword(dev, off, dword);