blob: da4f42f008f4edaee7cf9c66a3ec9e3d14edbea4 [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
15package HW.PCI
16is
17
18 type Bus is range 0 .. 255;
19 type Slot is range 0 .. 31;
20 type Func is range 0 .. 7;
21
22 type Address is record
23 Bus : PCI.Bus;
24 Slot : PCI.Slot;
25 Func : PCI.Func;
26 end record;
27
28 type Index is range 0 .. 4095;
29
30 Vendor_Id : constant Index := 16#00#;
31 Device_Id : constant Index := 16#02#;
32 Command : constant Index := 16#04#;
33 Command_Memory : constant := 16#02#;
34 Header_Type : constant Index := 16#0e#;
35 Header_Type_Mask : constant := 16#7f#;
36 Header_Type_Normal : constant := 16#00#;
37
38 type Resource is (Res0, Res1, Res2, Res3, Res4, Res5);
39 Base_Address : constant array (Resource) of Index :=
40 (16#10#, 16#14#, 16#18#, 16#1c#, 16#20#, 16#24#);
41 Base_Address_Space_Mask : constant := 1 * 2 ** 0;
42 Base_Address_Space_IO : constant := 1 * 2 ** 0;
43 Base_Address_Space_Mem : constant := 0 * 2 ** 0;
44 Base_Address_Mem_Type_Mask : constant := 3 * 2 ** 1;
45 Base_Address_Mem_Type_32 : constant := 0 * 2 ** 1;
46 Base_Address_Mem_Type_1M : constant := 1 * 2 ** 1;
47 Base_Address_Mem_Type_64 : constant := 2 * 2 ** 1;
48 Base_Address_Mem_Prefetch : constant := 1 * 2 ** 3;
49 Base_Address_IO_Mask : constant := 16#ffff_fffc#;
50 Base_Address_Mem_Mask : constant := 16#ffff_fff0#;
51
52private
53 use type HW.Word64;
54 function Calc_Base_Address (Base_Addr : Word64; Dev : Address) return Word64
55 is
56 (Base_Addr +
57 Word64 (Dev.Bus) * 32 * 8 * 4096 +
58 Word64 (Dev.Slot) * 8 * 4096 +
59 Word64 (Dev.Func) * 4096);
60
61end HW.PCI;