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/syscalls.h>
11 #include <linux/uaccess.h>
14 SYSCALL_DEFINE5(pciconfig_read
, unsigned long, bus
, unsigned long, dfn
,
15 unsigned long, off
, unsigned long, len
, void __user
*, buf
)
24 if (!capable(CAP_SYS_ADMIN
))
28 dev
= pci_get_domain_bus_and_slot(0, bus
, dfn
);
34 cfg_ret
= pci_user_read_config_byte(dev
, off
, &byte
);
37 cfg_ret
= pci_user_read_config_word(dev
, off
, &word
);
40 cfg_ret
= pci_user_read_config_dword(dev
, off
, &dword
);
48 if (cfg_ret
!= PCIBIOS_SUCCESSFUL
)
53 err
= put_user(byte
, (unsigned char __user
*)buf
);
56 err
= put_user(word
, (unsigned short __user
*)buf
);
59 err
= put_user(dword
, (unsigned int __user
*)buf
);
66 /* ??? XFree86 doesn't even check the return value. They
67 just look for 0xffffffff in the output, since that's what
68 they get instead of a machine check on x86. */
71 put_user(-1, (unsigned char __user
*)buf
);
74 put_user(-1, (unsigned short __user
*)buf
);
77 put_user(-1, (unsigned int __user
*)buf
);
84 SYSCALL_DEFINE5(pciconfig_write
, unsigned long, bus
, unsigned long, dfn
,
85 unsigned long, off
, unsigned long, len
, void __user
*, buf
)
93 if (!capable(CAP_SYS_ADMIN
))
96 dev
= pci_get_domain_bus_and_slot(0, bus
, dfn
);
102 err
= get_user(byte
, (u8 __user
*)buf
);
105 err
= pci_user_write_config_byte(dev
, off
, byte
);
106 if (err
!= PCIBIOS_SUCCESSFUL
)
111 err
= get_user(word
, (u16 __user
*)buf
);
114 err
= pci_user_write_config_word(dev
, off
, word
);
115 if (err
!= PCIBIOS_SUCCESSFUL
)
120 err
= get_user(dword
, (u32 __user
*)buf
);
123 err
= pci_user_write_config_dword(dev
, off
, dword
);
124 if (err
!= PCIBIOS_SUCCESSFUL
)