@@ -20,6 +20,7 @@ blk_req_queue_t *blk_req_queue;
2020blk_resp_queue_t * blk_resp_queue ;
2121uintptr_t blk_data ;
2222
23+ #define KEEP_REPEATING_COMMANDS false
2324#define NUM_READ_BLOCKS 6
2425#define NUM_WRITE_BLOCKS 5
2526_Static_assert (NUM_READ_BLOCKS > NUM_WRITE_BLOCKS , "#read must be greater than #write" );
@@ -94,9 +95,50 @@ void ensure_data_is_correct()
9495 sddf_printf ("Client read/write data is correct!\n" );
9596}
9697
98+ void send_commands (void )
99+ {
100+ uint32_t data_address = 0 ;
101+
102+ /* Setup a data region with a region to read into from the card, initially zeroed
103+ then another region to write to the card with.
104+
105+ Note: Read region is before the write region, so that we can ensure
106+ that reading into it doesn't overwrite our original data we wrote from
107+ i.e. a driver bug
108+ */
109+ volatile uint8_t * block_data = (volatile uint8_t * )blk_data ;
110+ for (int i = 0 ; i < NUM_READ_BLOCKS * BLK_TRANSFER_SIZE ; i ++ ) {
111+ block_data [i ] = 0x0 ;
112+ }
113+ for (int i = 0 ; i < NUM_WRITE_BLOCKS * BLK_TRANSFER_SIZE ; i ++ ) {
114+ // we offset it so it's not 0 at start or end
115+ block_data [i + NUM_READ_BLOCKS * BLK_TRANSFER_SIZE ] = BYTE_ADJUST (i );
116+ }
117+
118+ /* Request to write data, then read it back */
119+
120+ // write some zeroed data first; just our zeroed read blocks as a test.
121+ int err = blk_enqueue_req (& blk_queue , BLK_REQ_WRITE , 0x0 , data_address , NUM_READ_BLOCKS , /* req ID */ 0 );
122+ assert (!err );
123+ err = blk_enqueue_req (& blk_queue , BLK_REQ_WRITE , 0x0 + NUM_READ_BLOCKS * BLK_TRANSFER_SIZE , data_address ,
124+ NUM_WRITE_BLOCKS , /* req ID */ 1 );
125+ assert (!err );
126+ err = blk_enqueue_req (& blk_queue , BLK_REQ_BARRIER , 0 , 0 , 0 , /* req ID */ 2 );
127+ assert (!err );
128+ err = blk_enqueue_req (& blk_queue , BLK_REQ_FLUSH , 0 , 0 , 0 , /* req ID */ 3 );
129+ assert (!err );
130+ // read some random stuff
131+ err = blk_enqueue_req (& blk_queue , BLK_REQ_READ , 0x0 , 0x0 , NUM_READ_BLOCKS , /* req ID */ 4 );
132+ assert (!err );
133+ // do a second read test to check this
134+ err = blk_enqueue_req (& blk_queue , BLK_REQ_READ , 0x0 , data_address , NUM_READ_BLOCKS , /* req ID */ 5 );
135+ assert (!err );
136+
137+ microkit_notify (BLK_VIRT_CHANNEL );
138+ }
139+
97140void notified (microkit_channel ch )
98141{
99- microkit_dbg_puts ("client notified!\n" );
100142 if (ch != BLK_VIRT_CHANNEL ) {
101143 assert (!"bad channel?" );
102144 }
@@ -119,8 +161,13 @@ void notified(microkit_channel ch)
119161
120162 }
121163
122- print_some_data ();
164+ if (!KEEP_REPEATING_COMMANDS ) {
165+ print_some_data ();
166+ }
123167 ensure_data_is_correct ();
168+ if (KEEP_REPEATING_COMMANDS ) {
169+ send_commands ();
170+ }
124171}
125172
126173void init (void )
@@ -136,42 +183,5 @@ void init(void)
136183 so we don't overwrite anything important.
137184 */
138185 assert (blk_partition_mapping [0 ] == 2 );
139- uint32_t data_address = 0 ;
140-
141- /* Setup a data region with a region to read into from the card, initially zeroed
142- then another region to write to the card with.
143-
144- Note: Read region is before the write region, so that we can ensure
145- that reading into it doesn't overwrite our original data we wrote from
146- i.e. a driver bug
147- */
148- volatile uint8_t * block_data = (volatile uint8_t * )blk_data ;
149- for (int i = 0 ; i < NUM_READ_BLOCKS * BLK_TRANSFER_SIZE ; i ++ ) {
150- block_data [i ] = 0x0 ;
151- }
152- for (int i = 0 ; i < NUM_WRITE_BLOCKS * BLK_TRANSFER_SIZE ; i ++ ) {
153- // we offset it so it's not 0 at start or end
154- block_data [i + NUM_READ_BLOCKS * BLK_TRANSFER_SIZE ] = BYTE_ADJUST (i );
155- }
156-
157- /* Request to write data, then read it back */
158-
159- // write some zeroed data first; just our zeroed read blocks as a test.
160- int err = blk_enqueue_req (& blk_queue , BLK_REQ_WRITE , 0x0 , data_address , NUM_READ_BLOCKS , /* req ID */ 0 );
161- assert (!err );
162- err = blk_enqueue_req (& blk_queue , BLK_REQ_WRITE , 0x0 + NUM_READ_BLOCKS * BLK_TRANSFER_SIZE , data_address ,
163- NUM_WRITE_BLOCKS , /* req ID */ 1 );
164- assert (!err );
165- err = blk_enqueue_req (& blk_queue , BLK_REQ_BARRIER , 0 , 0 , 0 , /* req ID */ 2 );
166- assert (!err );
167- err = blk_enqueue_req (& blk_queue , BLK_REQ_FLUSH , 0 , 0 , 0 , /* req ID */ 3 );
168- assert (!err );
169- // read some random stuff
170- err = blk_enqueue_req (& blk_queue , BLK_REQ_READ , 0x0 , 0x0 , NUM_READ_BLOCKS , /* req ID */ 4 );
171- assert (!err );
172- // do a second read test to check this
173- err = blk_enqueue_req (& blk_queue , BLK_REQ_READ , 0x0 , data_address , NUM_READ_BLOCKS , /* req ID */ 5 );
174- assert (!err );
175-
176- microkit_notify (BLK_VIRT_CHANNEL );
186+ send_commands ();
177187}
0 commit comments