PCISerialDevice.h 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. /*
  2. * Copyright (c) 2021, Idan Horowitz <idan.horowitz@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <Kernel/Bus/PCI/Device.h>
  8. #include <Kernel/Bus/PCI/IDs.h>
  9. #include <Kernel/Devices/CharacterDevice.h>
  10. #include <Kernel/Devices/SerialDevice.h>
  11. namespace Kernel {
  12. class PCISerialDevice {
  13. AK_MAKE_ETERNAL
  14. public:
  15. static void detect();
  16. static SerialDevice& the();
  17. static bool is_available();
  18. private:
  19. struct BoardDefinition {
  20. PCI::ID device_id;
  21. StringView name;
  22. u32 port_count { 0 };
  23. u32 pci_bar { 0 };
  24. u32 first_offset { 0 };
  25. u32 port_size { 0 };
  26. SerialDevice::Baud baud_rate { SerialDevice::Baud::Baud38400 };
  27. };
  28. static constexpr BoardDefinition board_definitions[4] = {
  29. { { PCI::VendorID::WCH, 0x3253 }, "WCH CH382 2S", 2, 0, 0xC0, 8, SerialDevice::Baud::Baud115200 },
  30. { { PCI::VendorID::RedHat, 0x0002 }, "QEMU PCI 16550A", 1, 0, 0, 8, SerialDevice::Baud::Baud115200 },
  31. { { PCI::VendorID::RedHat, 0x0003 }, "QEMU PCI Dual-port 16550A", 2, 0, 0, 8, SerialDevice::Baud::Baud115200 },
  32. { { PCI::VendorID::RedHat, 0x0004 }, "QEMU PCI Quad-port 16550A", 4, 0, 0, 8, SerialDevice::Baud::Baud115200 }
  33. };
  34. };
  35. }