Skip to content

Commit

Permalink
Kernel: Move PCI vendor and device IDs into Kernel/PCI/IDs.h
Browse files Browse the repository at this point in the history
  • Loading branch information
gunnarbeutner authored and awesomekling committed Apr 27, 2021
1 parent eaf8fc9 commit bf703ee
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 12 deletions.
5 changes: 2 additions & 3 deletions Kernel/Net/E1000NetworkAdapter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <AK/MACAddress.h>
#include <Kernel/Debug.h>
#include <Kernel/Net/E1000NetworkAdapter.h>
#include <Kernel/PCI/IDs.h>

namespace Kernel {

Expand Down Expand Up @@ -117,8 +118,6 @@ namespace Kernel {
#define INTERRUPT_TXD_LOW (1 << 15)
#define INTERRUPT_SRPD (1 << 16)

#define PCI_VENDOR_INTEL 0x8086

// https://www.intel.com/content/dam/doc/manual/pci-pci-x-family-gbe-controllers-software-dev-manual.pdf Section 5.2
static bool is_valid_device_id(u16 device_id)
{
Expand Down Expand Up @@ -162,7 +161,7 @@ UNMAP_AFTER_INIT void E1000NetworkAdapter::detect()
PCI::enumerate([&](const PCI::Address& address, PCI::ID id) {
if (address.is_null())
return;
if (id.vendor_id != PCI_VENDOR_INTEL)
if (id.vendor_id != (u16)PCIVendorID::Intel)
return;
if (!is_valid_device_id(id.device_id))
return;
Expand Down
21 changes: 21 additions & 0 deletions Kernel/PCI/IDs.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* Copyright (c) 2021, Gunnar Beutner <[email protected]>
*
* SPDX-License-Identifier: BSD-2-Clause
*/

#pragma once

namespace Kernel {

enum class PCIVendorID {
VirtIO = 0x1af4,
Intel = 0x8086,
};

enum class PCIDeviceID {
VirtIOConsole = 0x1003,
VirtIOEntropy = 0x1005,
};

}
7 changes: 4 additions & 3 deletions Kernel/VirtIO/VirtIO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/

#include <Kernel/CommandLine.h>
#include <Kernel/PCI/IDs.h>
#include <Kernel/VirtIO/VirtIO.h>
#include <Kernel/VirtIO/VirtIOConsole.h>
#include <Kernel/VirtIO/VirtIORNG.h>
Expand All @@ -18,14 +19,14 @@ void VirtIO::detect()
PCI::enumerate([&](const PCI::Address& address, PCI::ID id) {
if (address.is_null() || id.is_null())
return;
if (id.vendor_id != VIRTIO_PCI_VENDOR_ID)
if (id.vendor_id != (u16)PCIVendorID::VirtIO)
return;
switch (id.device_id) {
case VIRTIO_CONSOLE_PCI_DEVICE_ID: {
case (u16)PCIDeviceID::VirtIOConsole: {
[[maybe_unused]] auto& unused = adopt_ref(*new VirtIOConsole(address)).leak_ref();
break;
}
case VIRTIO_ENTROPY_PCI_DEVICE_ID: {
case (u16)PCIDeviceID::VirtIOEntropy: {
[[maybe_unused]] auto& unused = adopt_ref(*new VirtIORNG(address)).leak_ref();
break;
}
Expand Down
2 changes: 0 additions & 2 deletions Kernel/VirtIO/VirtIO.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@

namespace Kernel {

#define VIRTIO_PCI_VENDOR_ID 0x1AF4

#define REG_DEVICE_FEATURES 0x0
#define REG_GUEST_FEATURES 0x4
#define REG_QUEUE_ADDRESS 0x8
Expand Down
2 changes: 0 additions & 2 deletions Kernel/VirtIO/VirtIOConsole.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@

namespace Kernel {

#define VIRTIO_CONSOLE_PCI_DEVICE_ID 0x1003

#define VIRTIO_CONSOLE_F_SIZE (1 << 0)
#define VIRTIO_CONSOLE_F_MULTIPORT (1 << 1)
#define VIRTIO_CONSOLE_F_EMERG_WRITE (1 << 2)
Expand Down
2 changes: 0 additions & 2 deletions Kernel/VirtIO/VirtIORNG.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@

namespace Kernel {

#define VIRTIO_ENTROPY_PCI_DEVICE_ID 0x1005

#define REQUESTQ 0

class VirtIORNG final : public CharacterDevice
Expand Down

0 comments on commit bf703ee

Please sign in to comment.