TEMU  2
The Terma Emulator
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros
PCI.h
Go to the documentation of this file.
1 //===------------------------------------------------------------*- C++ -*-===//
2 //
3 // T-EMU: The Terma Emulator
4 // (c) Terma 2019
5 // Authors: Mattias Holm <maho (at) terma.com>
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #ifndef TEMU_BUS_PCI_H
10 #define TEMU_BUS_PCI_H
11 #include <assert.h>
12 #include <stdint.h>
13 
14 #include "temu-c/Memory/Memory.h"
15 #include "temu-c/Support/Logging.h"
16 #include "temu-c/Support/Objsys.h"
17 
18 // Base and subclass codes
19 #define tePciBc_Pre 0x00
20 #define tePciSc_Any 0x00
21 #define tePciSc_Vga 0x01
22 
23 #define tePciBc_MassStorageController 0x01
24 #define tePciSc_ScsiBusController 0x00
25 #define tePciSc_IdeController 0x01
26 #define tePciSc_FloppyDiskController 0x02
27 #define tePciSc_IpiBusController 0x03
28 #define tePciSc_RaidController 0x04
29 #define tePciSc_AtaController 0x05
30 #define tePciSc_SataController 0x06 // Serial ATA
31 #define tePciSc_SasController 0x07 // Serial attached SCSI
32 #define tePciSc_OtherMassStorageController 0x80
33 
34 #define tePciBc_NetworkController 0x02
35 #define tePciSc_EthernetController 0x00
36 #define tePciSc_TokenRingController 0x01
37 #define tePciSc_FddiController 0x02
38 #define tePciSc_AtmController 0x03
39 #define tePciSc_IsdnController 0x04
40 #define tePciSc_WorldFipController 0x05
41 #define tePciSc_PicmgMultiComputing 0x06
42 #define tePciSc_OtherNetworkController 0x80
43 
44 #define tePciBc_DisplayController 0x03
45 #define tePciSc_VgaController 0x00
46 #define tePciSc_XgaController 0x01
47 #define tePciSc_3dController 0x02
48 #define tePciSc_OtherDisplayController 0x80
49 
50 #define tePciBc_MultimedaiDevice 0x04
51 #define tePciSc_VideoDevice 0x00
52 #define tePciSc_AudioDevice 0x01
53 #define tePciSc_ComptuterTelephonyDevice 0x02
54 #define tePciSc_OtherMultimediaDevice 0x80
55 
56 #define tePciBc_MemoryController 0x05
57 #define tePciSc_RAM 0x00
58 #define tePciSc_Flash 0x01
59 #define tePciSc_OtherMemoryController 0x80
60 
61 #define tePciBc_BridgeDevice 0x06
62 #define tePciSc_HostBridge 0x00
63 #define tePciSc_IsaBridge 0x01
64 #define tePciSc_EisaBridge 0x02
65 #define tePciSc_McaBridge 0x03
66 #define tePciSc_PciToPciBridge 0x04
67 #define tePciSc_PcmciaBridge 0x05
68 #define tePciSc_NuBusBridge 0x06
69 #define tePciSc_CardBusBridge 0x07
70 #define tePciSc_RaceWayBridge 0x08
71 #define tePciSc_SemiTransparentPciToPciBridge 0x09
72 #define tePciSc_InfiniBandToPciHostBridge 0x0a
73 #define tePciSc_OtherBridgeDevice 0x80
74 
75 #define tePciBc_SimpleCommunicationController 0x07
76 #define tePciSc_SerialController 0x00
77 #define tePciSc_ParallelPort 0x01
78 #define tePciSc_MultiPortSerialController 0x02
79 #define tePciSc_Modem 0x03
80 #define tePciSc_GpibController 0x04
81 #define tePciSc_SmartCard 0x05
82 #define tePciSc_OtherCommunicationsDevice 0x80
83 
84 #define tePciBc_BaseSystemPeripheral 0x08
85 #define tePciSc_Pic 0x00
86 #define tePciSc_DmaController 0x01
87 #define tePciSc_SystemTimer 0x02
88 #define tePciSc_RtcController 0x03
89 #define tePciSc_PciHotPlugController 0x04
90 #define tePciSc_SdHostController 0x05
91 #define tePciSc_OtherSystemPeripheral 0x80
92 
93 #define tePciBc_InputDevice 0x09
94 #define tePciSc_KeyboardController 0x00
95 #define tePciSc_Digitizer 0x01
96 #define tePciSc_MouseController 0x02
97 #define tePciSc_ScannerController 0x03
98 #define tePciSc_GameportController 0x04
99 #define tePciSc_OtherInputController 0x80
100 
101 #define tePciBc_DockingStation 0x0a
102 #define tePciSc_GenericDockingStation 0x00
103 #define tePciSc_OtherDockingStation 0x80
104 
105 #define tePciBc_Processor 0x0b
106 #define tePciSc_386 0x00
107 #define tePciSc_486 0x01
108 #define tePciSc_Pentium 0x02
109 #define tePciSc_Alpha 0x10
110 #define tePciSc_PowerPC 0x20
111 #define tePciSc_MIPS 0x30
112 #define tePciSc_CoProcessor 0x40
113 
114 #define tePciBc_SerialBusController 0x0c
115 #define tePciSc_FireWire 0x00
116 #define tePciSc_Ieee1394 0x00
117 #define tePciSc_AccessBus 0x01
118 #define tePciSc_Ssa 0x02
119 #define tePciSc_Usb 0x03
120 #define tePciSc_FibreChannel 0x04
121 #define tePciSc_SystemManagementBus 0x05
122 #define tePciSc_InfiniBand 0x06
123 #define tePciSc_Ipmi 0x07
124 #define tePciSc_SercosInterfaceStandard 0x08
125 #define tePciSc_CanBus 0x09
126 
127 #define tePciBc_WirelessController 0x0d
128 #define tePciSc_IrdaCompatibleController 0x00
129 #define tePciSc_ConsumerIrController 0x01
130 #define tePciSc_RfController 0x10
131 #define tePciSc_BluetoothController 0x11
132 #define tePciSc_BroadbandController 0x12
133 #define tePciSc_Ethernet802_11aController 0x20
134 #define tePciSc_Ethernet802_11bController 0x20
135 #define tePciSc_OtherWirelessController 0x80
136 
137 #define tePciBc_IntellegentIoController 0x0e
138 
139 #define tePciBc_SatelliteCommunicationController 0x0f
140 #define tePciSc_Tv 0x01
141 #define tePciSc_Audio 0x02
142 #define tePciSc_Voice 0x03
143 #define tePciSc_Data 0x04
144 
145 #define tePciBc_EncryptionDecryptionController 0x10
146 #define tePciSc_NetworkAndComputingCrypto 0x00
147 #define tePciSc_EntertainmentCrypto 0x10
148 #define tePciSc_OtherCrypto 0x80
149 
150 #define tePciBc_DataAcquisitionAndSignalProcessingController 0x11
151 #define tePciSc_DpioModules 0x00
152 #define tePciSc_PerformanceCounters 0x01
153 #define tePciSc_CommSyncPlusTimeAndFreq 0x10
154 #define tePciSc_ManagementCard 0x20
155 #define tePciSc_OtherDataAcquisitionSignalProcessingController 0x80
156 
157 #define tePciBc_Unknown 0xff
158 
159 typedef struct {
167 
168 typedef struct {
169  uint32_t DeviceVendorID;
170  uint32_t StatusCommand;
171  uint32_t ClassCodeRevID;
173  uint32_t BAR[6];
177  uint32_t CapPointer;
180 
181 typedef struct {
182  uint8_t Reserved;
183  uint8_t Length;
184  uint8_t NextPointer;
185  uint8_t CapabilityID;
186  uint32_t PCItoAHBAddressMapping[6];
191 
192 typedef struct {
193  void (*raiseReset)(temu_Object_ *);
194  void (*lowerReset)(temu_Object_ *);
195  void (*connect)(temu_Object_ *, temu_Object_ *);
196  void (*disconnect)(temu_Object_ *, temu_Object_ *);
198 TEMU_IFACE_REFERENCE_TYPE(temu_PCIBridge)
199 #define TEMU_PCI_BRIDGE_IFACE_TYPE "temu::PCIBridgeIface"
200 
201 typedef struct {
202  void (*startSelfTest)(
203  temu_Object_ *); // Optional, called when BIST bit 6 is set
204  temu_PCIConfig *(*getPciConfig)(void *);
205  // Writes to config space forwarded here
206  void (*writeConfig)(temu_Object_ *, temu_MemTransaction *MT);
207  uint64_t (*getPciBarSize)(temu_Object_ *, unsigned bar);
208  uint64_t (*getPciExpansionROMSize)(temu_Object_ *);
211 #define TEMU_PCI_DEVICE_IFACE_TYPE "temu::PCIDeviceIface"
212 
213 typedef struct {
217 
218 static inline void
219 temu_pciDeviceRegister(temu_Class *C)
220 {
221  temu_addProperty(C, "pciConfigDeviceVendorID",
222  offsetof(temu_PCIDevice, Conf.DeviceVendorID),
223  teTY_U32,
224  1, // Number of elements (1 = scalar)
225  NULL, NULL,
226  "PCI Device and Vendor ID");
227 
228 
229  temu_addProperty(C, "pciConfigStatusCommand",
230  offsetof(temu_PCIDevice, Conf.StatusCommand),
231  teTY_U32,
232  1, // Number of elements (1 = scalar)
233  NULL, NULL,
234  "PCI Status and Command Register");
235 
236  temu_addProperty(C, "pciConfigClassCodeRevID",
237  offsetof(temu_PCIDevice, Conf.ClassCodeRevID),
238  teTY_U32,
239  1, // Number of elements (1 = scalar)
240  NULL, NULL,
241  "PCI Class Code and Revision ID");
242 
243  temu_addProperty(C, "pciConfigBistHeaderLatencyCacheLineAndSize",
244  offsetof(temu_PCIDevice, Conf.BISTHeaderTypeLatencyTimerCacheLineSize),
245  teTY_U32,
246  1, // Number of elements (1 = scalar)
247  NULL, NULL,
248  "PCI BIST, Header Type, Latency and cache line size");
249 
250  temu_addProperty(C, "pciConfigBAR",
251  offsetof(temu_PCIDevice, Conf.BAR),
252  teTY_U32,
253  6, // Number of elements (1 = scalar)
254  NULL, NULL,
255  "PCI Base Address Registers");
256 
257  temu_addProperty(C, "pciConfigCardbusCISPointer",
258  offsetof(temu_PCIDevice, Conf.CardbusCISPointer),
259  teTY_U32,
260  1, // Number of elements (1 = scalar)
261  NULL, NULL,
262  "PCI Cardbus CIS Pointer");
263 
264  temu_addProperty(C, "pciConfigSubsystemVendorID",
265  offsetof(temu_PCIDevice, Conf.SubsystemVendorID),
266  teTY_U32,
267  1, // Number of elements (1 = scalar)
268  NULL, NULL,
269  "PCI Subsystem and Subsystem Vendor ID");
270 
271  temu_addProperty(C, "pciConfigExpansionROMBaseAddress",
272  offsetof(temu_PCIDevice, Conf.ExpansionROMBaseAddress),
273  teTY_U32,
274  1, // Number of elements (1 = scalar)
275  NULL, NULL,
276  "PCI Expansion ROM base address");
277 
278  temu_addProperty(C, "pciConfigCapabilityPointer",
279  offsetof(temu_PCIDevice, Conf.CapPointer),
280  teTY_U32,
281  1, // Number of elements (1 = scalar)
282  NULL, NULL,
283  "PCI Capability list pointer");
284 
285  temu_addProperty(C, "pciConfigMaxLatMinGntIntPinLine",
286  offsetof(temu_PCIDevice, Conf.MaxLatMinGntIntPinLine),
287  teTY_U32,
288  1, // Number of elements (1 = scalar)
289  NULL, NULL,
290  "PCI Max latency, min gnt, int pin and int line");
291 }
292 
293 static inline void
294 temu_pciSetDeviceId(temu_PCIConfig *C, uint16_t Val)
295 {
296  C->DeviceVendorID = ((uint32_t)Val << 16) | (C->DeviceVendorID & 0xffff);
297 }
298 
299 static inline void
300 temu_pciSetVendorId(temu_PCIConfig *C, uint16_t Val)
301 {
302  C->DeviceVendorID = (uint32_t)Val | (C->DeviceVendorID & 0xffff0000);
303 }
304 
305 static inline void
306 temu_pciSetStatus(temu_PCIConfig *C, uint16_t Val)
307 {
308  C->StatusCommand = ((uint32_t)Val << 16) | (C->StatusCommand & 0xffff);
309 }
310 
311 static inline void
312 temu_pciSetClassCode(temu_PCIConfig *C, uint32_t Val)
313 {
314  C->ClassCodeRevID &= 0x000000ff;
315  C->ClassCodeRevID |= Val << 8;
316 }
317 
318 static inline void
319 temu_pciSetRevId(temu_PCIConfig *C, uint8_t Val)
320 {
321  C->ClassCodeRevID &= 0xffffff00;
322  C->ClassCodeRevID |= Val;
323 }
324 
325 static inline void
326 temu_pciSetBist(temu_PCIConfig *C, uint8_t Val)
327 {
329  ((uint32_t)Val << 24) |
330  (C->BISTHeaderTypeLatencyTimerCacheLineSize & 0x00ffffff);
331 }
332 
333 static inline void
334 temu_pciSetHeaderType(temu_PCIConfig *C, uint8_t Val)
335 {
337  ((uint32_t)Val << 16) |
338  (C->BISTHeaderTypeLatencyTimerCacheLineSize & 0xff00ffff);
339 }
340 
341 static inline void
342 temu_pciSetLatencyTimer(temu_PCIConfig *C, uint8_t Val)
343 {
345  ((uint32_t)Val << 8) |
346  (C->BISTHeaderTypeLatencyTimerCacheLineSize & 0xffff00ff);
347 }
348 
349 static inline void
350 temu_pciSetCacheLineSize(temu_PCIConfig *C, uint8_t Val)
351 {
353  ((uint32_t)Val << 0) |
354  (C->BISTHeaderTypeLatencyTimerCacheLineSize & 0xffffff00);
355 }
356 
357 static inline void
358 temu_pciSetInterruptPin(temu_PCIConfig *C, uint8_t Val)
359 {
360  assert(Val < 0x05);
362  ((uint32_t)Val << 8) | (C->MaxLatMinGntIntPinLine & 0xffff00ff);
363 }
364 
365 static inline void
366 temu_pciSetSubsystemId(temu_PCIConfig *C, uint16_t Val)
367 {
368  C->SubsystemVendorID =
369  (uint32_t)Val << 16 | (C->SubsystemVendorID & 0x0000ffff);
370 }
371 
372 static inline void
373 temu_pciSetSubsystemVendorId(temu_PCIConfig *C, uint16_t Val)
374 {
375  C->SubsystemVendorID =
376  (uint32_t)Val << 0 | (C->SubsystemVendorID & 0xffff0000);
377 }
378 
379 #endif // !TEMU_BUS_PCI_H
uint8_t NextPointer
Definition: PCI.h:184
#define temu_Object_
Definition: Objsys.h:73
temu_MemoryIface MemBlock
Definition: PCI.h:165
uint8_t Reserved
Definition: PCI.h:182
uint32_t MaxLatMinGntIntPinLine
Definition: PCI.h:178
temu_MemoryIface IoBlock
Definition: PCI.h:164
temu_MemAccessIface IoAccess
Definition: PCI.h:161
uint32_t CardbusCISPointer
Definition: PCI.h:174
uint32_t AHBMasterPrefetchBurstLimit
Definition: PCI.h:189
void temu_Class
Definition: Objsys.h:58
uint8_t CapabilityID
Definition: PCI.h:185
uint32_t CapPointer
Definition: PCI.h:177
temu_PCIConfig Conf
Definition: PCI.h:215
temu_Object Super
Definition: PCI.h:214
uint32_t DeviceVendorID
Definition: PCI.h:169
#define TEMU_IFACE_REFERENCE_TYPE(N)
Definition: Objsys.h:129
uint32_t PCIBARSizeAndPrefetch
Definition: PCI.h:188
uint32_t SubsystemVendorID
Definition: PCI.h:175
temu_MemoryIface ConfigBlock
Definition: PCI.h:163
uint8_t Length
Definition: PCI.h:183
temu_MemAccessIface ConfigAccess
Definition: PCI.h:160
temu_MemAccessIface MemAccess
Definition: PCI.h:162
uint32_t StatusCommand
Definition: PCI.h:170
TEMU_API void temu_addProperty(temu_Class *Cls, const char *PropName, int Offset, temu_Type Typ, int Count, temu_PropWriter Wr, temu_PropReader Rd, const char *Doc)
uint32_t ClassCodeRevID
Definition: PCI.h:171
uint32_t ExpansionROMBaseAddress
Definition: PCI.h:176
uint32_t BISTHeaderTypeLatencyTimerCacheLineSize
Definition: PCI.h:172
uint32_t AHBBaseAndPCIBusCfg
Definition: PCI.h:187