4 * For architectures where we want to allow direct access
5 * to the PCI config stuff - it would probably be preferable
6 * on PCs too, but there people just do it by hand with the
7 * magic northbridge registers..
10 #include <linux/sched.h>
11 #include <linux/errno.h>
12 #include <linux/pci.h>
13 #include <linux/smp_lock.h>
14 #include <asm/uaccess.h>
18 sys_pciconfig_read(unsigned long bus
, unsigned long dfn
,
19 unsigned long off
, unsigned long len
, void *buf
)
28 if (!capable(CAP_SYS_ADMIN
))
32 dev
= pci_find_slot(bus
, dfn
);
39 cfg_ret
= pci_read_config_byte(dev
, off
, &byte
);
42 cfg_ret
= pci_read_config_word(dev
, off
, &word
);
45 cfg_ret
= pci_read_config_dword(dev
, off
, &dword
);
55 if (cfg_ret
!= PCIBIOS_SUCCESSFUL
)
60 err
= put_user(byte
, (unsigned char *)buf
);
63 err
= put_user(word
, (unsigned short *)buf
);
66 err
= put_user(dword
, (unsigned int *)buf
);
72 /* ??? XFree86 doesn't even check the return value. They
73 just look for 0xffffffff in the output, since that's what
74 they get instead of a machine check on x86. */
77 put_user(-1, (unsigned char *)buf
);
80 put_user(-1, (unsigned short *)buf
);
83 put_user(-1, (unsigned int *)buf
);
90 sys_pciconfig_write(unsigned long bus
, unsigned long dfn
,
91 unsigned long off
, unsigned long len
, void *buf
)
99 if (!capable(CAP_SYS_ADMIN
))
101 if (!pcibios_present())
104 dev
= pci_find_slot(bus
, dfn
);
111 err
= get_user(byte
, (u8
*)buf
);
114 err
= pci_write_config_byte(dev
, off
, byte
);
115 if (err
!= PCIBIOS_SUCCESSFUL
)
120 err
= get_user(word
, (u16
*)buf
);
123 err
= pci_write_config_byte(dev
, off
, word
);
124 if (err
!= PCIBIOS_SUCCESSFUL
)
129 err
= get_user(dword
, (u32
*)buf
);
132 pci_write_config_byte(dev
, off
, dword
);
133 if (err
!= PCIBIOS_SUCCESSFUL
)