1 |
2 |
mihad |
//==========================//
|
2 |
|
|
// PCI Target state machine //
|
3 |
|
|
//==========================//
|
4 |
|
|
|
5 |
|
|
`include "pci_stat.v"
|
6 |
|
|
|
7 |
|
|
module pci_target32_sm
|
8 |
|
|
(
|
9 |
|
|
// system inputs
|
10 |
|
|
clk_in,
|
11 |
|
|
reset_in,
|
12 |
|
|
// master inputs
|
13 |
|
|
pci_frame_in,
|
14 |
|
|
pci_irdy_in,
|
15 |
|
|
// target response outputs
|
16 |
|
|
pci_trdy_out,
|
17 |
|
|
pci_stop_out,
|
18 |
|
|
pci_devsel_out,
|
19 |
|
|
// address, data, bus command, byte enable in/outs
|
20 |
|
|
pci_ad_in,
|
21 |
|
|
pci_ad_out,
|
22 |
|
|
pci_ad_en_out,
|
23 |
|
|
pci_cbe_in,
|
24 |
|
|
|
25 |
|
|
// other side of state machine
|
26 |
|
|
address_o,
|
27 |
|
|
addr_claim_i,
|
28 |
|
|
bc_o,
|
29 |
|
|
data_o,
|
30 |
|
|
data_i,
|
31 |
|
|
be_o,
|
32 |
|
|
req_o,
|
33 |
|
|
rdy_o,
|
34 |
|
|
status_i,
|
35 |
|
|
last_o
|
36 |
|
|
) ;
|
37 |
|
|
|
38 |
|
|
// system inputs
|
39 |
|
|
input clk_in,
|
40 |
|
|
reset_in ;
|
41 |
|
|
|
42 |
|
|
/*==================================================================================================================
|
43 |
|
|
PCI interface signals - bidirectional signals are divided to inputs and outputs in I/O cells instantiation
|
44 |
|
|
module. Enables are separate signals.
|
45 |
|
|
==================================================================================================================*/
|
46 |
|
|
// master inputs
|
47 |
|
|
input pci_frame_in ;
|
48 |
|
|
input pci_irdy_in ;
|
49 |
|
|
|
50 |
|
|
// target response outputs
|
51 |
|
|
output pci_trdy_out,
|
52 |
|
|
pci_stop_out,
|
53 |
|
|
pci_devsel_out ;
|
54 |
|
|
|
55 |
|
|
// address, data, bus command, byte enable in/outs
|
56 |
|
|
input [31:0] pci_ad_in ;
|
57 |
|
|
output [31:0] pci_ad_out ;
|
58 |
|
|
output pci_ad_en_out ;
|
59 |
|
|
input [3:0] pci_cbe_in ;
|
60 |
|
|
|
61 |
|
|
/*==================================================================================================================
|
62 |
|
|
Other side of master state machine - the one that issues requests.
|
63 |
|
|
==================================================================================================================*/
|
64 |
|
|
/*==================================================================================================================
|
65 |
|
|
address output - address always qualifies current data present at data_i input or data_o output and because of that
|
66 |
|
|
it must be written to counter at address phase. After all dta phases address counter must be
|
67 |
|
|
incremented and the address claim input signal tells if the address falls into valid address space.
|
68 |
|
|
If address (address from PCI bus at address phase) is not claimed, then PCI Target must not respond
|
69 |
|
|
in any way, but if address from burst transfere crosses valid address space boundaries after first
|
70 |
|
|
data phase, then PCI Target respond with Target Abort.
|
71 |
|
|
==================================================================================================================*/
|
72 |
|
|
output [31:0] address_o ; // current request address output
|
73 |
|
|
|
74 |
|
|
/*==================================================================================================================
|
75 |
|
|
address claim input - address claim input always confirms if current address present at address_o output falls
|
76 |
|
|
into valid address space (for address phase) or is still in the valid address space (for all
|
77 |
|
|
data phases after first one). Address decoders with address translation are implemented at
|
78 |
|
|
the backend.
|
79 |
|
|
==================================================================================================================*/
|
80 |
|
|
input addr_claim_i ; // current request address claim input
|
81 |
|
|
|
82 |
|
|
/*==================================================================================================================
|
83 |
|
|
bus command output - bus command output must be valid through all transfere to identifie what backend should do (it
|
84 |
|
|
is PCI bus command). Because of that it must be latched at address phase when req_o is
|
85 |
|
|
asserted.
|
86 |
|
|
==================================================================================================================*/
|
87 |
|
|
output [3:0] bc_o ; // current request bus command output
|
88 |
|
|
|
89 |
|
|
/*==================================================================================================================
|
90 |
|
|
data input - for PCI read bus commands - this bus provides valid read data from backend during read commands when
|
91 |
|
|
req_o and rdy_o are asserted (rdy_o - PCI Target state machine is ready to receive data) and backend
|
92 |
|
|
signals `TRANSFERED status on status_i bus. On the rising edge of clock data must be latched from
|
93 |
|
|
data_i bus. After this, PCI Target state machine must deasert rdy_o if it is not ready to accept more
|
94 |
|
|
data.
|
95 |
|
|
==================================================================================================================*/
|
96 |
|
|
input [31:0] data_i ; // for read operations - current dataphase data input
|
97 |
|
|
|
98 |
|
|
/*==================================================================================================================
|
99 |
|
|
data output - for PCI write bus commands - data on this bus is provided from PCI Target state machine during write
|
100 |
|
|
commands and is qualified with rdy_o asserted. Backend is responsible for storing the data. Backend
|
101 |
|
|
signals if it is ready to store data with `TRANSFERED status on status_i bus. When that happens, PCI
|
102 |
|
|
Target state machine should provide new data imediately after rising clock edge or deassert rdy_o if
|
103 |
|
|
it is not ready to do so.
|
104 |
|
|
==================================================================================================================*/
|
105 |
|
|
output [31:0] data_o ; // for write operations - current request data output
|
106 |
|
|
|
107 |
|
|
/*==================================================================================================================
|
108 |
|
|
byte enable output - active low byte enables drived from BE# pins on pci during transfers - they are valid at every
|
109 |
|
|
data phase (rdy_o asserted). No matter which byte enables are active still all data must be
|
110 |
|
|
privided to backend or to PCI (write or read).
|
111 |
|
|
==================================================================================================================*/
|
112 |
|
|
output [3:0] be_o ; // current dataphase byte enable outputs
|
113 |
|
|
|
114 |
|
|
/*==================================================================================================================
|
115 |
|
|
request and ready outputs from PCI Target - req_o output means that PCI target has some transaction request for
|
116 |
|
|
backend (address and all data phases following).
|
117 |
|
|
During write requests PCI Target must provide address and bus command at address phase (and all data phases) and
|
118 |
|
|
byte enables and data during all data phases. During whole request req_o must be aserted, meanwhile rdy_o is
|
119 |
|
|
asserted with valid byte enables and data. Transaction and data phases are completed regarding status_i bus from
|
120 |
|
|
backend described later.
|
121 |
|
|
During read requests PCI Target must provide address and bus command at address phase (and all data phases) and
|
122 |
|
|
byte enables during all data phases. During whole request req_o must be aserted, meanwhile rdy_o is asserted when
|
123 |
|
|
PCI Target state machine is ready (PCI Master is pending for data) for data until backend signal status on status_i
|
124 |
|
|
bus that data are ready (`TRANSFERED) or to terminate with reatry (`RETRY - because all read transactions are
|
125 |
|
|
delayed read transactions). Other posibilitys on status_i bus are described later. When status `TRANSFERED is
|
126 |
|
|
signaled by backend, PCI Target must release rdy_o signal if it is not capable to receive more data. When PCI
|
127 |
|
|
Target state machine terminates with retry, PCI Master will release the PCI bus and PCI Target must also deasert
|
128 |
|
|
req_o signal.
|
129 |
|
|
==================================================================================================================*/
|
130 |
|
|
output req_o ; // PCI Target cycle is requested to backend
|
131 |
|
|
output rdy_o ; // requestor indicates that data is ready to be sent for write transaction and ready to
|
132 |
|
|
// be received on read transaction
|
133 |
|
|
/*==================================================================================================================
|
134 |
|
|
Last output - this output in conjuction with req_o and rdy_o qualifies last data beat in current request.
|
135 |
|
|
for single transfers all three signals are asserted in parallel, for burst transfers last_o is inactive
|
136 |
|
|
until last intended data is present at data_o ( assign last_o = pci_frame_in && ~pci_irdy_in ; boath
|
137 |
|
|
PCI signals are active low ).
|
138 |
|
|
==================================================================================================================*/
|
139 |
|
|
output last_o ; // last dataphase in current transaction indicator
|
140 |
|
|
|
141 |
|
|
/*==================================================================================================================
|
142 |
|
|
Status input - Status is always provided from the backend depending on FIFO progress. Status descriptions:
|
143 |
|
|
`WAIT - Default status - Means that current request is not processed in any way yet - this status is propagated
|
144 |
|
|
to Target state machine when backend is waiting FIFO to be ready while Target state machine wants to read/
|
145 |
|
|
write from/to FIFO (PCI Target then inserts wait states), or rdy_o output is down (nothing is to be done).
|
146 |
|
|
`TRANSFERED - Status means, that current data phase is completing succesfully on FIFO. During writes, this status
|
147 |
|
|
signals to the PCI Target state machine that it should provide new data imediately after rising clock
|
148 |
|
|
edge or deassert rdy_o if it is not ready to do so. During reads, this status signals to the PCI Target
|
149 |
|
|
state machine that on the rising edge of clock data must be latched from data_i bus. After this, PCI
|
150 |
|
|
Target state machine must deasert rdy_o if it is not ready to accept more data.
|
151 |
|
|
`DISCONNECT_WO_DATA - Backend signals this status to the PCI Target state machine when e.g. during write transaction,
|
152 |
|
|
in the middle of the burst, FIFO becommes full and no data can be written into it anymore.
|
153 |
|
|
Disconnect without data is normal termination and PCI Target state machine must also emediately
|
154 |
|
|
deaserts rdy_o and req_o.
|
155 |
|
|
`DISCONNECT_W_DATA - Backend signals this status to the PCI Target state machine when e.g. during write transaction,
|
156 |
|
|
in the middle of the burst, FIFO is almost full and only this data can be written into it or
|
157 |
|
|
if burst is attempt to I/O space, to which only single transactions are allowed, this way
|
158 |
|
|
burst is broken into single transfers.
|
159 |
|
|
Disconnect with data is normal termination and PCI Target state machine must also emediately
|
160 |
|
|
deaserts rdy_o and req_o.
|
161 |
|
|
`TABORT - Target Abort status - Backend signals this status to PCI Target state machine when there e.g. data parrity
|
162 |
|
|
error occures (depending of the backend design) in the middle of the transfere or
|
163 |
|
|
e.g. address parrity error occurs at the beginning of the transfere or if address
|
164 |
|
|
in the middle of the burst transfere crosses the valid address space boundaries.
|
165 |
|
|
PCI Target state machine must terminate the transaction with Target Abort if it
|
166 |
|
|
receives this status and it must deaserts rdy_o and req_o.
|
167 |
|
|
`RETRY - Backend signals this status to PCI Target state machine whenever there is a read transaction and backend
|
168 |
|
|
cannot start providing data because it does not have any data ready yet (e.g. FIFO still empty since all
|
169 |
|
|
reads are delayed reads) or when there is a write transaction and backend cannot start receiving data
|
170 |
|
|
because FIFO is still full.
|
171 |
|
|
PCI Target state machine is responsible to terminate transaxction with retry and emediately deaserts
|
172 |
|
|
rdy_o and req_o.
|
173 |
|
|
==================================================================================================================*/
|
174 |
|
|
input [3:0] status_i ; // current dataphase completion status
|
175 |
|
|
|
176 |
|
|
|
177 |
|
|
endmodule
|