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
)
25 if (!capable(CAP_SYS_ADMIN
))
29 dev
= pci_get_domain_bus_and_slot(0, bus
, dfn
);
35 cfg_ret
= pci_user_read_config_byte(dev
, off
, &byte
);
38 cfg_ret
= pci_user_read_config_word(dev
, off
, &word
);
41 cfg_ret
= pci_user_read_config_dword(dev
, off
, &dword
);
49 if (cfg_ret
!= PCIBIOS_SUCCESSFUL
)
54 err
= put_user(byte
, (unsigned char __user
*)buf
);
57 err
= put_user(word
, (unsigned short __user
*)buf
);
60 err
= put_user(dword
, (unsigned int __user
*)buf
);
67 /* ??? XFree86 doesn't even check the return value. They
68 just look for 0xffffffff in the output, since that's what
69 they get instead of a machine check on x86. */
72 put_user(-1, (unsigned char __user
*)buf
);
75 put_user(-1, (unsigned short __user
*)buf
);
78 put_user(-1, (unsigned int __user
*)buf
);
85 SYSCALL_DEFINE5(pciconfig_write
, unsigned long, bus
, unsigned long, dfn
,
86 unsigned long, off
, unsigned long, len
, void __user
*, buf
)
94 if (!capable(CAP_SYS_ADMIN
) ||
95 security_locked_down(LOCKDOWN_PCI_ACCESS
))
98 dev
= pci_get_domain_bus_and_slot(0, bus
, dfn
);
104 err
= get_user(byte
, (u8 __user
*)buf
);
107 err
= pci_user_write_config_byte(dev
, off
, byte
);
108 if (err
!= PCIBIOS_SUCCESSFUL
)
113 err
= get_user(word
, (u16 __user
*)buf
);
116 err
= pci_user_write_config_word(dev
, off
, word
);
117 if (err
!= PCIBIOS_SUCCESSFUL
)
122 err
= get_user(dword
, (u32 __user
*)buf
);
125 err
= pci_user_write_config_dword(dev
, off
, dword
);
126 if (err
!= PCIBIOS_SUCCESSFUL
)