1 // 2 // Copyright (c) 2010-2024 Antmicro 3 // 4 // This file is licensed under the MIT License. 5 // Full license text is available in 'licenses/MIT.txt'. 6 // 7 using System; 8 using Antmicro.Renode.Exceptions; 9 using Antmicro.Renode.Peripherals.CPU; 10 11 namespace Antmicro.Renode.Peripherals.Bus 12 { 13 public abstract class BusParametrizedRegistration : BusRangeRegistration 14 { BusParametrizedRegistration(ulong address, ulong size, ICPU cpu, ICluster<ICPU> cluster = null)15 public BusParametrizedRegistration(ulong address, ulong size, ICPU cpu, ICluster<ICPU> cluster = null) 16 : base(address, size, 0, cpu, cluster) 17 { 18 } 19 FillAccessMethods(IBusPeripheral peripheral, ref PeripheralAccessMethods methods)20 internal virtual void FillAccessMethods(IBusPeripheral peripheral, ref PeripheralAccessMethods methods) 21 { 22 methods.Peripheral = peripheral; 23 var readQuadWord = GetReadQuadWordMethod(peripheral); 24 if(readQuadWord != null) 25 { 26 methods.ReadQuadWord = new BusAccess.QuadWordReadMethod(readQuadWord); 27 } 28 var writeQuadWord = GetWriteQuadWordMethod(peripheral); 29 if(writeQuadWord != null) 30 { 31 methods.WriteQuadWord = new BusAccess.QuadWordWriteMethod(writeQuadWord); 32 } 33 var readDoubleWord = GetReadDoubleWordMethod(peripheral); 34 if(readDoubleWord != null) 35 { 36 methods.ReadDoubleWord = new BusAccess.DoubleWordReadMethod(readDoubleWord); 37 } 38 var writeDoubleWord = GetWriteDoubleWordMethod(peripheral); 39 if(writeDoubleWord != null) 40 { 41 methods.WriteDoubleWord = new BusAccess.DoubleWordWriteMethod(writeDoubleWord); 42 } 43 var readWord = GetReadWordMethod(peripheral); 44 if(readWord != null) 45 { 46 methods.ReadWord = new BusAccess.WordReadMethod(readWord); 47 } 48 var writeWord = GetWriteWordMethod(peripheral); 49 if(writeWord != null) 50 { 51 methods.WriteWord = new BusAccess.WordWriteMethod(writeWord); 52 } 53 var readByte = GetReadByteMethod(peripheral); 54 if(readByte != null) 55 { 56 methods.ReadByte = new BusAccess.ByteReadMethod(readByte); 57 } 58 var writeByte = GetWriteByteMethod(peripheral); 59 if(writeByte != null) 60 { 61 methods.WriteByte = new BusAccess.ByteWriteMethod(writeByte); 62 } 63 } 64 65 // Those functions return Func and Action instead of BusAccess.*Method, because the latter has `internal` visibility. 66 // That's also the reason why `FillAccessMethods` is internal - its visibility can only be as high as 67 // visibility of `PeripheralAccessMethods`, which is also marked `internal`. GetReadQuadWordMethod(IBusPeripheral _)68 public virtual Func<long, ulong> GetReadQuadWordMethod(IBusPeripheral _) => null; GetWriteQuadWordMethod(IBusPeripheral _)69 public virtual Action<long, ulong> GetWriteQuadWordMethod(IBusPeripheral _) => null; GetReadDoubleWordMethod(IBusPeripheral _)70 public virtual Func<long, uint> GetReadDoubleWordMethod(IBusPeripheral _) => null; GetWriteDoubleWordMethod(IBusPeripheral _)71 public virtual Action<long, uint> GetWriteDoubleWordMethod(IBusPeripheral _) => null; GetReadWordMethod(IBusPeripheral _)72 public virtual Func<long, ushort> GetReadWordMethod(IBusPeripheral _) => null; GetWriteWordMethod(IBusPeripheral _)73 public virtual Action<long, ushort> GetWriteWordMethod(IBusPeripheral _) => null; GetReadByteMethod(IBusPeripheral _)74 public virtual Func<long, byte> GetReadByteMethod(IBusPeripheral _) => null; GetWriteByteMethod(IBusPeripheral _)75 public virtual Action<long, byte> GetWriteByteMethod(IBusPeripheral _) => null; 76 RegisterForEachContext(Action<BusParametrizedRegistration> register)77 public virtual void RegisterForEachContext(Action<BusParametrizedRegistration> register) { } 78 } 79 } 80