Reorganize struct Qcow2Cache for better struct packing
[qemu/agraf.git] / hw / pcie_port.c
blob340dcdb3c4b72c4b7176ce0cb12029f3073ff0f0
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 hardwared 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);
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
52 struct PCIEChassis {
53 uint8_t number;
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) {
66 break;
69 return c;
72 void pcie_chassis_create(uint8_t chassis_number)
74 struct PCIEChassis *c;
75 c = pcie_chassis_find(chassis_number);
76 if (c) {
77 return;
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,
86 uint8_t slot)
88 PCIESlot *s;
89 QLIST_FOREACH(s, &c->slots, next) {
90 if (s->slot == slot) {
91 break;
94 return s;
97 PCIESlot *pcie_chassis_find_slot(uint8_t chassis_number, uint16_t slot)
99 struct PCIEChassis *c;
100 c = pcie_chassis_find(chassis_number);
101 if (!c) {
102 return NULL;
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);
111 if (!c) {
112 return -ENODEV;
114 if (pcie_chassis_find_slot_with_chassis(c, slot->slot)) {
115 return -EBUSY;
117 QLIST_INSERT_HEAD(&c->slots, slot, next);
118 return 0;
121 void pcie_chassis_del_slot(PCIESlot *s)
123 QLIST_REMOVE(s, next);