~ubuntu-branches/ubuntu/utopic/xen/utopic

« back to all changes in this revision

Viewing changes to xen/arch/ia64/xen/pci.c

  • Committer: Bazaar Package Importer
  • Author(s): Bastian Blank
  • Date: 2010-05-06 15:47:38 UTC
  • mto: (1.3.1) (15.1.1 sid) (4.1.1 experimental)
  • mto: This revision was merged to the branch mainline in revision 3.
  • Revision ID: james.westby@ubuntu.com-20100506154738-agoz0rlafrh1fnq7
Tags: upstream-4.0.0
ImportĀ upstreamĀ versionĀ 4.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * pci.c - Low-Level PCI Access in IA-64
 
3
 *
 
4
 * Derived from bios32.c of i386 tree.
 
5
 *
 
6
 * (c) Copyright 2002, 2005 Hewlett-Packard Development Company, L.P.
 
7
 *  David Mosberger-Tang <davidm@hpl.hp.com>
 
8
 * Bjorn Helgaas <bjorn.helgaas@hp.com>
 
9
 * Copyright (C) 2004 Silicon Graphics, Inc.
 
10
 *
 
11
 * Note: Above list of copyright holders is incomplete...
 
12
 */
 
13
 
 
14
#include <xen/pci.h>
 
15
#include <xen/pci_regs.h>
 
16
#include <xen/spinlock.h>
 
17
 
 
18
#include <asm/io.h>
 
19
#include <asm/sal.h>
 
20
#include <asm/hw_irq.h>
 
21
 
 
22
/*
 
23
 * Low-level SAL-based PCI configuration access functions. Note that SAL
 
24
 * calls are already serialized (via sal_lock), so we don't need another
 
25
 * synchronization mechanism here.
 
26
 */
 
27
 
 
28
#define PCI_SAL_ADDRESS(seg, bus, devfn, reg)       \
 
29
    (((u64) seg << 24) | (bus << 16) | (devfn << 8) | (reg))
 
30
 
 
31
/* SAL 3.2 adds support for extended config space. */
 
32
 
 
33
#define PCI_SAL_EXT_ADDRESS(seg, bus, devfn, reg)   \
 
34
    (((u64) seg << 28) | (bus << 20) | (devfn << 12) | (reg))
 
35
 
 
36
static int
 
37
pci_sal_read (unsigned int seg, unsigned int bus, unsigned int devfn,
 
38
        int reg, int len, u32 *value)
 
39
{
 
40
    u64 addr, data = 0;
 
41
    int mode, result;
 
42
 
 
43
    if (!value || (seg > 65535) || (bus > 255) || (devfn > 255) || (reg > 4095))
 
44
        return -EINVAL;
 
45
 
 
46
    if ((seg | reg) <= 255) {
 
47
        addr = PCI_SAL_ADDRESS(seg, bus, devfn, reg);
 
48
        mode = 0;
 
49
    } else {
 
50
        addr = PCI_SAL_EXT_ADDRESS(seg, bus, devfn, reg);
 
51
        mode = 1;
 
52
    }
 
53
    result = ia64_sal_pci_config_read(addr, mode, len, &data);
 
54
    if (result != 0)
 
55
        return -EINVAL;
 
56
 
 
57
    *value = (u32) data;
 
58
    return 0;
 
59
}
 
60
 
 
61
static int
 
62
pci_sal_write (unsigned int seg, unsigned int bus, unsigned int devfn,
 
63
        int reg, int len, u32 value)
 
64
{
 
65
    u64 addr;
 
66
    int mode, result;
 
67
 
 
68
    if ((seg > 65535) || (bus > 255) || (devfn > 255) || (reg > 4095))
 
69
        return -EINVAL;
 
70
 
 
71
    if ((seg | reg) <= 255) {
 
72
        addr = PCI_SAL_ADDRESS(seg, bus, devfn, reg);
 
73
        mode = 0;
 
74
    } else {
 
75
        addr = PCI_SAL_EXT_ADDRESS(seg, bus, devfn, reg);
 
76
        mode = 1;
 
77
    }
 
78
    result = ia64_sal_pci_config_write(addr, mode, len, value);
 
79
    if (result != 0)
 
80
        return -EINVAL;
 
81
    return 0;
 
82
}
 
83
 
 
84
 
 
85
uint8_t pci_conf_read8(
 
86
    unsigned int bus, unsigned int dev, unsigned int func, unsigned int reg)
 
87
{
 
88
    uint32_t value;
 
89
    BUG_ON((bus > 255) || (dev > 31) || (func > 7) || (reg > 255));
 
90
    pci_sal_read(0, bus, (dev<<3)|func, reg, 1, &value);
 
91
    return (uint8_t)value;
 
92
}
 
93
 
 
94
uint16_t pci_conf_read16(
 
95
    unsigned int bus, unsigned int dev, unsigned int func, unsigned int reg)
 
96
{
 
97
    uint32_t value;
 
98
    BUG_ON((bus > 255) || (dev > 31) || (func > 7) || (reg > 255));
 
99
    pci_sal_read(0, bus, (dev<<3)|func, reg, 2, &value);
 
100
    return (uint16_t)value;
 
101
}
 
102
 
 
103
uint32_t pci_conf_read32(
 
104
    unsigned int bus, unsigned int dev, unsigned int func, unsigned int reg)
 
105
{
 
106
    uint32_t value;
 
107
    BUG_ON((bus > 255) || (dev > 31) || (func > 7) || (reg > 255));
 
108
    pci_sal_read(0, bus, (dev<<3)|func, reg, 4, &value);
 
109
    return (uint32_t)value;
 
110
}
 
111
 
 
112
void pci_conf_write8(
 
113
    unsigned int bus, unsigned int dev, unsigned int func, unsigned int reg,
 
114
    uint8_t data)
 
115
{
 
116
    BUG_ON((bus > 255) || (dev > 31) || (func > 7) || (reg > 255));
 
117
    pci_sal_write(0, bus, (dev<<3)|func, reg, 1, data);
 
118
}
 
119
 
 
120
void pci_conf_write16(
 
121
    unsigned int bus, unsigned int dev, unsigned int func, unsigned int reg,
 
122
    uint16_t data)
 
123
{
 
124
    BUG_ON((bus > 255) || (dev > 31) || (func > 7) || (reg > 255));
 
125
    pci_sal_write(0, bus, (dev<<3)|func, reg, 2, data);
 
126
}
 
127
 
 
128
void pci_conf_write32(
 
129
    unsigned int bus, unsigned int dev, unsigned int func, unsigned int reg,
 
130
    uint32_t data)
 
131
{
 
132
    BUG_ON((bus > 255) || (dev > 31) || (func > 7) || (reg > 255));
 
133
    pci_sal_write(0, bus, (dev<<3)|func, reg, 4, data);
 
134
}
 
135
 
 
136
int pci_find_ext_capability(int seg, int bus, int devfn, int cap)
 
137
{
 
138
    return 0;
 
139
}