linux/drivers/pci/syscall.c
<<
>>
Prefs
   1/*
   2 *      pci_syscall.c
   3 *
   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..
   8 */
   9
  10#include <linux/errno.h>
  11#include <linux/pci.h>
  12#include <linux/syscalls.h>
  13#include <asm/uaccess.h>
  14#include "pci.h"
  15
  16SYSCALL_DEFINE5(pciconfig_read, unsigned long, bus, unsigned long, dfn,
  17                unsigned long, off, unsigned long, len, void __user *, buf)
  18{
  19        struct pci_dev *dev;
  20        u8 byte;
  21        u16 word;
  22        u32 dword;
  23        long err;
  24        long cfg_ret;
  25
  26        if (!capable(CAP_SYS_ADMIN))
  27                return -EPERM;
  28
  29        err = -ENODEV;
  30        dev = pci_get_bus_and_slot(bus, dfn);
  31        if (!dev)
  32                goto error;
  33
  34        switch (len) {
  35        case 1:
  36                cfg_ret = pci_user_read_config_byte(dev, off, &byte);
  37                break;
  38        case 2:
  39                cfg_ret = pci_user_read_config_word(dev, off, &word);
  40                break;
  41        case 4:
  42                cfg_ret = pci_user_read_config_dword(dev, off, &dword);
  43                break;
  44        default:
  45                err = -EINVAL;
  46                goto error;
  47        };
  48
  49        err = -EIO;
  50        if (cfg_ret != PCIBIOS_SUCCESSFUL)
  51                goto error;
  52
  53        switch (len) {
  54        case 1:
  55                err = put_user(byte, (unsigned char __user *)buf);
  56                break;
  57        case 2:
  58                err = put_user(word, (unsigned short __user *)buf);
  59                break;
  60        case 4:
  61                err = put_user(dword, (unsigned int __user *)buf);
  62                break;
  63        }
  64        pci_dev_put(dev);
  65        return err;
  66
  67error:
  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.  */
  71        switch (len) {
buf);
err = byte, (unsigned char __user *)buf);
  62                break;
  57        case 2:
  36     >err = word, (unsigned short __user *)buf);
  37                break;
  60        case 4:
  39     >err = dword, (unsigned int __user *)buf);
  40                break;
  63        }

  22        pci_dev_put(dev);
  65        return err;
  63        }
  25
  16SYSCALL_DEFINE5wride=pci_user_read_conNE5wride=dwordsref">pciconfig_read, unsigned long, bus, unsigned long, dfn,
  17                unsigned long, off, unsigned long, len, void __user *, buf)
  18{
  19        struct pci_dev *dev;
  20        u8 byte;
  21        u16 word;

  22        u32 dword;
dword, (un           dword;
  25
  26        if (!capable(CAP_SYS_ADMIN))
  27                return -EPERM;
  25
  22        dev = pci_get_bus_and_slot(bus, dfn);
  26        if (!dev)
  27              rr = -ENODEV;
  25
  71        switch (len) {
);
  61                , void put_user(  20        __user *)buf);
  50            dev)
  40                break;
  61                nfig_dwowride href="+code=pci_user_read_config_bywride href="+code" class="sref">pci_dev_put(put_user(buf);
  50            cfg_ret != PCIBIOS_SUCCESSFUL)
  61                err = -EIO;
  40                break;
  25
buf  57        case 2:
, void put_user(  21        __user *)buf);
  50            dev)
  40                break;
  36                nfig_dwowride href="+ode=pci_user_read_config_dwowride href="+ode=" class="sref">pci_dev_put(pu, &word);
  50            cfg_ret != PCIBIOS_SUCCESSFUL)
  61                err = -EIO;
  59                break;
                break;
  41        case 4:
, void put_user(  22        __user *)buf);
  50            dev)
  59                break;
  55                nfig_dwowride href="+code=pci_user_read_config_dwowride href="+code=" class="sref">pci_dev_put(pu, &dword);
  50            cfg_ret != PCIBIOS_SUCCESSFUL)
  61                err = -EIO;
  59                break;
   9
  44        default:
  61                err = -EINVAL;
  59                break;
  63        }
  64        pci_dev_put(dev);
  65        return err;
  63        }

Tt loriginal LXR softwareut tst le="L63"> http://sourceforge.net/projects/lxd >LXR L70"unitycode=onsub experi">  al v2.6t te="L63"> mailto:lxd@lsysc.no">lxd@lsysc.nocode.
search_esulti/syscasubfooted >
lxd.lsysc.no kindly hosted6t te="L63"> http://www.redpill-lsypro.no">Redpill Lsypro AScode=oprovider    Lsyscss="_resing ere opera    s _dwvices 0xffff1995.
search_re/bodyh_e/htmlla