Merge remote-tracking branch 'aneesh/for-upstream' into staging
[qemu-kvm.git] / hw / pcie_port.c
blobd6350e5e73f3deb48cecb187dbfcb0a9f3290cf5
1 /*
2 * pcie_port.c
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)
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);
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);
39 /**************************************************************************
40 * (chassis number, pcie physical slot number) -> pcie slot conversion
42 struct PCIEChassis {
43 uint8_t number;
45 QLIST_HEAD(, PCIESlot) slots;
46 QLIST_ENTRY(PCIEChassis) next;
49 static QLIST_HEAD(, PCIEChassis) chassis = QLIST_HEAD_INITIALIZER(chassis);
51 static struct PCIEChassis *pcie_chassis_find(uint8_t chassis_number)
53 struct PCIEChassis *c;
54 QLIST_FOREACH(c, &chassis, next) {
55 if (c->number == chassis_number) {
56 break;
59 return c;
62 void pcie_chassis_create(uint8_t chassis_number)
64 struct PCIEChassis *c;
65 c = pcie_chassis_find(chassis_number);
66 if (c) {
67 return;
69 c = g_malloc0(sizeof(*c));
70 c->number = chassis_number;
71 QLIST_INIT(&c->slots);
72 QLIST_INSERT_HEAD(&chassis, c, next);
75 static PCIESlot *pcie_chassis_find_slot_with_chassis(struct PCIEChassis *c,
76 uint8_t slot)
78 PCIESlot *s;
79 QLIST_FOREACH(s, &c->slots, next) {
80 if (s->slot == slot) {
81 break;
84 return s;
87 PCIESlot *pcie_chassis_find_slot(uint8_t chassis_number, uint16_t slot)
89 struct PCIEChassis *c;
90 c = pcie_chassis_find(chassis_number);
91 if (!c) {
92 return NULL;
94 return pcie_chassis_find_slot_with_chassis(c, slot);
97 int pcie_chassis_add_slot(struct PCIESlot *slot)
99 struct PCIEChassis *c;
100 c = pcie_chassis_find(slot->chassis);
101 if (!c) {
102 return -ENODEV;
104 if (pcie_chassis_find_slot_with_chassis(c, slot->slot)) {
105 return -EBUSY;
107 QLIST_INSERT_HEAD(&c->slots, slot, next);
108 return 0;
111 void pcie_chassis_del_slot(PCIESlot *s)
113 QLIST_REMOVE(s, next);