| Nico Huber | ef4545a | 2017-06-18 02:58:40 +0200 | [diff] [blame^] | 1 | -- |
| 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 | |
| 15 | with HW.Config; |
| 16 | |
| 17 | package body HW.PCI.MMConf |
| 18 | with |
| 19 | Refined_State => |
| 20 | (Address_State => |
| 21 | (MM8.Base_Address, MM16.Base_Address, MM32.Base_Address), |
| 22 | PCI_State => |
| 23 | (MM8.State, MM16.State, MM32.State)) |
| 24 | is |
| 25 | |
| 26 | Default_Base_Address : constant Word64 := |
| 27 | Calc_Base_Address (Config.Default_MMConf_Base, Dev); |
| 28 | |
| 29 | type Index16 is new Index range 0 .. Index'Last / 2; |
| 30 | type Index32 is new Index range 0 .. Index'Last / 4; |
| 31 | |
| 32 | type Array8 is array (Index) of Byte with Atomic_Components; |
| 33 | type Array16 is array (Index16) of Word16 with Atomic_Components; |
| 34 | type Array32 is array (Index32) of Word32 with Atomic_Components; |
| 35 | |
| 36 | package MM8 is new HW.MMIO_Range |
| 37 | (Default_Base_Address, Word8, Index, Array8); |
| 38 | package MM16 is new HW.MMIO_Range |
| 39 | (Default_Base_Address, Word16, Index16, Array16); |
| 40 | package MM32 is new HW.MMIO_Range |
| 41 | (Default_Base_Address, Word32, Index32, Array32); |
| 42 | |
| 43 | procedure Read8 (Value : out Word8; Offset : Index) renames MM8.Read; |
| 44 | |
| 45 | procedure Read16 (Value : out Word16; Offset : Index) |
| 46 | is |
| 47 | begin |
| 48 | MM16.Read (Value, Index16 (Offset / 2)); |
| 49 | end Read16; |
| 50 | |
| 51 | procedure Read32 (Value : out Word32; Offset : Index) |
| 52 | is |
| 53 | begin |
| 54 | MM32.Read (Value, Index32 (Offset / 4)); |
| 55 | end Read32; |
| 56 | |
| 57 | procedure Write8 (Offset : Index; Value : Word8) renames MM8.Write; |
| 58 | |
| 59 | procedure Write16 (Offset : Index; Value : Word16) |
| 60 | is |
| 61 | begin |
| 62 | MM16.Write (Index16 (Offset / 2), Value); |
| 63 | end Write16; |
| 64 | |
| 65 | procedure Write32 (Offset : Index; Value : Word32) |
| 66 | is |
| 67 | begin |
| 68 | MM32.Write (Index32 (Offset / 4), Value); |
| 69 | end Write32; |
| 70 | |
| 71 | procedure Set_Base_Address (Base : Word64) |
| 72 | is |
| 73 | Base_Address : constant Word64 := Calc_Base_Address (Base, Dev); |
| 74 | begin |
| 75 | MM8.Set_Base_Address (Base_Address); |
| 76 | MM16.Set_Base_Address (Base_Address); |
| 77 | MM32.Set_Base_Address (Base_Address); |
| 78 | end Set_Base_Address; |
| 79 | |
| 80 | end HW.PCI.MMConf; |