NativeGraphicsAdapter.cpp 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. LockRefPtr<IntelNativeGraphicsAdapter> IntelNativeGraphicsAdapter::initialize(PCI::DeviceIdentifier const& pci_device_identifier)
  25. {
  26. VERIFY(pci_device_identifier.hardware_id().vendor_id == 0x8086);
  27. if (!is_supported_model(pci_device_identifier.hardware_id().device_id))
  28. return {};
  29. auto adapter = adopt_lock_ref(*new IntelNativeGraphicsAdapter(pci_device_identifier.address()));
  30. MUST(adapter->initialize_adapter());
  31. return adapter;
  32. }
  33. ErrorOr<void> IntelNativeGraphicsAdapter::initialize_adapter()
  34. {
  35. auto address = pci_address();
  36. dbgln_if(INTEL_GRAPHICS_DEBUG, "Intel Native Graphics Adapter @ {}", address);
  37. auto bar0_space_size = PCI::get_BAR_space_size(address, PCI::HeaderType0BaseRegister::BAR0);
  38. VERIFY(bar0_space_size == 0x80000);
  39. auto bar2_space_size = PCI::get_BAR_space_size(address, PCI::HeaderType0BaseRegister::BAR2);
  40. dmesgln_pci(*this, "MMIO @ {}, space size is {:x} bytes", PhysicalAddress(PCI::get_BAR0(address)), bar0_space_size);
  41. dmesgln_pci(*this, "framebuffer @ {}", PhysicalAddress(PCI::get_BAR2(address)));
  42. PCI::enable_bus_mastering(address);
  43. m_display_connector = IntelNativeDisplayConnector::must_create(PhysicalAddress(PCI::get_BAR2(address) & 0xfffffff0), bar2_space_size, PhysicalAddress(PCI::get_BAR0(address) & 0xfffffff0), bar0_space_size);
  44. return {};
  45. }
  46. IntelNativeGraphicsAdapter::IntelNativeGraphicsAdapter(PCI::Address address)
  47. : GenericGraphicsAdapter()
  48. , PCI::Device(address)
  49. {
  50. }
  51. }