Skip to content

Commit 7b76444

Browse files
committed
Created mmc_driver_client file and moved sDDF data structures into it.
1 parent f2f465e commit 7b76444

16 files changed

+232
-73
lines changed

Diff for: mmc/CMakeLists.txt

+18-3
Original file line numberDiff line numberDiff line change
@@ -489,9 +489,7 @@ target_include_directories(mmc_rpi3b_lib_diskio PUBLIC src/lib_fatfs/)
489489
target_link_libraries(
490490
mmc_rpi3b_lib_diskio
491491
mmc_rpi3b_lib_ff
492-
mmc_rpi3b_lib_blk_request_queue
493-
mmc_rpi3b_lib_blk_response_queue
494-
mmc_rpi3b_lib_blk_shared_data_queue
492+
mmc_rpi3b_lib_mmc_driver_client
495493
)
496494

497495
add_library(mmc_rpi3b_lib_diskio_test src/lib_fatfs/diskio_test.c)
@@ -552,4 +550,21 @@ target_link_libraries(
552550
mmc_rpi3b_lib_blk_shared_data_buf
553551
mmc_rpi3b_lib_fatfs_e2e
554552
mmc_rpi3b_lib_diskio
553+
mmc_rpi3b_lib_mmc_driver_client
554+
)
555+
556+
add_library(mmc_rpi3b_lib_mmc_driver_client src/mmc_driver_client/mmc_driver_client.c)
557+
target_include_directories(mmc_rpi3b_lib_mmc_driver_client PUBLIC include/)
558+
target_link_libraries(
559+
mmc_rpi3b_lib_mmc_driver_client
560+
mmc_rpi3b_lib_sel4cp_facade
561+
mmc_rpi3b_lib_blk_request_queue
562+
mmc_rpi3b_lib_blk_response_queue
563+
mmc_rpi3b_lib_blk_shared_data_queue
564+
mmc_rpi3b_lib_blk_request
565+
mmc_rpi3b_lib_blk_response
566+
mmc_rpi3b_lib_blk_shared_data_buf
567+
mmc_rpi3b_lib_result
555568
)
569+
570+

Diff for: mmc/Makefile

+2
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ FATFS_OBJS := \
159159
lib_fatfs/diskio_test.o \
160160
lib_fatfs/ffunicode.o \
161161
fatfs_e2e.o \
162+
mmc_driver_client/mmc_driver_client.o \
162163

163164
IMAGES := \
164165
serial_driver.elf \
@@ -183,6 +184,7 @@ directories:
183184
mkdir -p $(BUILD_DIR)/lib_sddf_blk
184185
mkdir -p $(BUILD_DIR)/common
185186
mkdir -p $(BUILD_DIR)/mmc_driver
187+
mkdir -p $(BUILD_DIR)/mmc_driver_client
186188
mkdir -p $(BUILD_DIR)/mmc_driver/sdhci
187189
mkdir -p $(BUILD_DIR)/mmc_driver/bcm_emmc_regs
188190
mkdir -p $(BUILD_DIR)/mmc_driver/bcm_emmc_regs/cmdtm

Diff for: mmc/include/fatfs.h

+3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@
99
#include "blk_shared_data_queue.h"
1010
#include "fatfs_e2e.h"
1111
#include "diskio.h"
12+
#include "mmc_driver_client.h"
1213

1314
#define FATFS_TO_SERIAL_CLIENT_PUTCHAR_CHANNEL (13)
15+
#define FATFS_TO_MMC_DRIVER_REQUEST_CHANNEL (15)
16+
1417
#define FAT_CLUSTER_SIZE (0x10000)
1518

Diff for: mmc/include/mmc_driver.h

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
#define MMC_DRIVER_TO_SERIAL_CLIENT_PUTCHAR_CHANNEL (7)
1717
#define MMC_DRIVER_TO_TIMER_DRIVER_GET_NUM_TICKS_CHANNEL (11)
18+
#define MMC_DRIVER_TO_FATFS_REQUEST_CHANNEL (16)
1819

1920
/**
2021
* Returns the number of blocks on the SD card.

Diff for: mmc/include/mmc_driver_client.h

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#pragma once
2+
3+
#include <stddef.h>
4+
5+
#include "sel4cp_facade.h"
6+
#include "blk_request_queue.h"
7+
#include "blk_response_queue.h"
8+
#include "blk_shared_data_queue.h"
9+
#include "blk_request.h"
10+
#include "blk_response.h"
11+
#include "blk_shared_data_buf.h"
12+
#include "result.h"
13+
14+
typedef struct mmc_driver_client mmc_driver_client_t;
15+
struct mmc_driver_client {
16+
/* sel4cp channel ID to send Request notifications to `mmc_driver`. */
17+
size_t sel4cp_channel_id_request;
18+
blk_request_queue_t *request_queue;
19+
blk_response_queue_t *response_queue;
20+
blk_shared_data_queue_t shared_data_queue;
21+
};
22+
23+
/**
24+
* Initialise our `mmc_driver_client`.
25+
* @param mmc_driver_client
26+
* @param sel4cp_channel_id_request
27+
* @param request_queue
28+
* @param response_queue
29+
* @param shared_data_queue
30+
* @return
31+
*/
32+
result_t mmc_driver_client_init(
33+
mmc_driver_client_t *mmc_driver_client,
34+
size_t sel4cp_channel_id_request,
35+
blk_request_queue_t *request_queue,
36+
blk_response_queue_t *response_queue,
37+
blk_shared_data_queue_t *shared_data_queue
38+
);
39+
40+
/**
41+
* Services the `GET_SECTOR_COUNT` FatFs request.
42+
* @param mmc_driver_client
43+
* @param ret_val
44+
* @return
45+
*/
46+
result_t mmc_driver_client_get_num_blocks(
47+
mmc_driver_client_t *mmc_driver_client,
48+
uint64_t *ret_val
49+
);
50+

Diff for: mmc/mmc.system

+6-2
Original file line numberDiff line numberDiff line change
@@ -418,8 +418,12 @@
418418
setvar_vaddr="mmc_driver_shared_data" />
419419
</protection_domain>
420420
<channel>
421-
<end pd="fatfs" id="13" />
422-
<end pd="serial_client" id="14" />
421+
<end pd="fatfs" id="13"/>
422+
<end pd="serial_client" id="14"/>
423+
</channel>
424+
<channel>
425+
<end pd="fatfs" id="15"/>
426+
<end pd="mmc_driver" id="16"/>
423427
</channel>
424428
</system>
425429

Diff for: mmc/src/fatfs.c

+25-15
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ uintptr_t mmc_driver_response_queue;
1212
/* Shared memory region for passing data between `mmc_driver` and `fatfs`. */
1313
uintptr_t mmc_driver_shared_data;
1414

15-
/* The global shared data queue that manages the buffers within the
16-
* `mmc_driver_shared_data` shared memory region. */
17-
blk_shared_data_queue_t global_shared_data_queue = {0};
15+
/* The global MMC driver client that uses the sDDF data structures (above) to
16+
* interact with the `mmc_driver`. */
17+
mmc_driver_client_t global_mmc_driver_client = {0};
1818

1919
void init(void) {
2020
/* Initialise `printf`. The `log.h` library depends on `printf` being
@@ -49,8 +49,9 @@ void init(void) {
4949
return;
5050
}
5151

52+
blk_shared_data_queue_t shared_data_queue = {0};
5253
blk_shared_data_queue_result_t shared_data_queue_init_result = blk_shared_data_queue_init(
53-
&global_shared_data_queue,
54+
&shared_data_queue,
5455
mmc_driver_shared_data,
5556
SEL4CP_MAX_PAGE_SIZE,
5657
FAT_CLUSTER_SIZE /* TODO: Figure out how to obtain this info dynamically. */
@@ -60,22 +61,31 @@ void init(void) {
6061
return;
6162
}
6263

63-
/* Initialises FatFs by passing it the data structures it requires access to
64-
* for low-level disk I/O functions. */
65-
disk_init(
64+
/* Initialise the `mmc_driver_client` library that FatFs relies on. */
65+
result_t res;
66+
res = mmc_driver_client_init(
67+
&global_mmc_driver_client,
68+
FATFS_TO_MMC_DRIVER_REQUEST_CHANNEL,
6669
request_queue,
6770
response_queue,
68-
&global_shared_data_queue
71+
&shared_data_queue
6972
);
73+
if (result_is_err(res)) {
74+
result_printf(res);
75+
return;
76+
}
77+
78+
/* Initialises FatFs by passing it the `mmc_driver_client`, which uses sDDF
79+
* data structures to interact with the `mmc_driver`. */
80+
disk_init(&global_mmc_driver_client);
7081

7182
/* TODO: E2E test the state of the above data structures. */
72-
// result_t res;
73-
// res = fatfs_e2e_diskio_test();
74-
// if (result_is_err(res)) {
75-
// result_printf(res);
76-
// return;
77-
// }
78-
//
83+
res = fatfs_e2e_diskio_test();
84+
if (result_is_err(res)) {
85+
result_printf(res);
86+
return;
87+
}
88+
7989
// res = fatfs_e2e_write_close_read_simple();
8090
// if (result_is_err(res)) {
8191
// result_printf(res);

Diff for: mmc/src/lib_fatfs/diskio.c

+13-10
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,12 @@
1515
#define DEV_RAM 1 /* Example: Map Ramdisk to physical drive 1 */
1616
#define DEV_USB 2 /* Example: Map USB MSD to physical drive 2 */
1717

18-
blk_request_queue_t *disk_request_queue = NULL;
19-
blk_response_queue_t *disk_response_queue = NULL;
20-
blk_shared_data_queue_t *disk_shared_data_queue = NULL;
18+
mmc_driver_client_t *fatfs_mmc_driver_client = NULL;
2119

2220
void disk_init(
23-
blk_request_queue_t *request_queue,
24-
blk_response_queue_t *response_queue,
25-
blk_shared_data_queue_t *shared_data_queue
21+
mmc_driver_client_t *mmc_driver_client
2622
) {
27-
disk_request_queue = request_queue;
28-
disk_response_queue = response_queue;
29-
disk_shared_data_queue = shared_data_queue;
23+
fatfs_mmc_driver_client = mmc_driver_client;
3024
}
3125

3226
/*-----------------------------------------------------------------------*/
@@ -243,7 +237,16 @@ DRESULT disk_ioctl(
243237
case DEV_MMC :
244238
switch (cmd) {
245239
case GET_SECTOR_COUNT: {
246-
// uint64_t *num_blocks = (uint64_t *) buff;
240+
uint64_t *num_blocks = (uint64_t *) buff;
241+
if (result_is_err(
242+
mmc_driver_client_get_num_blocks(
243+
fatfs_mmc_driver_client,
244+
num_blocks
245+
)
246+
)) {
247+
res = RES_ERROR;
248+
break;
249+
}
247250
// result_t res_mmc = mmc_driver_get_num_blocks(num_blocks);
248251
// if (result_is_err(res_mmc)) {
249252
// res = RES_ERROR;

Diff for: mmc/src/lib_fatfs/diskio.h

+5-12
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,12 @@
55
#ifndef _DISKIO_DEFINED
66
#define _DISKIO_DEFINED
77

8-
#include "blk_request_queue.h"
9-
#include "blk_response_queue.h"
10-
#include "blk_shared_data_queue.h"
11-
#include "blk_request.h"
12-
#include "blk_response.h"
13-
#include "blk_shared_data_buf.h"
14-
15-
/* Initialises FatFs by passing it the data structures it requires access to for
16-
* low-level disk I/O functions. */
8+
#include "mmc_driver_client.h"
9+
10+
/* Initialises FatFs by passing it the `mmc_driver_client`, which uses sDDF data
11+
* structures to interact with the `mmc_driver`. */
1712
void disk_init(
18-
blk_request_queue_t *request_queue,
19-
blk_response_queue_t *response_queue,
20-
blk_shared_data_queue_t *shared_data_queue
13+
mmc_driver_client_t *mmc_driver_client
2114
);
2215

2316
#ifdef __cplusplus

Diff for: mmc/src/lib_sddf_blk/blk_request.c

+2-13
Original file line numberDiff line numberDiff line change
@@ -30,25 +30,14 @@ static inline blk_request_result_t blk_request_init_no_args(
3030
return OK_BLK_REQUEST;
3131
}
3232

33-
blk_request_result_t blk_request_init_get_sector_count(
33+
blk_request_result_t blk_request_init_get_num_blocks(
3434
blk_request_t *request,
3535
blk_shared_data_buf_t *shared_data_buf
3636
) {
3737
return blk_request_init_no_args(
3838
request,
3939
shared_data_buf,
40-
GET_SECTOR_COUNT
41-
);
42-
}
43-
44-
blk_request_result_t blk_request_init_get_sector_size(
45-
blk_request_t *request,
46-
blk_shared_data_buf_t *shared_data_buf
47-
) {
48-
return blk_request_init_no_args(
49-
request,
50-
shared_data_buf,
51-
GET_SECTOR_SIZE
40+
GET_NUM_BLOCKS
5241
);
5342
}
5443

Diff for: mmc/src/lib_sddf_blk/blk_request.h

+3-15
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@
99
#include "blk_shared_data_buf.h"
1010

1111
enum blk_request_operation {
12-
GET_SECTOR_COUNT,
13-
GET_SECTOR_SIZE,
12+
GET_NUM_BLOCKS,
1413
GET_BLOCK_SIZE,
1514
CTRL_SYNC,
1615
READ,
@@ -38,23 +37,12 @@ enum blk_request_result {
3837
typedef enum blk_request_result blk_request_result_t;
3938

4039
/**
41-
* Initialises a `GET_SECTOR_COUNT` request.
40+
* Initialises a `GET_NUM_BLOCKS` request.
4241
* @param request
4342
* @param shared_data_buf
4443
* @return
4544
*/
46-
blk_request_result_t blk_request_init_get_sector_count(
47-
blk_request_t *request,
48-
blk_shared_data_buf_t *shared_data_buf
49-
);
50-
51-
/**
52-
* Initialises a `GET_SECTOR_SIZE` request.
53-
* @param request
54-
* @param shared_data_buf
55-
* @return
56-
*/
57-
blk_request_result_t blk_request_init_get_sector_size(
45+
blk_request_result_t blk_request_init_get_num_blocks(
5846
blk_request_t *request,
5947
blk_shared_data_buf_t *shared_data_buf
6048
);

Diff for: mmc/src/lib_sddf_blk/blk_shared_data_queue.c

+12-1
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ blk_shared_data_queue_result_t blk_shared_data_queue_enqueue(
142142
return ERR_BLK_SHARED_DATA_QUEUE_FULL;
143143
}
144144
/* Copy everything from `val` into `queue->data_bufs[queue->tail_idx]`. */
145+
/* TODO: Encapsulate into a function call. */
145146
memcpy(&queue->data_bufs[queue->tail_idx], val, sizeof(*val));
146147
/* We place a memory barrier here to ensure that the instructions that
147148
* update the tail index are guaranteed to occur after the buffer has been
@@ -173,6 +174,7 @@ blk_shared_data_queue_result_t blk_shared_data_queue_dequeue(
173174
return ERR_BLK_SHARED_DATA_QUEUE_EMPTY;
174175
}
175176
/* Copy everything from `queue->data_bufs[queue->head_idx]` into `ret_val`. */
177+
/* TODO: Encapsulate into a function call. */
176178
memcpy(ret_val, &queue->data_bufs[queue->head_idx], sizeof(*ret_val));
177179
/* We place a memory barrier here to ensure that the instructions that
178180
* update the head index are guaranteed to occur after the buffer has been
@@ -183,5 +185,14 @@ blk_shared_data_queue_result_t blk_shared_data_queue_dequeue(
183185
return OK_BLK_SHARED_DATA_QUEUE;
184186
}
185187

186-
188+
blk_shared_data_queue_result_t blk_shared_data_queue_copy(
189+
blk_shared_data_queue_t *dst_queue,
190+
blk_shared_data_queue_t *src_queue
191+
) {
192+
if (dst_queue == NULL || src_queue == NULL) {
193+
return ERR_NULL_BLK_SHARED_DATA_QUEUE;
194+
}
195+
memcpy(dst_queue, src_queue, sizeof(*dst_queue));
196+
return OK_BLK_SHARED_DATA_QUEUE;
197+
}
187198

Diff for: mmc/src/lib_sddf_blk/blk_shared_data_queue.h

+9
Original file line numberDiff line numberDiff line change
@@ -129,3 +129,12 @@ blk_shared_data_queue_result_t blk_shared_data_queue_dequeue(
129129
blk_shared_data_buf_t *ret_val
130130
);
131131

132+
/**
133+
* Copies the contents of `src_queue` into `dst_queue`.
134+
* @param dst_queue
135+
* @param src_queue
136+
*/
137+
blk_shared_data_queue_result_t blk_shared_data_queue_copy(
138+
blk_shared_data_queue_t *dst_queue,
139+
blk_shared_data_queue_t *src_queue
140+
);

Diff for: mmc/src/mmc_driver.c

+9-1
Original file line numberDiff line numberDiff line change
@@ -208,5 +208,13 @@ result_t mmc_driver_read_blocks(
208208
}
209209

210210
void notified(sel4cp_channel ch) {
211-
211+
switch(ch) {
212+
case MMC_DRIVER_TO_FATFS_REQUEST_CHANNEL: {
213+
printf("Received something on MMC_DRIVER_TO_FATFS_REQUEST_CHANNEL\n");
214+
break;
215+
}
216+
default:
217+
printf("MMC Driver: received notification on unexpected channel\n");
218+
break;
219+
}
212220
}

0 commit comments

Comments
 (0)