1 //
2 // Copyright (c) 2010-2024 Antmicro
3 // Copyright (c) 2011-2015 Realtime Embedded
4 //
5 // This file is licensed under the MIT License.
6 // Full license text is available in 'licenses/MIT.txt'.
7 //
8 using System;
9 
10 namespace Antmicro.Renode.Peripherals.Bus
11 {
12     public class GaislerAPBPlugAndPlayRecord
13     {
GaislerAPBPlugAndPlayRecord()14         public GaislerAPBPlugAndPlayRecord()
15         {
16             ConfigurationWord = new IdReg();
17             BankAddressRegister = new Bar();
18         }
19 
20         public IdReg ConfigurationWord;
21         public Bar BankAddressRegister;
22 
23         public class IdReg
24         {
25             public uint Vendor = 0;
26             public uint Device = 0;
27             public uint Version = 0;
28             public uint Irq = 0;
GetValue()29             public uint GetValue()
30             {
31                 var value = ((Vendor & 0xff) << 24) | ((Device & 0xfff) << 12) | ((Version & 0x1f) << 5) | ((Irq & 0x1f) << 0 );
32                 return value;
33             }
34         }
35         public class Bar
36         {
37             public uint Address = 0;
38             public bool Prefechable = false;
39             public bool Cacheable = false;
40             public ulong Size = 0;
41             public SpaceType Type = SpaceType.None;
42 
GetValue()43             public uint GetValue()
44             {
45                 // Round the size up to a multiple of 0x100
46                 var size = (Size + 0xff) / 0x100;
47                 var mask = (uint)(0x1000 - size);
48                 var address = (Address >> 8) & 0xfff;
49                 var value = (address << 20) | (Prefechable ? 1u << 17 : 0) | (Cacheable ? 1u << 16 : 0) | ((mask & 0xfff) << 4) | ((uint)Type & 0xf);
50                 return value;
51             }
52         }
53 
ToUintArray()54         public uint[] ToUintArray()
55         {
56             var arr = new uint[2];
57             arr[0] = ConfigurationWord.GetValue();
58             arr[1] = BankAddressRegister.GetValue();
59 
60             return arr;
61         }
62 
63         public enum SpaceType : uint
64         {
65             None = 0x00,
66             APBIOSpace = 0x01,
67             AHBMemorySpace = 0x02,
68             AHBIOSpace = 0x03
69         }
70     }
71 }
72