4 * Copyright (c) 2010 Isaku Yamahata <yamahata at valinux co jp>
5 * VA Linux Systems Japan K.K.
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.
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.
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/>.
21 #include "pcie_port.h"
23 void pcie_port_init_reg(PCIDevice
*d
)
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);
30 /* Unlike conventional pci bridge, some bits are hardwared to 0. */
31 pci_set_word(d
->wmask
+ PCI_BRIDGE_CONTROL
,
32 PCI_BRIDGE_CTL_PARITY
|
36 PCI_BRIDGE_CTL_BUS_RESET
);
38 /* 7.5.3.5 Prefetchable Memory Base Limit
39 * The Prefetchable Memory Base and Prefetchable Memory Limit registers
40 * must indicate that 64-bit addresses are supported, as defined in
41 * PCI-to-PCI Bridge Architecture Specification, Revision 1.2.
43 pci_word_test_and_set_mask(d
->config
+ PCI_PREF_MEMORY_BASE
,
44 PCI_PREF_RANGE_TYPE_64
);
45 pci_word_test_and_set_mask(d
->config
+ PCI_PREF_MEMORY_LIMIT
,
46 PCI_PREF_RANGE_TYPE_64
);
49 /**************************************************************************
50 * (chassis number, pcie physical slot number) -> pcie slot conversion
55 QLIST_HEAD(, PCIESlot
) slots
;
56 QLIST_ENTRY(PCIEChassis
) next
;
59 static QLIST_HEAD(, PCIEChassis
) chassis
= QLIST_HEAD_INITIALIZER(chassis
);
61 static struct PCIEChassis
*pcie_chassis_find(uint8_t chassis_number
)
63 struct PCIEChassis
*c
;
64 QLIST_FOREACH(c
, &chassis
, next
) {
65 if (c
->number
== chassis_number
) {
72 void pcie_chassis_create(uint8_t chassis_number
)
74 struct PCIEChassis
*c
;
75 c
= pcie_chassis_find(chassis_number
);
79 c
= qemu_mallocz(sizeof(*c
));
80 c
->number
= chassis_number
;
81 QLIST_INIT(&c
->slots
);
82 QLIST_INSERT_HEAD(&chassis
, c
, next
);
85 static PCIESlot
*pcie_chassis_find_slot_with_chassis(struct PCIEChassis
*c
,
89 QLIST_FOREACH(s
, &c
->slots
, next
) {
90 if (s
->slot
== slot
) {
97 PCIESlot
*pcie_chassis_find_slot(uint8_t chassis_number
, uint16_t slot
)
99 struct PCIEChassis
*c
;
100 c
= pcie_chassis_find(chassis_number
);
104 return pcie_chassis_find_slot_with_chassis(c
, slot
);
107 int pcie_chassis_add_slot(struct PCIESlot
*slot
)
109 struct PCIEChassis
*c
;
110 c
= pcie_chassis_find(slot
->chassis
);
114 if (pcie_chassis_find_slot_with_chassis(c
, slot
->slot
)) {
117 QLIST_INSERT_HEAD(&c
->slots
, slot
, next
);
121 void pcie_chassis_del_slot(PCIESlot
*s
)
123 QLIST_REMOVE(s
, next
);