NativeGraphicsAdapter.cpp 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /*
  2. * Copyright (c) 2021, Liav A. <liavalb@hotmail.co.il>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <Kernel/Bus/PCI/API.h>
  7. #include <Kernel/Graphics/Console/ContiguousFramebufferConsole.h>
  8. #include <Kernel/Graphics/Definitions.h>
  9. #include <Kernel/Graphics/GraphicsManagement.h>
  10. #include <Kernel/Graphics/Intel/NativeGraphicsAdapter.h>
  11. #include <Kernel/PhysicalAddress.h>
  12. namespace Kernel {
  13. static constexpr u16 supported_models[] {
  14. 0x29c2, // Intel G35 Adapter
  15. };
  16. static bool is_supported_model(u16 device_id)
  17. {
  18. for (auto& id : supported_models) {
  19. if (id == device_id)
  20. return true;
  21. }
  22. return false;
  23. }
  24. ErrorOr<bool> IntelNativeGraphicsAdapter::probe(PCI::DeviceIdentifier const& pci_device_identifier)
  25. {
  26. return is_supported_model(pci_device_identifier.hardware_id().device_id);
  27. }
  28. ErrorOr<NonnullLockRefPtr<GenericGraphicsAdapter>> IntelNativeGraphicsAdapter::create(PCI::DeviceIdentifier const& pci_device_identifier)
  29. {
  30. auto adapter = TRY(adopt_nonnull_lock_ref_or_enomem(new (nothrow) IntelNativeGraphicsAdapter(pci_device_identifier)));
  31. TRY(adapter->initialize_adapter());
  32. return adapter;
  33. }
  34. ErrorOr<void> IntelNativeGraphicsAdapter::initialize_adapter()
  35. {
  36. dbgln_if(INTEL_GRAPHICS_DEBUG, "Intel Native Graphics Adapter @ {}", device_identifier().address());
  37. auto bar0_space_size = PCI::get_BAR_space_size(device_identifier(), PCI::HeaderType0BaseRegister::BAR0);
  38. VERIFY(bar0_space_size == 0x80000);
  39. auto bar2_space_size = PCI::get_BAR_space_size(device_identifier(), PCI::HeaderType0BaseRegister::BAR2);
  40. dmesgln_pci(*this, "MMIO @ {}, space size is {:x} bytes", PhysicalAddress(PCI::get_BAR0(device_identifier())), bar0_space_size);
  41. dmesgln_pci(*this, "framebuffer @ {}", PhysicalAddress(PCI::get_BAR2(device_identifier())));
  42. PCI::enable_bus_mastering(device_identifier());
  43. m_display_connector = TRY(IntelNativeDisplayConnector::try_create(PhysicalAddress(PCI::get_BAR2(device_identifier()) & 0xfffffff0), bar2_space_size, PhysicalAddress(PCI::get_BAR0(device_identifier()) & 0xfffffff0), bar0_space_size));
  44. return {};
  45. }
  46. IntelNativeGraphicsAdapter::IntelNativeGraphicsAdapter(PCI::DeviceIdentifier const& pci_device_identifier)
  47. : GenericGraphicsAdapter()
  48. , PCI::Device(const_cast<PCI::DeviceIdentifier&>(pci_device_identifier))
  49. {
  50. }
  51. }