root / hw / pcie_port.c @ a1bc20df
History | View | Annotate | Download (3.1 kB)
1 |
/*
|
---|---|
2 |
* pcie_port.c
|
3 |
*
|
4 |
* Copyright (c) 2010 Isaku Yamahata <yamahata at valinux co jp>
|
5 |
* VA Linux Systems Japan K.K.
|
6 |
*
|
7 |
* This program is free software; you can redistribute it and/or modify
|
8 |
* it under the terms of the GNU General Public License as published by
|
9 |
* the Free Software Foundation; either version 2 of the License, or
|
10 |
* (at your option) any later version.
|
11 |
*
|
12 |
* This program is distributed in the hope that it will be useful,
|
13 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
14 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
15 |
* GNU General Public License for more details.
|
16 |
*
|
17 |
* You should have received a copy of the GNU General Public License along
|
18 |
* with this program; if not, see <http://www.gnu.org/licenses/>.
|
19 |
*/
|
20 |
|
21 |
#include "pcie_port.h" |
22 |
|
23 |
void pcie_port_init_reg(PCIDevice *d)
|
24 |
{ |
25 |
/* Unlike pci bridge,
|
26 |
66MHz and fast back to back don't apply to pci express port. */
|
27 |
pci_set_word(d->config + PCI_STATUS, 0);
|
28 |
pci_set_word(d->config + PCI_SEC_STATUS, 0);
|
29 |
|
30 |
/* Unlike conventional pci bridge, some bits are hardwired to 0. */
|
31 |
pci_set_word(d->wmask + PCI_BRIDGE_CONTROL, |
32 |
PCI_BRIDGE_CTL_PARITY | |
33 |
PCI_BRIDGE_CTL_ISA | |
34 |
PCI_BRIDGE_CTL_VGA | |
35 |
PCI_BRIDGE_CTL_SERR | |
36 |
PCI_BRIDGE_CTL_BUS_RESET); |
37 |
} |
38 |
|
39 |
/**************************************************************************
|
40 |
* (chassis number, pcie physical slot number) -> pcie slot conversion
|
41 |
*/
|
42 |
struct PCIEChassis {
|
43 |
uint8_t number; |
44 |
|
45 |
QLIST_HEAD(, PCIESlot) slots; |
46 |
QLIST_ENTRY(PCIEChassis) next; |
47 |
}; |
48 |
|
49 |
static QLIST_HEAD(, PCIEChassis) chassis = QLIST_HEAD_INITIALIZER(chassis);
|
50 |
|
51 |
static struct PCIEChassis *pcie_chassis_find(uint8_t chassis_number) |
52 |
{ |
53 |
struct PCIEChassis *c;
|
54 |
QLIST_FOREACH(c, &chassis, next) { |
55 |
if (c->number == chassis_number) {
|
56 |
break;
|
57 |
} |
58 |
} |
59 |
return c;
|
60 |
} |
61 |
|
62 |
void pcie_chassis_create(uint8_t chassis_number)
|
63 |
{ |
64 |
struct PCIEChassis *c;
|
65 |
c = pcie_chassis_find(chassis_number); |
66 |
if (c) {
|
67 |
return;
|
68 |
} |
69 |
c = g_malloc0(sizeof(*c));
|
70 |
c->number = chassis_number; |
71 |
QLIST_INIT(&c->slots); |
72 |
QLIST_INSERT_HEAD(&chassis, c, next); |
73 |
} |
74 |
|
75 |
static PCIESlot *pcie_chassis_find_slot_with_chassis(struct PCIEChassis *c, |
76 |
uint8_t slot) |
77 |
{ |
78 |
PCIESlot *s; |
79 |
QLIST_FOREACH(s, &c->slots, next) { |
80 |
if (s->slot == slot) {
|
81 |
break;
|
82 |
} |
83 |
} |
84 |
return s;
|
85 |
} |
86 |
|
87 |
PCIESlot *pcie_chassis_find_slot(uint8_t chassis_number, uint16_t slot) |
88 |
{ |
89 |
struct PCIEChassis *c;
|
90 |
c = pcie_chassis_find(chassis_number); |
91 |
if (!c) {
|
92 |
return NULL; |
93 |
} |
94 |
return pcie_chassis_find_slot_with_chassis(c, slot);
|
95 |
} |
96 |
|
97 |
int pcie_chassis_add_slot(struct PCIESlot *slot) |
98 |
{ |
99 |
struct PCIEChassis *c;
|
100 |
c = pcie_chassis_find(slot->chassis); |
101 |
if (!c) {
|
102 |
return -ENODEV;
|
103 |
} |
104 |
if (pcie_chassis_find_slot_with_chassis(c, slot->slot)) {
|
105 |
return -EBUSY;
|
106 |
} |
107 |
QLIST_INSERT_HEAD(&c->slots, slot, next); |
108 |
return 0; |
109 |
} |
110 |
|
111 |
void pcie_chassis_del_slot(PCIESlot *s)
|
112 |
{ |
113 |
QLIST_REMOVE(s, next); |
114 |
} |