Skip to content

Commit 9c5ee7e

Browse files
DC-SWATQuzarDC
authored andcommitted
sd: Added creation of a block device for the entire SD card.
Also use DMA for writing if possible.
1 parent acaf32f commit 9c5ee7e

4 files changed

Lines changed: 47 additions & 1 deletion

File tree

kernel/arch/dreamcast/exports-naomi.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ sd_read_blocks
8585
sd_write_blocks
8686
sd_get_size
8787
sd_blockdev_for_partition
88+
sd_blockdev_for_device
8889

8990
# Timers
9091
timer_prime

kernel/arch/dreamcast/exports-pristine.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ sd_read_blocks
103103
sd_write_blocks
104104
sd_get_size
105105
sd_blockdev_for_partition
106+
sd_blockdev_for_device
106107

107108
# Timers
108109
timer_prime

kernel/arch/dreamcast/hardware/sd.c

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,10 @@ static void sci_read_data_wrapper(uint8_t *data, size_t len) {
141141
}
142142

143143
static void sci_write_data_wrapper(const uint8_t *data, size_t len) {
144-
sci_spi_write_data(data, len);
144+
if(len & 31)
145+
sci_spi_write_data(data, len);
146+
else
147+
sci_spi_dma_write_data(data, len, NULL, NULL);
145148
}
146149

147150
static void scif_shutdown_wrapper(void) {
@@ -810,3 +813,28 @@ int sd_blockdev_for_partition(int partition, kos_blockdev_t *rv,
810813
return 0;
811814
}
812815

816+
int sd_blockdev_for_device(kos_blockdev_t *rv) {
817+
sd_devdata_t *ddata;
818+
819+
if (!initted) {
820+
errno = ENXIO;
821+
return -1;
822+
}
823+
824+
if (!rv) {
825+
errno = EFAULT;
826+
return -1;
827+
}
828+
829+
/* Allocate the device data */
830+
if (!(ddata = (sd_devdata_t *)malloc(sizeof(sd_devdata_t)))) {
831+
errno = ENOMEM;
832+
return -1;
833+
}
834+
835+
ddata->start_block = 0;
836+
ddata->block_count = (sd_get_size() / 512);
837+
rv->dev_data = ddata;
838+
839+
return 0;
840+
}

kernel/arch/dreamcast/include/dc/sd.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,22 @@ uint64 sd_get_size(void);
202202
int sd_blockdev_for_partition(int partition, kos_blockdev_t *rv,
203203
uint8 *partition_type);
204204

205+
/** \brief Get a block device for the SD card.
206+
207+
This function creates a block device descriptor for the attached SD card.
208+
This block device is used to interface with various filesystems on the device.
209+
210+
\param rv Used to return the block device. Must be non-NULL.
211+
\retval 0 On success.
212+
\retval -1 On error, errno will be set as appropriate.
213+
214+
\par Error Conditions:
215+
\em ENXIO - SD card support was not initialized
216+
\em EFAULT - rv was NULL
217+
\em ENOMEM - out of memory
218+
*/
219+
int sd_blockdev_for_device(kos_blockdev_t *rv);
220+
205221
/** @} */
206222

207223
__END_DECLS

0 commit comments

Comments
 (0)