61class ipcc :
public sc_core::sc_module
75 GLOBAL_SIGNAL_STATUS_0,
76 GLOBAL_SIGNAL_STATUS_1,
77 GLOBAL_SIGNAL_CLEAR_0,
78 GLOBAL_SIGNAL_CLEAR_1,
82 GLOBAL_QUAL_SIGNAL_STATUS_0,
83 GLOBAL_QUAL_SIGNAL_STATUS_1,
85 RECV_ID_PHYS = 0x48 / 4,
86 RECV_CLIENT_PRIORITY_n = 0x100 / 4,
87 RECV_CLIENT_ENABLE_0_n = 0x200 / 4,
88 RECV_CLIENT_ENABLE_1_n = 0x300 / 4,
89 RECV_CLIENT_DISABLE_0_n = 0x400 / 4,
90 RECV_CLIENT_DISABLE_1_n = 0x500 / 4,
92 CLIENT_SIGNAL_STATUS_0_n = 0x600 / 4,
93 CLIENT_SIGNAL_STATUS_1_n = 0x700 / 4,
94 CLIENT_ENABLE_STATUS_0_n = 0x800 / 4,
95 CLIENT_ENABLE_STATUS_1_n = 0x900 / 4,
98 enum Protocol { MPROC = 0, COMPUTE_L0 = 1, COMPUTE_L1 = 2, PCIE_MSI = 3 };
99 static constexpr unsigned int NUM_PROTOCOLS = 4;
100 static_assert(NUM_PROTOCOLS <= 4,
"IPCC supports at most four protocols");
102 static constexpr int protocol_physical_client_count(
unsigned int protocol)
104 return protocol == PCIE_MSI ? 60 : MAX_CLIENT_SIZE;
110 uint32_t regs[0x1000 / 4];
113 uint32_t p_client_size;
115 bool status(
int client,
int signal)
117 assert(client < p_client_size);
118 assert(signal < p_client_size);
120 return (regs[CLIENT_SIGNAL_STATUS_0_n + client] & (1 << signal)) != 0;
122 return (regs[CLIENT_SIGNAL_STATUS_1_n + client] & (1 << (signal - 32))) != 0;
124 bool enable(
int client,
int signal)
126 assert(client < p_client_size);
127 assert(signal < p_client_size);
129 return (regs[CLIENT_ENABLE_STATUS_0_n + client] & (1 << signal)) != 0;
131 return (regs[CLIENT_ENABLE_STATUS_1_n + client] & (1 << (signal - 32))) != 0;
134 void set_status(
int client,
int signal)
136 assert(client < p_client_size);
137 assert(signal < p_client_size);
139 regs[CLIENT_SIGNAL_STATUS_0_n + client] |= (1 << signal);
141 regs[CLIENT_SIGNAL_STATUS_1_n + client] |= (1 << (signal - 32));
144 void clear_status(
int client,
int signal)
146 assert(client < p_client_size);
147 assert(signal < p_client_size);
149 regs[CLIENT_SIGNAL_STATUS_0_n + client] &= ~(1 << signal);
151 regs[CLIENT_SIGNAL_STATUS_1_n + client] &= ~(1 << (signal - 32));
154 void set_enable(
int client,
int signal)
156 assert(client < p_client_size);
157 assert(signal < p_client_size);
159 regs[CLIENT_ENABLE_STATUS_0_n + client] |= (1 << signal);
161 regs[CLIENT_ENABLE_STATUS_1_n + client] |= (1 << (signal - 32));
164 void clear_enable(
int client,
int signal)
166 assert(client < p_client_size);
167 assert(signal < p_client_size);
169 regs[CLIENT_ENABLE_STATUS_0_n + client] &= ~(1 << signal);
171 regs[CLIENT_ENABLE_STATUS_1_n + client] &= ~(1 << (signal - 32));
176 memset(regs, 0,
sizeof(regs));
177 regs[VERSION] = p_version;
178 regs[RECV_ID] = 0xFFFFFFFF;
180 IPC_client(): p_client_size(MAX_CLIENT_SIZE), p_version(0x10200) { reset(); };
182 IPC_client client[NUM_PROTOCOLS][MAX_CLIENT_SIZE];
183 sc_core::sc_event update_irq_ev;
185 int logical_of_physical[MAX_CLIENT_SIZE];
186 int physical_of_logical[MAX_CLIENT_SIZE];
188 int physical_client(
unsigned int protocol,
int logical_client)
const
190 for (
int client = 0; client < protocol_physical_client_count(protocol); client++) {
191 if (logical_of_physical[client] == logical_client)
return client;
197 cci::cci_param<unsigned int> p_num_irq;
198 cci::cci_param<unsigned int> p_hw_version;
199 cci::cci_param<std::string> p_logical_ids;
201 template <
class Port>
202 static void safe_write(Port& p,
bool v)
204 if (p.size() > 0) p->write(v);
207 uint32_t read(IPC_client& src, uint64_t addr)
209 uint32_t ret = src.regs[addr / 4];
214 uint32_t logical_id = src.regs[RECV_ID];
215 if ((src.regs[CONFIG] & 0x1) && (logical_id != 0xffffffff)) {
216 src.clear_status(logical_id >> 16, logical_id & 0xffff);
217 src.regs[RECV_ID] = 0xffffffff;
218 src.regs[RECV_ID_PHYS] = 0xffffffff;
226 void write(IPC_client& src, uint64_t addr, uint32_t data)
228 src.regs[addr / 4] = data;
232 int s = data & 0xffff;
233 int src_protocol = src.regs[ID] & 0x3f;
234 int src_logical = (src.regs[ID] >> 16) & 0x3f;
235 if (data & 0x80000000) {
236 SCP_INFO(()) <<
"IPCC_SEND broadcast src_logical=" << std::dec << src_logical
237 <<
" protocol=" << src_protocol <<
" signal=" << s <<
" raw=0x" << std::hex << data
239 for (
int c = 0; c < src.p_client_size; c++) {
243 int target_logical = (data >> 16) & 0xffff;
244 int c = physical_client(src_protocol, target_logical & 0x3f);
245 SCP_INFO(()) <<
"IPCC_SEND src_logical=" << std::dec << src_logical <<
" protocol=" << src_protocol
246 <<
" target_logical=" << target_logical <<
" target_phys=" << c <<
" signal=" << s
247 <<
" raw=0x" << std::hex << data << std::dec;
248 if ((src_logical == 6 || src_logical == 18) && target_logical == 8 && s == 2) {
249 SCP_WARN(()) <<
"IPCC_CDSP_READY_KICK src_logical=" << std::dec << src_logical
250 <<
" target_logical=" << target_logical <<
" signal=" << s <<
" raw=0x" << std::hex
257 case RECV_SIGNAL_ENABLE: {
258 int c = (data >> 16) & 0xffff;
259 int s = (data & 0xffff);
260 int p = src.regs[ID] & 0x3f;
261 int dst_c = (src.regs[ID] >> 16) & 0x3f;
262 SCP_DEBUG(()) <<
"IPCC_LOG ENABLE: DstClient " << dst_c <<
" (Proto " << p <<
") enabled Signal " << s
263 <<
" from SrcClient " << c;
264 SCP_INFO(()) <<
"IPCC_RECV_ENABLE dst_logical=" << std::dec << dst_c <<
" src_logical=" << c
265 <<
" signal=" << s <<
" raw=0x" << std::hex << data << std::dec;
266 src.set_enable(c, s);
269 case RECV_SIGNAL_DISABLE: {
270 int c = (data >> 16) & 0xffff;
271 int s = (data & 0xffff);
272 src.clear_enable(c, s);
275 case RECV_SIGNAL_CLEAR: {
276 int c = (data >> 16) & 0xffff;
277 int s = (data & 0xffff);
278 int dst_c = (src.regs[ID] >> 16) & 0x3f;
279 SCP_INFO(()) <<
"IPCC_RECV_CLEAR dst_logical=" << std::dec << dst_c <<
" src_logical=" << c
280 <<
" signal=" << s <<
" raw=0x" << std::hex << data << std::dec;
281 src.clear_status(c, s);
285 uint32_t
id = src.regs[ID];
287 memset(src.regs, 0,
sizeof(src.regs));
288 src.regs[VERSION] = p_hw_version.get_value();
289 src.regs[RECV_ID] = 0xFFFFFFFF;
296 void send(IPC_client& src,
int c,
int s)
298 int p = src.regs[ID] & 0x3f;
299 int sc = (src.regs[ID] >> 16) & 0x3f;
300 if (p >= NUM_PROTOCOLS) {
301 SCP_WARN(()) <<
"Ignoring send from unsupported protocol " << p;
304 if (c < 0 || c >= protocol_physical_client_count(p)) {
305 SCP_WARN(()) <<
"Ignoring send to unsupported client " << c <<
" on protocol " << p;
308 IPC_client& dst = client[p][c];
309 SCP_DEBUG(()) <<
"IPCC_LOG STATUS SET: DstClient " << c <<
" (Proto " << p <<
") received Signal " << s
310 <<
" from SrcClient " << sc;
311 dst.set_status(sc, s);
315 int client_size = client[0][0].p_client_size;
316 for (
int c = 0; c < client_size; c++) {
318 for (
unsigned int p = 0; p < NUM_PROTOCOLS; p++) {
319 if (c >= protocol_physical_client_count(p))
continue;
325 for (
int sc = 0; sc < client_size; sc++) {
326 for (
int s = 0; s < client_size; s++) {
327 if (client[p][c].status(sc, s)) {
329 if ((client[p][c].regs[CONFIG] & 0x80000000) == 0) {
330 if (client[p][c].enable(sc, s)) {
331 int pr = client[p][c].regs[RECV_CLIENT_PRIORITY_n + sc];
332 if (irqcount == 0 || pr > prio) {
343 allirqcount += irqcount;
345 int phys_cli = (cli < MAX_CLIENT_SIZE && physical_of_logical[cli] >= 0) ? physical_of_logical[cli]
347 client[p][c].regs[RECV_ID] = (cli << 16) + sig;
348 client[p][c].regs[RECV_ID_PHYS] = (phys_cli << 16) + sig;
350 client[p][c].regs[RECV_ID] = 0xffffffff;
351 client[p][c].regs[RECV_ID_PHYS] = 0xffffffff;
355 safe_write(irq_mproc[c], irqcount != 0);
358 safe_write(irq_compute_l0[c], irqcount != 0);
361 safe_write(irq_compute_l1[c], irqcount != 0);
364 safe_write(irq_pcie_msi[c], irqcount != 0);
367 SCP_FATAL(()) <<
"Unsupported IPCC protocol " << p;
370 if (allirqcount >= 1) {
371 if (!irq_status[c]) {
372 SCP_INFO(()) <<
"SEND IRQ " << c;
373 irq_status[c] =
true;
374 safe_write(irq[c],
true);
378 SCP_INFO(()) <<
"CLEAR IRQ " << c;
379 irq_status[c] =
false;
380 safe_write(irq[c],
false);
385 void b_transport(tlm::tlm_generic_payload& txn, sc_core::sc_time& delay)
387 unsigned int len = txn.get_data_length();
388 unsigned char* ptr = txn.get_data_ptr();
389 sc_dt::uint64 addr = txn.get_address();
390 if (len >
sizeof(client)) {
391 txn.set_response_status(tlm::TLM_ADDRESS_ERROR_RESPONSE);
396 int c = (addr / 0x1000) & 0x3f;
397 uint64_t p = addr / 0x40000;
398 if (p >= NUM_PROTOCOLS || addr >= 0x100000ULL || (p == PCIE_MSI && c >= 60)) {
399 SCP_WARN(()) <<
"Ignoring access to unsupported protocol " << p;
400 txn.set_response_status(tlm::TLM_ADDRESS_ERROR_RESPONSE);
403 switch (txn.get_command()) {
404 case tlm::TLM_READ_COMMAND: {
405 uint32_t data = read(client[p][c], addr & 0xfff);
406 memcpy(ptr, &data, len);
407 SCP_INFO(()) <<
"b_transport read " << std::hex << addr <<
" " << data;
410 case tlm::TLM_WRITE_COMMAND: {
412 memcpy(&data, ptr, len);
413 SCP_INFO(()) <<
"b_transport write " << std::hex << addr <<
" " << data;
414 write(client[p][c], addr & 0xfff, data);
418 SCP_ERR(()) <<
"TLM command not supported";
422 txn.set_response_status(tlm::TLM_OK_RESPONSE);
424 update_irq_ev.notify(sc_core::SC_ZERO_TIME);
428 tlm_utils::simple_target_socket<ipcc, DEFAULT_TLM_BUSWIDTH> socket;
430 sc_core::sc_vector<InitiatorSignalSocket<bool>> irq;
431 bool irq_status[MAX_CLIENT_SIZE] = {
false };
432 sc_core::sc_vector<InitiatorSignalSocket<bool>> irq_mproc;
433 sc_core::sc_vector<InitiatorSignalSocket<bool>> irq_compute_l0;
434 sc_core::sc_vector<InitiatorSignalSocket<bool>> irq_compute_l1;
435 sc_core::sc_vector<InitiatorSignalSocket<bool>> irq_pcie_msi;
438 ipcc(sc_core::sc_module_name name)
439 : p_num_irq(
"num_irq", MAX_CLIENT_SIZE,
"Number of irq")
440 , p_hw_version(
"hw_version", 0x10200,
"IPCC HW VERSION register value")
441 , p_logical_ids(
"logical_ids",
"",
"Comma-separated logical IDs per physical slot (empty=identity)")
442 , socket(
"target_socket")
443 , irq(
"irq", p_num_irq)
444 , irq_mproc(
"irq_mproc", p_num_irq)
445 , irq_compute_l0(
"irq_compute_l0", p_num_irq)
446 , irq_compute_l1(
"irq_compute_l1", p_num_irq)
447 , irq_pcie_msi(
"irq_pcie_msi", p_num_irq)
450 SCP_TRACE(())(
"Init");
451 for (
int i = 0; i < MAX_CLIENT_SIZE; i++) {
452 logical_of_physical[i] = i;
453 physical_of_logical[i] = -1;
456 std::string s = p_logical_ids.get_value();
458 while (!s.empty() && i < MAX_CLIENT_SIZE) {
459 size_t pos = s.find(
',');
460 int lid = std::stoi(pos == std::string::npos ? s : s.substr(0, pos));
461 if (lid >= 0 && lid < MAX_CLIENT_SIZE) {
462 logical_of_physical[i] = lid;
464 if (pos == std::string::npos)
break;
465 s = s.substr(pos + 1);
469 for (
int i = 0; i < MAX_CLIENT_SIZE; i++) {
470 int lid = logical_of_physical[i];
471 if (lid >= 0 && lid < MAX_CLIENT_SIZE && physical_of_logical[lid] < 0) {
472 physical_of_logical[lid] = i;
476 int client_size = client[0][0].p_client_size;
477 uint32_t hw_ver = p_hw_version.get_value();
478 for (
unsigned int p = 0; p < NUM_PROTOCOLS; p++) {
479 for (
int c = 0; c < protocol_physical_client_count(p); c++) {
480 client[p][c].p_version = hw_ver;
481 client[p][c].regs[VERSION] = hw_ver;
482 client[p][c].regs[ID] = (logical_of_physical[c] << 16) + p;
485 socket.register_b_transport(
this, &ipcc::b_transport);
487 SC_METHOD(update_irq);
488 sensitive << update_irq_ev;
490 reset.register_value_changed_cb([&](
bool value) {
492 SCP_WARN(())(
"Reset");
493 int client_size = client[0][0].p_client_size;
494 for (
unsigned int p = 0; p < NUM_PROTOCOLS; p++) {
495 for (
int c = 0; c < protocol_physical_client_count(p); c++) {
496 client[p][c].reset();
497 client[p][c].regs[ID] = (logical_of_physical[c] << 16) + p;
506 ipcc(
const ipcc&) =
delete;