1 // SPDX-License-Identifier: GPL-2.0
5 * For architectures where we want to allow direct access
6 * to the PCI config stuff - it would probably be preferable
7 * on PCs too, but there people just do it by hand with the
8 * magic northbridge registers..
11 #include <linux/errno.h>
12 #include <linux/pci.h>
13 #include <linux/syscalls.h>
14 #include <linux/uaccess.h>
17 SYSCALL_DEFINE5(pciconfig_read
, unsigned long, bus
, unsigned long, dfn
,
18 unsigned long, off
, unsigned long, len
, void __user
*, buf
)
27 if (!capable(CAP_SYS_ADMIN
))
31 dev
= pci_get_domain_bus_and_slot(0, bus
, dfn
);
37 cfg_ret
= pci_user_read_config_byte(dev
, off
, &byte
);
40 cfg_ret
= pci_user_read_config_word(dev
, off
, &word
);
43 cfg_ret
= pci_user_read_config_dword(dev
, off
, &dword
);
51 if (cfg_ret
!= PCIBIOS_SUCCESSFUL
)
56 err
= put_user(byte
, (unsigned char __user
*)buf
);
59 err
= put_user(word
, (unsigned short __user
*)buf
);
62 err
= put_user(dword
, (unsigned int __user
*)buf
);
69 /* ??? XFree86 doesn't even check the return value. They
70 just look for 0xffffffff in the output, since that's what
71 they get instead of a machine check on x86. */
74 put_user(-1, (unsigned char __user
*)buf
);
77 put_user(-1, (unsigned short __user
*)buf
);
80 put_user(-1, (unsigned int __user
*)buf
);
87 SYSCALL_DEFINE5(pciconfig_write
, unsigned long, bus
, unsigned long, dfn
,
88 unsigned long, off
, unsigned long, len
, void __user
*, buf
)
96 if (!capable(CAP_SYS_ADMIN
))
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
);
109 if (err
!= PCIBIOS_SUCCESSFUL
)
114 err
= get_user(word
, (u16 __user
*)buf
);
117 err
= pci_user_write_config_word(dev
, off
, word
);
118 if (err
!= PCIBIOS_SUCCESSFUL
)
123 err
= get_user(dword
, (u32 __user
*)buf
);
126 err
= pci_user_write_config_dword(dev
, off
, dword
);
127 if (err
!= PCIBIOS_SUCCESSFUL
)