Support multi-partition/-card mounting.

This commit is contained in:
Wayne Lin 2021-11-29 14:48:56 +08:00 committed by Bernard Xiong
parent c84952d9cd
commit 7e6ffd3447
4 changed files with 22 additions and 12 deletions

View File

@ -161,7 +161,7 @@ struct rt_mmcsd_card {
struct rt_sdio_cccr cccr; /* common card info */ struct rt_sdio_cccr cccr; /* common card info */
struct rt_sdio_cis cis; /* common tuple info */ struct rt_sdio_cis cis; /* common tuple info */
struct rt_sdio_function *sdio_function[SDIO_MAX_FUNCTIONS + 1]; /* SDIO functions (devices) */ struct rt_sdio_function *sdio_function[SDIO_MAX_FUNCTIONS + 1]; /* SDIO functions (devices) */
rt_list_t blk_devices; /* for block device list */
}; };
#ifdef __cplusplus #ifdef __cplusplus

View File

@ -96,6 +96,8 @@ struct rt_mmcsd_host {
rt_uint32_t max_blk_size; /* maximum block size */ rt_uint32_t max_blk_size; /* maximum block size */
rt_uint32_t max_blk_count; /* maximum block count */ rt_uint32_t max_blk_count; /* maximum block count */
rt_uint32_t id; /* Assigned host id */
rt_uint32_t spi_use_crc; rt_uint32_t spi_use_crc;
struct rt_mutex bus_lock; struct rt_mutex bus_lock;
struct rt_semaphore sem_ack; struct rt_semaphore sem_ack;

View File

@ -21,7 +21,6 @@
#endif /* RT_SDIO_DEBUG */ #endif /* RT_SDIO_DEBUG */
#include <rtdbg.h> #include <rtdbg.h>
static rt_list_t blk_devices = RT_LIST_OBJECT_INIT(blk_devices);
#define BLK_MIN(a, b) ((a) < (b) ? (a) : (b)) #define BLK_MIN(a, b) ((a) < (b) ? (a) : (b))
@ -357,8 +356,8 @@ rt_int32_t rt_mmcsd_blk_probe(struct rt_mmcsd_card *card)
rt_int32_t err = 0; rt_int32_t err = 0;
rt_uint8_t i, status; rt_uint8_t i, status;
rt_uint8_t *sector; rt_uint8_t *sector;
char dname[4]; char dname[8];
char sname[8]; char sname[12];
struct mmcsd_blk_device *blk_dev = RT_NULL; struct mmcsd_blk_device *blk_dev = RT_NULL;
err = mmcsd_set_blksize(card); err = mmcsd_set_blksize(card);
@ -381,6 +380,10 @@ rt_int32_t rt_mmcsd_blk_probe(struct rt_mmcsd_card *card)
status = rt_mmcsd_req_blk(card, 0, sector, 1, 0); status = rt_mmcsd_req_blk(card, 0, sector, 1, 0);
if (status == RT_EOK) if (status == RT_EOK)
{ {
rt_int32_t host_id = card->host->id;
/* Initial blk_device link-list. */
rt_list_init(&card->blk_devices);
for (i = 0; i < RT_MMCSD_MAX_PARTITION; i++) for (i = 0; i < RT_MMCSD_MAX_PARTITION; i++)
{ {
blk_dev = rt_calloc(1, sizeof(struct mmcsd_blk_device)); blk_dev = rt_calloc(1, sizeof(struct mmcsd_blk_device));
@ -390,6 +393,10 @@ rt_int32_t rt_mmcsd_blk_probe(struct rt_mmcsd_card *card)
break; break;
} }
/* Given block device name is with allocated host id and its partition index. */
rt_snprintf(dname, sizeof(dname), "sd%c%d", (host_id+'a'), i);
rt_snprintf(sname, sizeof(sname), "sem_sd%c%d", (host_id+'a'), i);
blk_dev->max_req_size = BLK_MIN((card->host->max_dma_segs * blk_dev->max_req_size = BLK_MIN((card->host->max_dma_segs *
card->host->max_seg_size) >> 9, card->host->max_seg_size) >> 9,
(card->host->max_blk_count * (card->host->max_blk_count *
@ -399,8 +406,6 @@ rt_int32_t rt_mmcsd_blk_probe(struct rt_mmcsd_card *card)
status = dfs_filesystem_get_partition(&blk_dev->part, sector, i); status = dfs_filesystem_get_partition(&blk_dev->part, sector, i);
if (status == RT_EOK) if (status == RT_EOK)
{ {
rt_snprintf(dname, 4, "sd%d", i);
rt_snprintf(sname, 8, "sem_sd%d", i);
blk_dev->part.lock = rt_sem_create(sname, 1, RT_IPC_FLAG_FIFO); blk_dev->part.lock = rt_sem_create(sname, 1, RT_IPC_FLAG_FIFO);
/* register mmcsd device */ /* register mmcsd device */
@ -425,7 +430,7 @@ rt_int32_t rt_mmcsd_blk_probe(struct rt_mmcsd_card *card)
rt_device_register(&blk_dev->dev, dname, rt_device_register(&blk_dev->dev, dname,
RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_REMOVABLE | RT_DEVICE_FLAG_STANDALONE); RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_REMOVABLE | RT_DEVICE_FLAG_STANDALONE);
rt_list_insert_after(&blk_devices, &blk_dev->list); rt_list_insert_after(&card->blk_devices, &blk_dev->list);
} }
else else
{ {
@ -434,7 +439,7 @@ rt_int32_t rt_mmcsd_blk_probe(struct rt_mmcsd_card *card)
/* there is no partition table */ /* there is no partition table */
blk_dev->part.offset = 0; blk_dev->part.offset = 0;
blk_dev->part.size = 0; blk_dev->part.size = 0;
blk_dev->part.lock = rt_sem_create("sem_sd0", 1, RT_IPC_FLAG_FIFO); blk_dev->part.lock = rt_sem_create(sname, 1, RT_IPC_FLAG_FIFO);
/* register mmcsd device */ /* register mmcsd device */
blk_dev->dev.type = RT_Device_Class_Block; blk_dev->dev.type = RT_Device_Class_Block;
@ -457,9 +462,9 @@ rt_int32_t rt_mmcsd_blk_probe(struct rt_mmcsd_card *card)
blk_dev->geometry.sector_count = blk_dev->geometry.sector_count =
card->card_capacity * (1024 / 512); card->card_capacity * (1024 / 512);
rt_device_register(&blk_dev->dev, "sd0", rt_device_register(&blk_dev->dev, dname,
RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_REMOVABLE | RT_DEVICE_FLAG_STANDALONE); RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_REMOVABLE | RT_DEVICE_FLAG_STANDALONE);
rt_list_insert_after(&blk_devices, &blk_dev->list); rt_list_insert_after(&card->blk_devices, &blk_dev->list);
} }
else else
{ {
@ -496,7 +501,7 @@ void rt_mmcsd_blk_remove(struct rt_mmcsd_card *card)
rt_list_t *l, *n; rt_list_t *l, *n;
struct mmcsd_blk_device *blk_dev; struct mmcsd_blk_device *blk_dev;
for (l = (&blk_devices)->next, n = l->next; l != &blk_devices; l = n, n = n->next) for (l = (&card->blk_devices)->next, n = l->next; l != &card->blk_devices; l = n, n=n->next)
{ {
blk_dev = (struct mmcsd_blk_device *)rt_list_entry(l, struct mmcsd_blk_device, list); blk_dev = (struct mmcsd_blk_device *)rt_list_entry(l, struct mmcsd_blk_device, list);
if (blk_dev->card == card) if (blk_dev->card == card)

View File

@ -40,6 +40,7 @@ static struct rt_mailbox mmcsd_detect_mb;
static rt_uint32_t mmcsd_detect_mb_pool[4]; static rt_uint32_t mmcsd_detect_mb_pool[4];
static struct rt_mailbox mmcsd_hotpluge_mb; static struct rt_mailbox mmcsd_hotpluge_mb;
static rt_uint32_t mmcsd_hotpluge_mb_pool[4]; static rt_uint32_t mmcsd_hotpluge_mb_pool[4];
static rt_uint32_t allocated_host_num = 0;
void mmcsd_host_lock(struct rt_mmcsd_host *host) void mmcsd_host_lock(struct rt_mmcsd_host *host)
{ {
@ -707,8 +708,10 @@ struct rt_mmcsd_host *mmcsd_alloc_host(void)
host->max_dma_segs = 1; host->max_dma_segs = 1;
host->max_blk_size = 512; host->max_blk_size = 512;
host->max_blk_count = 4096; host->max_blk_count = 4096;
host->id = allocated_host_num;
allocated_host_num++;
rt_mutex_init(&host->bus_lock, "sd_bus_lock", RT_IPC_FLAG_PRIO); rt_mutex_init(&host->bus_lock, "sd_bus_lock", RT_IPC_FLAG_FIFO);
rt_sem_init(&host->sem_ack, "sd_ack", 0, RT_IPC_FLAG_FIFO); rt_sem_init(&host->sem_ack, "sd_ack", 0, RT_IPC_FLAG_FIFO);
return host; return host;