1/**
2 * \file Fake PCI host bridge
3 */
4
5/*
6 * Copyright (c) 2009, ETH Zurich.
7 * All rights reserved.
8 *
9 * This file is distributed under the terms in the attached LICENSE file.
10 * If you do not find this file, copies can be found by writing to:
11 * ETH Zurich D-INFK, Universitaetstrasse 6, CH-8092 Zurich. Attn: Systems Group.
12 */
13
14#include <stdlib.h>
15
16#include "vmkitmon.h"
17#include "pci.h"
18#include "pci_devices.h"
19#include <dev/pci_hdr0_mem_dev.h>
20
21#define INVALID         0xffffffff
22
23struct pci_hostbridge {
24    pci_hdr0_mem_t      ph;
25    uint32_t            pci_header[0x40];
26};
27
28static void confspace_write(struct pci_device *dev,
29                            union pci_config_address_word addr,
30                            enum opsize size, uint32_t val)
31{
32}
33
34static void confspace_read(struct pci_device *dev,
35                           union pci_config_address_word addr,
36                           enum opsize size, uint32_t *val)
37{
38    struct pci_hostbridge *h = dev->state;
39
40    if(addr.d.fnct_nr != 0) {
41        *val = INVALID;
42        return;
43    }
44
45    if(addr.d.doubleword < 0x40) {
46        *val = h->pci_header[addr.d.doubleword];
47    } else {
48        *val = INVALID;
49    }
50}
51
52struct pci_device *pci_hostbridge_new(void)
53{
54    struct pci_device *dev = calloc(1, sizeof(struct pci_device));
55    struct pci_hostbridge *host = calloc(1, sizeof(struct pci_hostbridge));
56    pci_hdr0_mem_t *ph = &host->ph;
57
58    dev->confspace_write = confspace_write;
59    dev->confspace_read = confspace_read;
60    dev->state = host;
61
62    pci_hdr0_mem_initialize(ph, (mackerel_addr_t)host->pci_header);
63
64    // Fake a host bridge
65    pci_hdr0_mem_vendor_id_wr(ph, 0x8086);
66    pci_hdr0_mem_device_id_wr(ph, 1);
67    pci_hdr0_mem_class_code_clss_wrf(ph, pci_hdr0_mem_bridge);
68
69    return dev;
70}
71