2 -- Copyright (C) 2016-2017 secunet Security Networks AG
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.
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.
15 with Libxhcidbg_Component.Devices;
19 pragma Elaborate_All (HW.MMIO_Regs);
21 pragma Elaborate_All (HW.MMIO_Range);
26 Abstract_State => (State, (DMA with External)),
32 procedure Poll (Now : Boolean := False);
38 Post => Len <= Len'Old;
43 Success : out Boolean)
45 Post => Len <= Len'Old;
47 ----------------------------------------------------------------------------
51 type Word2 is mod 2 ** 2;
52 type Word3 is mod 2 ** 3;
53 type Word4 is mod 2 ** 4;
54 type Word5 is mod 2 ** 5;
55 type Word10 is mod 2 ** 10;
56 type Word19 is mod 2 ** 19;
57 type Word20 is mod 2 ** 20;
58 type Word28 is mod 2 ** 28;
82 ----------------------------------------------------------------------------
84 Max_DMA_Xfers : constant := 64;
85 Max_Bulk_Size : constant := 4096;
86 Highest_Address : constant := 16#0000_ffff_ffff_ffff#;
88 Endpoint_Count : constant := 3;
89 -- Endpoint 1 (the control endpoint) is handled by hardware
90 -- Endpoint 2 is the bulk out endpoint
91 -- Endpoint 3 is the bulk in endpoint
92 subtype Endpoint_Range is Positive range 2 .. Endpoint_Count;
94 type Global_Transfer_Id is range 0 .. Max_DMA_Xfers - 1;
95 -- DMA space for the last transfer is reserved for the kernel.
96 subtype Transfer_Id is
97 Global_Transfer_Id range 0 .. Global_Transfer_Id'Last - 1;
99 ----------------------------------------------------------------------------
101 MMIO_Size : constant := Libxhcidbg_Component.Devices.Xhci_Xhci_Registers_Size;
102 type MMIO_Index is range 0 .. MMIO_Size / 4 - 1;
103 type MMIO_Array is array (MMIO_Index) of Word32
106 Size => MMIO_Size * 8;
107 pragma Warnings (Off, "atomic synchronization set");
108 package MMIO is new MMIO_Range
109 (Base_Addr => Libxhcidbg_Component.Devices.Xhci_Xhci_Registers_Address,
111 Index_T => MMIO_Index,
112 Array_T => MMIO_Array);
113 pragma Warnings (On, "atomic synchronization set");
115 type Cap_Registers is
116 (Capability_Registers_Length,
118 package Cap_S_Regs is new Sub_Regs (Cap_Registers);
119 Cap_Reg_Descs : constant Cap_S_Regs.Array_T :=
120 (Capability_Registers_Length => (16#00#, 7, 0),
121 XHCI_Extended_Caps => (16#10#, 31, 16));
122 package Cap_Regs is new MMIO_Regs (MMIO, 0, Cap_S_Regs, Cap_Reg_Descs);
126 Host_Controller_Reset,
128 Controller_Not_Ready);
129 package Op_S_Regs is new Sub_Regs (Op_Registers);
130 Op_Reg_Descs : constant Op_S_Regs.Array_T :=
131 (Run_Stop => (16#00#, 0, 0),
132 Host_Controller_Reset => (16#00#, 1, 1),
133 HC_Halted => (16#04#, 0, 0),
134 Controller_Not_Ready => (16#04#, 11, 11));
135 package Op_Regs is new MMIO_Regs (MMIO, 0, Op_S_Regs, Op_Reg_Descs);
137 type xCap_Registers is
140 package xCap_S_Regs is new Sub_Regs (xCap_Registers);
141 xCap_Reg_Descs : constant xCap_S_Regs.Array_T :=
142 (Capability_ID => (16#00#, 7, 0),
143 Next_xCap => (16#00#, 15, 8));
144 package xCap_Regs is new MMIO_Regs (MMIO, 0, xCap_S_Regs, xCap_Reg_Descs);
145 procedure Find_Next_xCap (Cap_Id : in Word8; Success : out Boolean);
147 type Legacy_Support_Registers is
148 (HC_BIOS_Owned_Semaphore,
149 HC_OS_Owned_Semaphore);
150 package Legacy_Support_S_Regs is new Sub_Regs (Legacy_Support_Registers);
151 Legacy_Support_Reg_Descs : constant Legacy_Support_S_Regs.Array_T :=
152 (HC_BIOS_Owned_Semaphore => (16#00#, 16, 16),
153 HC_OS_Owned_Semaphore => (16#00#, 24, 24));
154 package Legacy_Support_Regs is new MMIO_Regs
155 (DbC.MMIO, 0, Legacy_Support_S_Regs, Legacy_Support_Reg_Descs);
166 Link_Status_Event_Enable,
170 Debug_Max_Burst_Size,
174 Event_Ring_Not_Empty,
175 DbC_System_Bus_Reset,
178 Current_Connect_Status,
183 Connect_Status_Change,
185 Port_Link_Status_Change,
186 Port_Config_Error_Change,
193 package S_Regs is new Sub_Regs (Registers);
194 Reg_Descs : constant S_Regs.Array_T :=
195 (Doorbell_Target => (16#04#, 15, 8),
196 ERST_Size => (16#08#, 15, 0),
197 ERST_Base_Lo => (16#10#, 31, 0),
198 ERST_Base_Hi => (16#14#, 31, 0),
199 ER_Dequeue_Ptr_Lo => (16#18#, 31, 0),
200 ER_Dequeue_Ptr_Hi => (16#1c#, 31, 0),
201 DBC_CONTROL => (16#20#, 31, 0),
202 DbC_Run => (16#20#, 0, 0),
203 Link_Status_Event_Enable => (16#20#, 1, 1),
204 Halt_OUT_TR => (16#20#, 2, 2),
205 Halt_IN_TR => (16#20#, 3, 3),
206 DbC_Run_Change => (16#20#, 4, 4),
207 Debug_Max_Burst_Size => (16#20#, 23, 16),
208 Device_Address => (16#20#, 30, 24),
209 DbC_Enable => (16#20#, 31, 31),
210 DBC_STATUS => (16#24#, 31, 0),
211 Event_Ring_Not_Empty => (16#24#, 0, 0),
212 DbC_System_Bus_Reset => (16#24#, 1, 1),
213 Debug_Port_Number => (16#24#, 31, 24),
214 DBC_PORTSC => (16#28#, 31, 0),
215 Current_Connect_Status => (16#28#, 0, 0),
216 Port_Enable_Disable => (16#28#, 1, 1),
217 Port_Reset => (16#28#, 4, 4),
218 Port_Link_State => (16#28#, 8, 5),
219 Port_Speed => (16#28#, 13, 10),
220 Connect_Status_Change => (16#28#, 17, 17),
221 Port_Reset_Change => (16#28#, 21, 21),
222 Port_Link_Status_Change => (16#28#, 22, 22),
223 Port_Config_Error_Change => (16#28#, 23, 23),
224 Context_Pointer_Lo => (16#30#, 31, 0),
225 Context_Pointer_Hi => (16#34#, 31, 0),
226 DbC_Protocol => (16#38#, 7, 0),
227 Vendor_ID => (16#38#, 31, 16),
228 Product_ID => (16#3c#, 15, 0),
229 Device_Revision => (16#3c#, 31, 16));
230 package Regs is new MMIO_Regs (MMIO, 0, S_Regs, Reg_Descs);
232 procedure Ring_Doorbell (EP : Endpoint_Range)
234 Pre => Regs.Byte_Offset /= 0;
238 -- vim: set ts=8 sts=3 sw=3 et: