Jason Baron | a1c9304 | 2012-11-14 15:54:07 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2006 Fabrice Bellard |
| 3 | * |
| 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 5 | * of this software and associated documentation files (the "Software"), to deal |
| 6 | * in the Software without restriction, including without limitation the rights |
| 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 8 | * copies of the Software, and to permit persons to whom the Software is |
| 9 | * furnished to do so, subject to the following conditions: |
| 10 | * |
| 11 | * The above copyright notice and this permission notice shall be included in |
| 12 | * all copies or substantial portions of the Software. |
| 13 | * |
| 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 17 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 20 | * THE SOFTWARE. |
| 21 | */ |
| 22 | /* |
| 23 | * QEMU i82801b11 dmi-to-pci Bridge Emulation |
| 24 | * |
| 25 | * Copyright (c) 2009, 2010, 2011 |
| 26 | * Isaku Yamahata <yamahata at valinux co jp> |
| 27 | * VA Linux Systems Japan K.K. |
| 28 | * Copyright (C) 2012 Jason Baron <jbaron@redhat.com> |
| 29 | * |
| 30 | * This library is free software; you can redistribute it and/or |
| 31 | * modify it under the terms of the GNU Lesser General Public |
| 32 | * License as published by the Free Software Foundation; either |
| 33 | * version 2 of the License, or (at your option) any later version. |
| 34 | * |
| 35 | * This library is distributed in the hope that it will be useful, |
| 36 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 37 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 38 | * Lesser General Public License for more details. |
| 39 | * |
| 40 | * You should have received a copy of the GNU Lesser General Public |
| 41 | * License along with this library; if not, see <http://www.gnu.org/licenses/> |
| 42 | */ |
| 43 | |
Paolo Bonzini | 83c9f4c | 2013-02-04 15:40:22 +0100 | [diff] [blame] | 44 | #include "hw/pci/pci.h" |
Paolo Bonzini | 0d09e41 | 2013-02-05 17:06:20 +0100 | [diff] [blame] | 45 | #include "hw/i386/ich9.h" |
Jason Baron | a1c9304 | 2012-11-14 15:54:07 -0500 | [diff] [blame] | 46 | |
| 47 | |
| 48 | /*****************************************************************************/ |
| 49 | /* ICH9 DMI-to-PCI bridge */ |
| 50 | #define I82801ba_SSVID_OFFSET 0x50 |
| 51 | #define I82801ba_SSVID_SVID 0 |
| 52 | #define I82801ba_SSVID_SSID 0 |
| 53 | |
| 54 | typedef struct I82801b11Bridge { |
Andreas Färber | 5315dc7 | 2013-07-12 19:21:22 +0200 | [diff] [blame] | 55 | /*< private >*/ |
| 56 | PCIBridge parent_obj; |
| 57 | /*< public >*/ |
Jason Baron | a1c9304 | 2012-11-14 15:54:07 -0500 | [diff] [blame] | 58 | } I82801b11Bridge; |
| 59 | |
| 60 | static int i82801b11_bridge_initfn(PCIDevice *d) |
| 61 | { |
| 62 | int rc; |
| 63 | |
Alex Williamson | 60a0e44 | 2013-03-14 16:01:11 -0600 | [diff] [blame] | 64 | rc = pci_bridge_initfn(d, TYPE_PCI_BUS); |
Jason Baron | a1c9304 | 2012-11-14 15:54:07 -0500 | [diff] [blame] | 65 | if (rc < 0) { |
| 66 | return rc; |
| 67 | } |
| 68 | |
| 69 | rc = pci_bridge_ssvid_init(d, I82801ba_SSVID_OFFSET, |
| 70 | I82801ba_SSVID_SVID, I82801ba_SSVID_SSID); |
| 71 | if (rc < 0) { |
| 72 | goto err_bridge; |
| 73 | } |
Don Koch | 4268b09 | 2013-07-09 13:36:05 -0400 | [diff] [blame] | 74 | pci_config_set_prog_interface(d->config, PCI_CLASS_BRIDGE_PCI_INF_SUB); |
Jason Baron | a1c9304 | 2012-11-14 15:54:07 -0500 | [diff] [blame] | 75 | return 0; |
| 76 | |
| 77 | err_bridge: |
| 78 | pci_bridge_exitfn(d); |
| 79 | |
| 80 | return rc; |
| 81 | } |
| 82 | |
| 83 | static void i82801b11_bridge_class_init(ObjectClass *klass, void *data) |
| 84 | { |
| 85 | PCIDeviceClass *k = PCI_DEVICE_CLASS(klass); |
Marcel Apfelbaum | 125ee0e | 2013-07-29 17:17:45 +0300 | [diff] [blame] | 86 | DeviceClass *dc = DEVICE_CLASS(klass); |
Jason Baron | a1c9304 | 2012-11-14 15:54:07 -0500 | [diff] [blame] | 87 | |
| 88 | k->is_bridge = 1; |
| 89 | k->vendor_id = PCI_VENDOR_ID_INTEL; |
| 90 | k->device_id = PCI_DEVICE_ID_INTEL_82801BA_11; |
| 91 | k->revision = ICH9_D2P_A2_REVISION; |
| 92 | k->init = i82801b11_bridge_initfn; |
Gerd Hoffmann | 4965b7f | 2013-08-05 16:36:40 +0200 | [diff] [blame] | 93 | k->config_write = pci_bridge_write_config; |
Marcel Apfelbaum | 125ee0e | 2013-07-29 17:17:45 +0300 | [diff] [blame] | 94 | set_bit(DEVICE_CATEGORY_BRIDGE, dc->categories); |
Jason Baron | a1c9304 | 2012-11-14 15:54:07 -0500 | [diff] [blame] | 95 | } |
| 96 | |
| 97 | static const TypeInfo i82801b11_bridge_info = { |
| 98 | .name = "i82801b11-bridge", |
Andreas Färber | f055e96 | 2013-07-11 17:13:43 +0200 | [diff] [blame] | 99 | .parent = TYPE_PCI_BRIDGE, |
Jason Baron | a1c9304 | 2012-11-14 15:54:07 -0500 | [diff] [blame] | 100 | .instance_size = sizeof(I82801b11Bridge), |
| 101 | .class_init = i82801b11_bridge_class_init, |
| 102 | }; |
| 103 | |
| 104 | PCIBus *ich9_d2pbr_init(PCIBus *bus, int devfn, int sec_bus) |
| 105 | { |
| 106 | PCIDevice *d; |
| 107 | PCIBridge *br; |
| 108 | char buf[16]; |
| 109 | DeviceState *qdev; |
| 110 | |
| 111 | d = pci_create_multifunction(bus, devfn, true, "i82801b11-bridge"); |
| 112 | if (!d) { |
| 113 | return NULL; |
| 114 | } |
Andreas Färber | f055e96 | 2013-07-11 17:13:43 +0200 | [diff] [blame] | 115 | br = PCI_BRIDGE(d); |
| 116 | qdev = DEVICE(d); |
Jason Baron | a1c9304 | 2012-11-14 15:54:07 -0500 | [diff] [blame] | 117 | |
| 118 | snprintf(buf, sizeof(buf), "pci.%d", sec_bus); |
| 119 | pci_bridge_map_irq(br, buf, pci_swizzle_map_irq_fn); |
| 120 | qdev_init_nofail(qdev); |
| 121 | |
| 122 | return pci_bridge_get_sec_bus(br); |
| 123 | } |
| 124 | |
| 125 | static void d2pbr_register(void) |
| 126 | { |
| 127 | type_register_static(&i82801b11_bridge_info); |
| 128 | } |
| 129 | |
| 130 | type_init(d2pbr_register); |