[coreboot-gerrit] Change in libgfxinit[master]: gfx_test: Update to use *libhwbase* new PCI interface

Nico Huber (Code Review) gerrit at coreboot.org
Mon Jul 17 23:32:59 CEST 2017


Nico Huber has uploaded this change for review. ( https://review.coreboot.org/20598


Change subject: gfx_test: Update to use *libhwbase* new PCI interface
......................................................................

gfx_test: Update to use *libhwbase* new PCI interface

Thereby, move `gfx_test` into HW.GFX.GMA to make package dependencies
easier to handle.

Change-Id: Ie8a1251354b4fff57eef8c4bada8b49aa04ef382
Signed-off-by: Nico Huber <nico.h at gmx.de>
---
M README.md
M gfxtest/Makefile.inc
D gfxtest/gfx_test.ads
M gfxtest/gfx_test_main.adb
R gfxtest/hw-gfx-gma-gfx_test.adb
A gfxtest/hw-gfx-gma-gfx_test.ads
6 files changed, 58 insertions(+), 78 deletions(-)



  git pull ssh://review.coreboot.org:29418/libgfxinit refs/changes/98/20598/1

diff --git a/README.md b/README.md
index 998b8cc..7bfb504 100644
--- a/README.md
+++ b/README.md
@@ -40,16 +40,16 @@
 You can either write your own `.config`, link one of the shipped files
 in `configs/`, e.g.:
 
-    $ ln -s configs/posix libhwbase/.config
+    $ ln -s configs/linux libhwbase/.config
 
 or overwrite the config filename by specifying `cnf=<configfile>` on
 the make command line.
 
-Let's install *libhwbase*. We'll need `configs/posix` to build regular
+Let's install *libhwbase*. We'll need `configs/linux` to build regular
 Linux executables:
 
     $ cd libhwbase
-    $ make cnf=configs/posix install
+    $ make cnf=configs/linux install
 
 By default this installs into a new subdirectory `dest`. You can however
 overwrite this decision by specifying `DESTDIR=`.
@@ -80,11 +80,12 @@
 command line or with *i915* blacklisted). After running *i915* it
 only works by chance.
 
-When running `gfx_test` (as root), it will ask for a single argument:
-The path to a sysfs PCI-device node, where it will find the graphics
-hardware. Usually this is PCI device 00:02.0:
+When running `gfx_test` (as root), it will access the graphics hard-
+ware through the sysfs PCI interface. The path is
 
-    $ sudo build/gfx_test /sys/devices/pci0000:00/0000:00:02.0/
+    /sys/devices/pci0000:00/0000:00:02.0/
+
+for all supported platforms.
 
 If you chose the right config above, you should be presented with a
 nice test image. However, `gfx_test` is one-way only: The graphics
diff --git a/gfxtest/Makefile.inc b/gfxtest/Makefile.inc
index 158665a..ff7fa8e 100644
--- a/gfxtest/Makefile.inc
+++ b/gfxtest/Makefile.inc
@@ -1,4 +1,4 @@
-gfxinit-y += gfx_test.adb
-gfxinit-y += gfx_test.ads
+gfxinit-y += hw-gfx-gma-gfx_test.adb
+gfxinit-y += hw-gfx-gma-gfx_test.ads
 
 gfxinit-main-y = gfx_test_main.adb
diff --git a/gfxtest/gfx_test.ads b/gfxtest/gfx_test.ads
deleted file mode 100644
index 52e268e..0000000
--- a/gfxtest/gfx_test.ads
+++ /dev/null
@@ -1,5 +0,0 @@
-package GFX_Test is
-
-   procedure Main;
-
-end GFX_Test;
diff --git a/gfxtest/gfx_test_main.adb b/gfxtest/gfx_test_main.adb
index d3666c9..2e1d5da 100644
--- a/gfxtest/gfx_test_main.adb
+++ b/gfxtest/gfx_test_main.adb
@@ -1,6 +1,6 @@
-with GFX_Test;
+with HW.GFX.GMA.GFX_Test;
 
 procedure GFX_Test_Main is
 begin
-   GFX_Test.Main;
+   HW.GFX.GMA.GFX_Test.Main;
 end GFX_Test_Main;
diff --git a/gfxtest/gfx_test.adb b/gfxtest/hw-gfx-gma-gfx_test.adb
similarity index 69%
rename from gfxtest/gfx_test.adb
rename to gfxtest/hw-gfx-gma-gfx_test.adb
index e7fb80c..b7060ec 100644
--- a/gfxtest/gfx_test.adb
+++ b/gfxtest/hw-gfx-gma-gfx_test.adb
@@ -1,24 +1,18 @@
-with System.Storage_Elements;
+with Ada.Unchecked_Conversion;
 with Ada.Command_Line;
 with Interfaces.C;
 
-with HW.File;
 with HW.Debug;
+with HW.PCI.Dev;
+with HW.MMIO_Range;
 with HW.GFX.GMA;
 with HW.GFX.GMA.Display_Probing;
 
-use HW;
-use HW.GFX;
+package body HW.GFX.GMA.GFX_Test
+is
+   pragma Disable_Atomic_Synchronization;
 
-package body GFX_Test is
-
-   MMIO_Size : constant := 2 * 1024 * 1024;
-   subtype MMIO_Range is Natural range 0 .. MMIO_Size - 1;
-   subtype MMIO_Buffer is Buffer (MMIO_Range);
-   MMIO_Dummy : MMIO_Buffer
-   with
-      Alignment => 16#1000#,
-      Volatile;
+   package Dev is new PCI.Dev (PCI.Address'(0, 2, 0));
 
    type Pixel_Type is record
       Red   : Byte;
@@ -34,16 +28,23 @@
       Alpha at 3 range 0 .. 7;
    end record;
 
+   function Pixel_To_Word (P : Pixel_Type) return Word32
+   with
+      SPARK_Mode => Off
+   is
+      function To_Word is new Ada.Unchecked_Conversion (Pixel_Type, Word32);
+   begin
+      return To_Word (P);
+   end Pixel_To_Word;
+
    Max_W    : constant := 4096;
    Max_H    : constant := 2160;
    FB_Align : constant := 16#0004_0000#;
-   type Screen_Type is
-      array (0 .. 3 * (Max_W * Max_H + FB_Align / 4) - 1) of Pixel_Type;
+   subtype Screen_Index is Natural range
+      0 .. 3 * (Max_W * Max_H + FB_Align / 4) - 1;
+   type Screen_Type is array (Screen_Index) of Word32;
 
-   Screen : Screen_Type
-   with
-      Alignment => 16#1000#,
-      Volatile;
+   package Screen is new MMIO_Range (0, Word32, Screen_Index, Screen_Type);
 
    Pipes : GMA.Pipe_Configs;
 
@@ -76,7 +77,6 @@
      (Framebuffer : Framebuffer_Type;
       Pipe        : GMA.Pipe_Index)
    is
-      use type HW.Word32;
       P        : Pixel_Type;
       -- We have pixel offset wheras the framebuffer has a byte offset
       Offset_Y : Natural := Natural (Framebuffer.Offset / 4);
@@ -90,7 +90,7 @@
             else
                P := Fill (X, Y, Framebuffer, Pipe);
             end if;
-            Screen (Offset) := P;
+            Screen.Write (Offset, Pixel_To_Word (P));
             Offset := Offset + 1;
          end loop;
          Offset_Y := Offset_Y + Natural (Framebuffer.Stride);
@@ -102,8 +102,6 @@
       Mode     : in     Mode_Type;
       Offset   : in out Word32)
    is
-      use type HW.Int32;
-      use type HW.Word32;
    begin
       Offset := (Offset + FB_Align - 1) and not (FB_Align - 1);
       FB :=
@@ -119,7 +117,7 @@
    is
       use type HW.GFX.GMA.Port_Type;
 
-      Offset : HW.Word32 := 0;
+      Offset : Word32 := 0;
    begin
       GMA.Display_Probing.Scan_Ports (Pipes);
 
@@ -135,65 +133,46 @@
       GMA.Dump_Configs (Pipes);
    end Prepare_Configs;
 
-   procedure Print_Usage is
-   begin
-      Debug.Put_Line
-        ("Usage: " & Ada.Command_Line.Command_Name & " <sysfs-pci-path>");
-      Debug.New_Line;
-   end Print_Usage;
-
    procedure Main
    is
-      use System.Storage_Elements;
-
       use type HW.GFX.GMA.Port_Type;
+      use type HW.Word64;
       use type Interfaces.C.int;
 
-      MMIO_Mapped,
-      Screen_Mapped,
+      Res_Addr : Word64;
+
+      Dev_Init,
       Initialized : Boolean;
 
       function iopl (level : Interfaces.C.int) return Interfaces.C.int;
       pragma Import (C, iopl, "iopl");
    begin
-      if Ada.Command_Line.Argument_Count /= 1 then
-         Print_Usage;
-         return;
-      end if;
-
       if iopl (3) /= 0 then
          Debug.Put_Line ("Failed to change i/o privilege level.");
          return;
       end if;
 
-      File.Map
-        (Path     => Ada.Command_Line.Argument (1) & "/resource0",
-         Addr     => Word64 (To_Integer (MMIO_Dummy'Address)),
-         Len      => MMIO_Dummy'Size / 8,
-         Readable => True,
-         Writable => True,
-         Success  => MMIO_Mapped);
-      if not MMIO_Mapped then
-         Debug.Put_Line
-           ("Failed to map '" & Ada.Command_Line.Argument (1) & "/resource0'.");
+      Dev.Initialize (Dev_Init);
+      if not Dev_Init then
+         Debug.Put_Line ("Failed to map PCI config.");
          return;
       end if;
 
-      File.Map
-        (Path     => Ada.Command_Line.Argument (1) & "/resource2",
-         Addr     => Word64 (To_Integer (Screen'Address)),
-         Len      => Screen'Size / 8,
-         Readable => True,
-         Writable => True,
-         Success  => Screen_Mapped);
-      if not Screen_Mapped then
-         Debug.Put_Line
-           ("Failed to map '" & Ada.Command_Line.Argument (1) & "/resource2'.");
+      Dev.Map (Res_Addr, PCI.Res2, WC => True);
+      if Res_Addr = 0 then
+         Debug.Put_Line ("Failed to map PCI resource2.");
+         return;
+      end if;
+      Screen.Set_Base_Address (Res_Addr);
+
+      Dev.Map (Res_Addr, PCI.Res0);
+      if Res_Addr = 0 then
+         Debug.Put_Line ("Failed to map PCI resource0.");
          return;
       end if;
 
       GMA.Initialize
-        (MMIO_Base   => Word64 (To_Integer (MMIO_Dummy'Address)),
+        (MMIO_Base   => Res_Addr,
          Clean_State => True,
          Success     => Initialized);
 
@@ -212,4 +191,4 @@
       end if;
    end Main;
 
-end GFX_Test;
+end HW.GFX.GMA.GFX_Test;
diff --git a/gfxtest/hw-gfx-gma-gfx_test.ads b/gfxtest/hw-gfx-gma-gfx_test.ads
new file mode 100644
index 0000000..71da057
--- /dev/null
+++ b/gfxtest/hw-gfx-gma-gfx_test.ads
@@ -0,0 +1,5 @@
+package HW.GFX.GMA.GFX_Test is
+
+   procedure Main;
+
+end HW.GFX.GMA.GFX_Test;

-- 
To view, visit https://review.coreboot.org/20598
To unsubscribe, visit https://review.coreboot.org/settings

Gerrit-Project: libgfxinit
Gerrit-Branch: master
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ie8a1251354b4fff57eef8c4bada8b49aa04ef382
Gerrit-Change-Number: 20598
Gerrit-PatchSet: 1
Gerrit-Owner: Nico Huber <nico.h at gmx.de>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.coreboot.org/pipermail/coreboot-gerrit/attachments/20170717/b899fcee/attachment-0001.html>


More information about the coreboot-gerrit mailing list