Skip to content

Commit

Permalink
Adding XHCI via PCI
Browse files Browse the repository at this point in the history
  • Loading branch information
janweinstock committed May 13, 2024
1 parent e28a443 commit a377a23
Show file tree
Hide file tree
Showing 4 changed files with 110 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,10 @@ add_library(vcml STATIC
${src}/vcml/models/usb/drive.cpp
${src}/vcml/models/usb/keyboard.cpp
${src}/vcml/models/usb/xhci.cpp
${src}/vcml/models/usb/xhcipci.cpp
${src}/vcml/models/pci/device.cpp
${src}/vcml/models/pci/host.cpp
${src}/vcml/models/pci/endpoint.cpp
${src}/vcml/models/virtio/mmio.cpp
${src}/vcml/models/virtio/pci.cpp
${src}/vcml/models/virtio/rng.cpp
Expand Down
2 changes: 2 additions & 0 deletions include/vcml.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,13 +118,15 @@
#include "vcml/models/sd/sdhci.h"

#include "vcml/models/usb/xhci.h"
#include "vcml/models/usb/xhcipci.h"
#include "vcml/models/usb/device.h"
#include "vcml/models/usb/keyboard.h"
#include "vcml/models/usb/drive.h"
#include "vcml/models/usb/hostdev.h"

#include "vcml/models/pci/device.h"
#include "vcml/models/pci/host.h"
#include "vcml/models/pci/endpoint.h"

#include "vcml/models/virtio/mmio.h"
#include "vcml/models/virtio/pci.h"
Expand Down
43 changes: 43 additions & 0 deletions include/vcml/models/usb/xhcipci.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/******************************************************************************
* *
* Copyright (C) 2024 MachineWare GmbH *
* All Rights Reserved *
* *
* This is work is licensed under the terms described in the LICENSE file *
* found in the root directory of this source tree. *
* *
******************************************************************************/

#ifndef VCML_USB_XHCIPCI_H
#define VCML_USB_XHCIPCI_H

#include "vcml/core/types.h"
#include "vcml/core/range.h"
#include "vcml/core/systemc.h"
#include "vcml/core/peripheral.h"

#include "vcml/models/pci/endpoint.h"
#include "vcml/models/usb/xhci.h"

namespace vcml {
namespace usb {

class xhcipci : public module, public usb_host_if
{
private:
pci::endpoint m_ep;
usb::xhci m_xhci;

public:
pci_base_target_socket pci_in;
usb_base_initiator_array usb_out;

xhcipci(const sc_module_name& name);
virtual ~xhcipci();
VCML_KIND(usb::xhcipci);
};

} // namespace usb
} // namespace vcml

#endif
63 changes: 63 additions & 0 deletions src/vcml/models/usb/xhcipci.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/******************************************************************************
* *
* Copyright (C) 2024 MachineWare GmbH *
* All Rights Reserved *
* *
* This is work is licensed under the terms described in the LICENSE file *
* found in the root directory of this source tree. *
* *
******************************************************************************/

#include "vcml/models/usb/xhcipci.h"

namespace vcml {
namespace usb {

static const pci_config XHCI_PCIE_CONFIG = {
/* pcie = */ true,
/* vendor_id = */ 0x1234,
/* device_id = */ 0x5678,
/* subvendor_id = */ 0xffff,
/* subsystem_id = */ 0xffff,
/* class_code = */ pci_class_code(0xc, 0x3, 0x30, 1),
/* latency_timer = */ 0,
/* max_latency = */ 0,
/* min_grant = */ 0,
/* int_pin = */ PCI_IRQ_A,
};

constexpr size_t XHCIPCI_MEMORY_SIZE = 0x4000;
constexpr size_t XHCIPCI_MSIX_OFFSET = 0x3000;

xhcipci::xhcipci(const sc_module_name& nm):
module(nm),
usb_host_if(),
m_ep("ep", XHCI_PCIE_CONFIG),
m_xhci("xhci"),
pci_in("pci_in"),
usb_out("usb_out") {
pci_in.bind(m_ep.pci_in);
m_xhci.usb_out.bind(usb_out);

m_ep.bar_out[0].bind(m_xhci.in);
m_xhci.irq.bind(m_ep.irq_in[0]);
m_xhci.dma.bind(m_ep.dma_in);

m_ep.pci_declare_bar(0, XHCIPCI_MEMORY_SIZE, PCI_BAR_MMIO | PCI_BAR_64);
m_ep.pci_declare_pm_cap(PCI_PM_CAP_VER_1_1);
m_ep.pci_declare_msi_cap(PCI_MSI_VECTOR | PCI_MSI_64BIT | PCI_MSI_QMASK1);
m_ep.pci_declare_msix_cap(0, m_ep.irq_in.count(), XHCIPCI_MSIX_OFFSET);

m_ep.rst.stub();
m_xhci.rst.stub();

m_ep.clk.stub(100 * MHz);
m_xhci.clk.stub(100 * MHz);
}

xhcipci::~xhcipci() {
// nothing to do
}

} // namespace usb
} // namespace vcml

0 comments on commit a377a23

Please sign in to comment.