|
| 1 | +/*- |
| 2 | +* Copyright (c) 2011 NetApp, Inc. |
| 3 | +* Copyright (c) 2018 Intel Corporation |
| 4 | +* All rights reserved. |
| 5 | +* |
| 6 | +* Redistribution and use in source and binary forms, with or without |
| 7 | +* modification, are permitted provided that the following conditions |
| 8 | +* are met: |
| 9 | +* 1. Redistributions of source code must retain the above copyright |
| 10 | +* notice, this list of conditions and the following disclaimer. |
| 11 | +* 2. Redistributions in binary form must reproduce the above copyright |
| 12 | +* notice, this list of conditions and the following disclaimer in the |
| 13 | +* documentation and/or other materials provided with the distribution. |
| 14 | +* |
| 15 | +* THIS SOFTWARE IS PROVIDED BY NETAPP, INC ``AS IS'' AND |
| 16 | +* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 17 | +* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 18 | +* ARE DISCLAIMED. IN NO EVENT SHALL NETAPP, INC OR CONTRIBUTORS BE LIABLE |
| 19 | +* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 20 | +* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
| 21 | +* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 22 | +* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
| 23 | +* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
| 24 | +* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 25 | +* SUCH DAMAGE. |
| 26 | +* |
| 27 | +* $FreeBSD$ |
| 28 | +*/ |
| 29 | + |
| 30 | + |
| 31 | +/*_ |
| 32 | +* Emulate a PCI Host bridge: |
| 33 | +* Intel Corporation Celeron N3350/Pentium N4200/Atom E3900 |
| 34 | +* Series Host Bridge (rev 0b) |
| 35 | +*/ |
| 36 | + |
| 37 | +#include <hypervisor.h> |
| 38 | +#include <hv_lib.h> |
| 39 | +#include <acrn_common.h> |
| 40 | +#include <hv_arch.h> |
| 41 | +#include <hv_debug.h> |
| 42 | +#include "pci_priv.h" |
| 43 | + |
| 44 | +static int vdev_hostbridge_init(struct pci_vdev *vdev) |
| 45 | +{ |
| 46 | + /* PCI config space */ |
| 47 | + pci_vdev_write_cfg_u16(vdev, PCIR_VENDOR, 0x8086U); |
| 48 | + pci_vdev_write_cfg_u16(vdev, PCIR_DEVICE, 0x5af0U); |
| 49 | + |
| 50 | + pci_vdev_write_cfg_u8(vdev, PCIR_REVID, 0xbU); |
| 51 | + |
| 52 | + pci_vdev_write_cfg_u8(vdev, PCIR_HDRTYPE, PCIM_HDRTYPE_NORMAL |
| 53 | + | PCIM_MFDEV); |
| 54 | + pci_vdev_write_cfg_u8(vdev, PCIR_CLASS, PCIC_BRIDGE); |
| 55 | + pci_vdev_write_cfg_u8(vdev, PCIR_SUBCLASS, PCIS_BRIDGE_HOST); |
| 56 | + |
| 57 | + pci_vdev_write_cfg_u8(vdev, 0x34U, 0xe0U); |
| 58 | + pci_vdev_write_cfg_u8(vdev, 0x3cU, 0xe0U); |
| 59 | + pci_vdev_write_cfg_u8(vdev, 0x48U, 0x1U); |
| 60 | + pci_vdev_write_cfg_u8(vdev, 0x4aU, 0xd1U); |
| 61 | + pci_vdev_write_cfg_u8(vdev, 0x4bU, 0xfeU); |
| 62 | + pci_vdev_write_cfg_u8(vdev, 0x50U, 0xc1U); |
| 63 | + pci_vdev_write_cfg_u8(vdev, 0x51U, 0x2U); |
| 64 | + pci_vdev_write_cfg_u8(vdev, 0x54U, 0x33U); |
| 65 | + pci_vdev_write_cfg_u8(vdev, 0x58U, 0x7U); |
| 66 | + pci_vdev_write_cfg_u8(vdev, 0x5aU, 0xf0U); |
| 67 | + pci_vdev_write_cfg_u8(vdev, 0x5bU, 0x7fU); |
| 68 | + pci_vdev_write_cfg_u8(vdev, 0x60U, 0x1U); |
| 69 | + pci_vdev_write_cfg_u8(vdev, 0x63U, 0xe0U); |
| 70 | + pci_vdev_write_cfg_u8(vdev, 0xabU, 0x80U); |
| 71 | + pci_vdev_write_cfg_u8(vdev, 0xacU, 0x2U); |
| 72 | + pci_vdev_write_cfg_u8(vdev, 0xb0U, 0x1U); |
| 73 | + pci_vdev_write_cfg_u8(vdev, 0xb3U, 0x7cU); |
| 74 | + pci_vdev_write_cfg_u8(vdev, 0xb4U, 0x1U); |
| 75 | + pci_vdev_write_cfg_u8(vdev, 0xb6U, 0x80U); |
| 76 | + pci_vdev_write_cfg_u8(vdev, 0xb7U, 0x7bU); |
| 77 | + pci_vdev_write_cfg_u8(vdev, 0xb8U, 0x1U); |
| 78 | + pci_vdev_write_cfg_u8(vdev, 0xbbU, 0x7bU); |
| 79 | + pci_vdev_write_cfg_u8(vdev, 0xbcU, 0x1U); |
| 80 | + pci_vdev_write_cfg_u8(vdev, 0xbfU, 0x80U); |
| 81 | + pci_vdev_write_cfg_u8(vdev, 0xe0U, 0x9U); |
| 82 | + pci_vdev_write_cfg_u8(vdev, 0xe2U, 0xcU); |
| 83 | + pci_vdev_write_cfg_u8(vdev, 0xe3U, 0x1U); |
| 84 | + pci_vdev_write_cfg_u8(vdev, 0xf5U, 0xfU); |
| 85 | + pci_vdev_write_cfg_u8(vdev, 0xf6U, 0x1cU); |
| 86 | + pci_vdev_write_cfg_u8(vdev, 0xf7U, 0x1U); |
| 87 | + |
| 88 | + return 0; |
| 89 | +} |
| 90 | + |
| 91 | +static int vdev_hostbridge_deinit(__unused struct pci_vdev *vdev) |
| 92 | +{ |
| 93 | + return 0; |
| 94 | +} |
| 95 | + |
| 96 | +static int vdev_hostbridge_cfgread(struct pci_vdev *vdev, uint32_t offset, |
| 97 | + uint32_t bytes, uint32_t *val) |
| 98 | +{ |
| 99 | + /* Assumption: access needed to be aligned on 1/2/4 bytes */ |
| 100 | + if ((offset & (bytes - 1)) != 0U) { |
| 101 | + *val = 0xffffffffU; |
| 102 | + return -EINVAL; |
| 103 | + } |
| 104 | + |
| 105 | + *val = pci_vdev_read_cfg(vdev, offset, bytes); |
| 106 | + |
| 107 | + return 0; |
| 108 | +} |
| 109 | + |
| 110 | +static int vdev_hostbridge_cfgwrite(struct pci_vdev *vdev, uint32_t offset, |
| 111 | + uint32_t bytes, uint32_t val) |
| 112 | +{ |
| 113 | + /* Assumption: access needed to be aligned on 1/2/4 bytes */ |
| 114 | + if ((offset & (bytes - 1)) != 0U) { |
| 115 | + return -EINVAL; |
| 116 | + } |
| 117 | + |
| 118 | + pci_vdev_write_cfg(vdev, offset, bytes, val); |
| 119 | + |
| 120 | + return 0; |
| 121 | +} |
| 122 | + |
| 123 | +struct pci_vdev_ops pci_ops_vdev_hostbridge = { |
| 124 | + .init = vdev_hostbridge_init, |
| 125 | + .deinit = vdev_hostbridge_deinit, |
| 126 | + .cfgwrite = vdev_hostbridge_cfgwrite, |
| 127 | + .cfgread = vdev_hostbridge_cfgread, |
| 128 | +}; |
| 129 | + |
0 commit comments