aboutsummaryrefslogtreecommitdiffstats
path: root/tests/asicworld/code_specman_switch_fabric.v
blob: 1ac7ee7017fad23f68ef3b6c0baf8da768ec59a3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
module switch_fabric(
  clk, reset, data_in0, data_in1, data_in2,
  data_in3, data_in4, data_in5, data_in_valid0,
  data_in_valid1, data_in_valid2, data_in_valid3,
  data_in_valid4, data_in_valid5, data_out0,
  data_out1, data_out2, data_out3, data_out4,
  data_out5, data_out_ack0, data_out_ack1,
  data_out_ack2, data_out_ack3, data_out_ack4,
  data_out_ack5
);

input           clk, reset;
input  [7:0]    data_in0, data_in1, data_in2, data_in3;
input  [7:0]    data_in4, data_in5;
input           data_in_valid0, data_in_valid1, data_in_valid2;
input  [7:0]    data_in_valid3, data_in_valid4, data_in_valid5;
output [7:0]    data_out0, data_out1, data_out2, data_out3;
output [7:0]    data_out4, data_out5;
output          data_out_ack0, data_out_ack1, data_out_ack2;
output [7:0]    data_out_ack3, data_out_ack4, data_out_ack5;

(* gentb_clock *)
wire clk;

switch port_0 ( .clk(clk), .reset(reset), .data_in(data_in0), 
  .data_in_valid(data_in_valid0), .data_out(data_out0), 
  .data_out_ack(data_out_ack0));

switch port_1 ( .clk(clk), .reset(reset), .data_in(data_in1), 
  .data_in_valid(data_in_valid1), .data_out(data_out1), 
  .data_out_ack(data_out_ack1));

switch port_2 ( .clk(clk), .reset(reset), .data_in(data_in2), 
  .data_in_valid(data_in_valid2), .data_out(data_out2), .
  data_out_ack(data_out_ack2));

switch port_3 ( .clk(clk), .reset(reset), .data_in(data_in3), 
  .data_in_valid(data_in_valid3), .data_out(data_out3), 
  .data_out_ack(data_out_ack3));

switch port_4 ( .clk(clk), .reset(reset), .data_in(data_in4), 
  .data_in_valid(data_in_valid4), .data_out(data_out4), 
  .data_out_ack(data_out_ack4));

switch port_5 ( .clk(clk), .reset(reset), .data_in(data_in5), 
  .data_in_valid(data_in_valid5), .data_out(data_out5), 
  .data_out_ack(data_out_ack5));

endmodule

module switch (
  clk,
  reset,
  data_in,
  data_in_valid,
  data_out,
  data_out_ack
);

input   clk;
input   reset;
input [7:0]  data_in;
input   data_in_valid;
output [7:0]  data_out;
output  data_out_ack;

reg [7:0]  data_out;
reg   data_out_ack;

always @ (posedge clk)
if (reset) begin
   data_out <= 0;
   data_out_ack <= 0;
end else if (data_in_valid) begin
   data_out <= data_in;
   data_out_ack <= 1;
end else begin
   data_out <= 0;
   data_out_ack <= 0;
end

endmodule
s="p">{ for (;;) { if (sizeof (ulong) == sizeof (u64)) { ret = papr_put_term_char(NULL, chan, m + 1, ch.oct[0], ch.oct[1]); } else { ret = papr_put_term_char(NULL, chan, m + 1, ch.quad[0], ch.quad[1], ch.quad[2], ch.quad[3]); } if (ret != H_Busy) { break; } /* yielding here would be nice */ } if (ret != H_Success) { return -1; } } } *actual = count; if (*actual == -1) { return OF_FAILURE; } return OF_SUCCESS; } #define __HYPERVISOR_console_io 18 #define CONSOLEIO_write 0 #define CONSOLEIO_read 1 #define XEN_MARK(a) ((a) | (~0UL << 16)) extern long xen_hvcall(ulong code, ...); #define XENCOMM_MINI_AREA (sizeof(struct xencomm_mini) * 2) static s32 ofh_xen_dom0_read(s32 chan, void *buf, u32 count, s32 *actual, ulong b) { char __storage[XENCOMM_MINI_AREA]; struct xencomm_desc *desc; s32 rc; char *s = buf; s32 ret = 0; while (count > 0) { if (xencomm_create_mini(__storage, XENCOMM_MINI_AREA, s, count, &desc)) return ret; rc = xen_hvcall(XEN_MARK(__HYPERVISOR_console_io), CONSOLEIO_read, count, desc); if (rc <= 0) { return ret; } count -= rc; s += rc; ret += rc; } *actual = ret; return OF_SUCCESS; } static s32 ofh_xen_dom0_write(s32 chan, const void *buf, u32 count, s32 *actual, ulong b) { char __storage[XENCOMM_MINI_AREA]; struct xencomm_desc *desc; s32 rc; char *s = (char *)buf; s32 ret = 0; while (count > 0) { if (xencomm_create_mini(__storage, XENCOMM_MINI_AREA, s, count, &desc)) return ret; rc = xen_hvcall(XEN_MARK(__HYPERVISOR_console_io), CONSOLEIO_write, count, desc); if (rc <= 0) { return ret; } count -= rc; s += rc; ret += rc; } *actual = ret; if (*actual == -1) { return OF_FAILURE; } return OF_SUCCESS; } static s32 ofh_xen_domu_read(s32 chan, void *buf, u32 count, s32 *actual, ulong b) { struct xencons_interface *intf; XENCONS_RING_IDX cons, prod; s32 ret; intf = DRELA(ofh_ihp, b)->ofi_intf; cons = intf->in_cons; prod = intf->in_prod; mb(); ret = prod - cons; if (ret > 0) { ret = (ret < count) ? ret : count; memcpy(buf, intf->in+MASK_XENCONS_IDX(cons,intf->in), ret); } *actual = (ret < 0) ? 0 : ret; return OF_SUCCESS; } static s32 ofh_xen_domu_write(s32 chan, const void *buf, u32 count, s32 *actual, ulong b) { struct xencons_interface *intf; XENCONS_RING_IDX cons, prod; s32 ret; intf = DRELA(ofh_ihp, b)->ofi_intf; cons = intf->in_cons; prod = intf->in_prod; mb(); ret = prod - cons; /* FIXME: Do we have to write the whole thing or are partial writes ok? */ if (ret > 0) { ret = (ret < count) ? ret : count; memcpy(intf->in+MASK_XENCONS_IDX(cons,intf->in), buf, ret); } *actual = (ret < 0) ? 0 : ret; return OF_SUCCESS; } /* for emergency printing in the OFH */ s32 ofh_cons_write(const void *buf, u32 count, s32 *actual) { ulong b = get_base(); struct ofh_ihandle *ihp = DRELA(ofh_ihp, b); return ihp->ofi_write(ihp->ofi_chan, buf, count, actual, b); } s32 ofh_cons_close(void) { return OF_SUCCESS; } void ofh_cons_init(struct ofh_ihandle *ihp, ulong b) { if (ihp->ofi_chan == OFH_CONS_XEN) { if (ihp->ofi_intf == NULL) { ihp->ofi_write = ofh_xen_dom0_write; ihp->ofi_read = ofh_xen_dom0_read; } else { ihp->ofi_write = ofh_xen_domu_write; ihp->ofi_read = ofh_xen_domu_read; } } else { ihp->ofi_write = ofh_papr_write; ihp->ofi_read = ofh_papr_read; } *DRELA(&ofh_ihp, b) = ihp; }