NativeGraphicsAdapter.cpp 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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/Memory/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. auto bar2_space_size = PCI::get_BAR_space_size(device_identifier(), PCI::HeaderType0BaseRegister::BAR2);
  39. dmesgln_pci(*this, "MMIO @ {}, space size is {:x} bytes", PhysicalAddress(PCI::get_BAR0(device_identifier())), bar0_space_size);
  40. dmesgln_pci(*this, "framebuffer @ {}", PhysicalAddress(PCI::get_BAR2(device_identifier())));
  41. using MMIORegion = IntelDisplayConnectorGroup::MMIORegion;
  42. MMIORegion first_region { MMIORegion::BARAssigned::BAR0, PhysicalAddress(PCI::get_BAR0(device_identifier()) & PCI::bar_address_mask), bar0_space_size };
  43. MMIORegion second_region { MMIORegion::BARAssigned::BAR2, PhysicalAddress(PCI::get_BAR2(device_identifier()) & PCI::bar_address_mask), bar2_space_size };
  44. PCI::enable_bus_mastering(device_identifier());
  45. PCI::enable_io_space(device_identifier());
  46. PCI::enable_memory_space(device_identifier());
  47. switch (device_identifier().hardware_id().device_id) {
  48. case 0x29c2:
  49. m_connector_group = TRY(IntelDisplayConnectorGroup::try_create({}, IntelGraphics::Generation::Gen4, first_region, second_region));
  50. return {};
  51. default:
  52. return Error::from_errno(ENODEV);
  53. }
  54. }
  55. IntelNativeGraphicsAdapter::IntelNativeGraphicsAdapter(PCI::DeviceIdentifier const& pci_device_identifier)
  56. : GenericGraphicsAdapter()
  57. , PCI::Device(const_cast<PCI::DeviceIdentifier&>(pci_device_identifier))
  58. {
  59. }
  60. }