2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
4 * Copyright (c) 2011 NetApp, Inc.
5 * Copyright (c) 2018 Joyent, Inc.
6 * Copyright 2021 Oxide Computer Company
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
18 * THIS SOFTWARE IS PROVIDED BY NETAPP, INC ``AS IS'' AND
19 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL NETAPP, INC OR CONTRIBUTORS BE LIABLE
22 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 #include <sys/cdefs.h>
40 __FBSDID("$FreeBSD$");
51 static struct pci_hostbridge_model
{
52 const char *phm_model
;
56 { "amd", 0x1022, 0x7432 }, /* AMD/made-up */
57 { "netapp", 0x1275, 0x1275 }, /* NetApp/NetApp */
58 { "i440fx", 0x8086, 0x1237 }, /* Intel/82441 */
59 { "q35", 0x8086, 0x29b0 }, /* Intel/Q35 HB */
62 #define NUM_HB_MODELS (sizeof (pci_hb_models) / sizeof (pci_hb_models[0]))
66 pci_hostbridge_init(struct vmctx
*ctx __unused
, struct pci_devinst
*pi
,
73 vendor
= 0x1275; /* NetApp */
74 device
= 0x1275; /* NetApp */
79 value
= get_config_value_node(nvl
, "vendor");
81 vendor
= strtol(value
, NULL
, 0);
82 value
= get_config_value_node(nvl
, "devid");
84 device
= strtol(value
, NULL
, 0);
87 const char *model
= get_config_value_node(nvl
, "model");
89 if (model
!= NULL
&& (vendor
!= 0 || device
!= 0)) {
90 fprintf(stderr
, "pci_hostbridge: cannot specify model "
93 } else if ((vendor
!= 0 && device
== 0) ||
94 (vendor
== 0 && device
!= 0)) {
95 fprintf(stderr
, "pci_hostbridge: must specify both vendor and"
96 "device for custom hostbridge");
99 if (model
== NULL
&& vendor
== 0 && device
== 0)
103 for (uint_t i
= 0; i
< NUM_HB_MODELS
; i
++) {
104 if (strcmp(model
, pci_hb_models
[i
].phm_model
) != 0)
107 /* found a model match */
108 vendor
= pci_hb_models
[i
].phm_vendor
;
109 device
= pci_hb_models
[i
].phm_device
;
113 fprintf(stderr
, "pci_hostbridge: invalid model '%s'",
119 /* Both i440fx and Q35 chipsets feature the concept of Programmable
120 * Address Memory (PAM), where certain physical address ranges can be
121 * configured to direct reads/writes to either DRAM, or to the PCI MMIO
122 * space instead. At boot, they default to bypassing DRAM, so in order
123 * to cheaply paper over our lack of emulation, the memory in PAM0
124 * (0xf0000-0xfffff, the System BIOS segment) should be zeroed.
126 * If this emulation is expanded in the future to truly support PAM
127 * behavior, this hack can be removed.
129 if (vendor
== 0x8086 && (device
== 0x1237 || device
== 0x29b0)) {
130 const uintptr_t start
= 0xf0000;
131 const size_t len
= 0x10000;
132 void *system_bios_region
= paddr_guest2host(ctx
, start
, len
);
133 assert(system_bios_region
!= NULL
);
134 bzero(system_bios_region
, len
);
136 #endif /* !__FreeBSD__ */
139 pci_set_cfgdata16(pi
, PCIR_VENDOR
, vendor
);
140 pci_set_cfgdata16(pi
, PCIR_DEVICE
, device
);
141 pci_set_cfgdata8(pi
, PCIR_HDRTYPE
, PCIM_HDRTYPE_NORMAL
);
142 pci_set_cfgdata8(pi
, PCIR_CLASS
, PCIC_BRIDGE
);
143 pci_set_cfgdata8(pi
, PCIR_SUBCLASS
, PCIS_BRIDGE_HOST
);
145 pci_emul_add_pciecap(pi
, PCIEM_TYPE_ROOT_PORT
);
151 pci_amd_hostbridge_legacy_config(nvlist_t
*nvl
, const char *opts __unused
)
153 set_config_value_node(nvl
, "vendor", "0x1022"); /* AMD */
154 set_config_value_node(nvl
, "devid", "0x7432"); /* made up */
159 static const struct pci_devemu pci_de_amd_hostbridge
= {
160 .pe_emu
= "amd_hostbridge",
161 .pe_legacy_config
= pci_amd_hostbridge_legacy_config
,
162 .pe_alias
= "hostbridge",
164 PCI_EMUL_SET(pci_de_amd_hostbridge
);
166 static const struct pci_devemu pci_de_hostbridge
= {
167 .pe_emu
= "hostbridge",
168 .pe_init
= pci_hostbridge_init
,
170 PCI_EMUL_SET(pci_de_hostbridge
);