1 // 2 // Copyright (c) 2010-2018 Antmicro 3 // 4 // This file is licensed under the MIT License. 5 // Full license text is available in 'licenses/MIT.txt'. 6 // 7 using Antmicro.Renode.Core.Structure.Registers; 8 9 namespace Antmicro.Renode.Peripherals.PCI.Capabilities 10 { 11 public class PCIeCapability : Capability 12 { PCIeCapability(PCIeBasePeripheral parent)13 public PCIeCapability(PCIeBasePeripheral parent) : base(parent, 0x10, 0x3C) 14 { 15 Registers.Add(new DoubleWordRegister(parent) 16 .WithValueField(0, 8, FieldMode.Read, valueProviderCallback: _ => Id, name: "PCI Express Cap ID") 17 .WithValueField(8, 8, FieldMode.Read, valueProviderCallback: _ => NextCapability, name: "Next Cap Pointer") 18 .WithValueField(16, 4, FieldMode.Read, valueProviderCallback: _ => 0x2 /* current specification */, name: "Capability Version") 19 .WithEnumField(20, 4, FieldMode.Read, valueProviderCallback: (DeviceType _) => parent.HeaderType.HasFlag(HeaderType.Bridge) ? DeviceType.RootComplexIntegratedEndpoint : DeviceType.PCIExpressEndpoint, name: "Device/Port Type") // this is a guess and an approximation to the two types of devices we have 20 .WithFlag(24, FieldMode.Read, valueProviderCallback: _ => false, name: "Slot Implemented") 21 .WithTag("Interrupt Message Number", 25, 5) 22 .WithReservedBits(30, 2) 23 ); 24 } 25 26 private enum DeviceType 27 { 28 PCIExpressEndpoint = 0x0, 29 LegacyPCIExpressEndpoint = 0x1, 30 RootPortOfPCIExpressRootComplex = 0x4, 31 UpstreamPortOfPCIExpressSwitch = 0x5, 32 DownstreamPortOfPCIExpressSwitch = 0x6, 33 PCIExpressToPCIBridge = 0x7, 34 PCIToPCIExpressBridge = 0x8, 35 RootComplexIntegratedEndpoint = 0x9, 36 RootComplexEventCollector = 0xA, 37 } 38 } 39 }