blob: f7da219fa89203b8cb45aaa61fdfbd4e452d2fed [file] [log] [blame]
Nico Huberef4545a2017-06-18 02:58:40 +02001--
2-- Copyright (C) 2017 Nico Huber <nico.h@gmx.de>
3--
4-- This program is free software; you can redistribute it and/or modify
5-- it under the terms of the GNU General Public License as published by
6-- the Free Software Foundation; either version 2 of the License, or
7-- (at your option) any later version.
8--
9-- This program is distributed in the hope that it will be useful,
10-- but WITHOUT ANY WARRANTY; without even the implied warranty of
11-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12-- GNU General Public License for more details.
13--
14
Nico Huberef4545a2017-06-18 02:58:40 +020015package body HW.PCI.MMConf
16with
17 Refined_State =>
18 (Address_State =>
19 (MM8.Base_Address, MM16.Base_Address, MM32.Base_Address),
20 PCI_State =>
21 (MM8.State, MM16.State, MM32.State))
22is
23
24 Default_Base_Address : constant Word64 :=
Nico Huber61f72872020-06-10 15:53:35 +020025 Calc_Base_Address (MMConf_Base, Dev);
Nico Huberef4545a2017-06-18 02:58:40 +020026
27 type Index16 is new Index range 0 .. Index'Last / 2;
28 type Index32 is new Index range 0 .. Index'Last / 4;
29
30 type Array8 is array (Index) of Byte with Atomic_Components;
31 type Array16 is array (Index16) of Word16 with Atomic_Components;
32 type Array32 is array (Index32) of Word32 with Atomic_Components;
33
34 package MM8 is new HW.MMIO_Range
35 (Default_Base_Address, Word8, Index, Array8);
36 package MM16 is new HW.MMIO_Range
37 (Default_Base_Address, Word16, Index16, Array16);
38 package MM32 is new HW.MMIO_Range
39 (Default_Base_Address, Word32, Index32, Array32);
40
41 procedure Read8 (Value : out Word8; Offset : Index) renames MM8.Read;
42
43 procedure Read16 (Value : out Word16; Offset : Index)
44 is
45 begin
46 MM16.Read (Value, Index16 (Offset / 2));
47 end Read16;
48
49 procedure Read32 (Value : out Word32; Offset : Index)
50 is
51 begin
52 MM32.Read (Value, Index32 (Offset / 4));
53 end Read32;
54
55 procedure Write8 (Offset : Index; Value : Word8) renames MM8.Write;
56
57 procedure Write16 (Offset : Index; Value : Word16)
58 is
59 begin
60 MM16.Write (Index16 (Offset / 2), Value);
61 end Write16;
62
63 procedure Write32 (Offset : Index; Value : Word32)
64 is
65 begin
66 MM32.Write (Index32 (Offset / 4), Value);
67 end Write32;
68
69 procedure Set_Base_Address (Base : Word64)
70 is
71 Base_Address : constant Word64 := Calc_Base_Address (Base, Dev);
72 begin
73 MM8.Set_Base_Address (Base_Address);
74 MM16.Set_Base_Address (Base_Address);
75 MM32.Set_Base_Address (Base_Address);
76 end Set_Base_Address;
77
78end HW.PCI.MMConf;