From: Adrian M. <ad...@mc...> - 2002-08-21 22:22:42
|
This is getting quite close to working, I hope. --- vmu-old.c Fri Aug 16 00:05:22 2002 +++ vmu-flash.c Wed Aug 21 23:16:18 2002 @@ -2,6 +2,10 @@ * drivers/mtd/maps/vmu-flash.c * * (C)opyright 2001 Paul Mundt <le...@ch...> + + + + + + Messed about with and fragments copyright 2002, Adrian McMenamin <ad...@mc...> + + * * Flash mapping handler for the Sega Dreamcast VMU. * @@ -26,12 +30,111 @@ /* MTD Information */ static struct mtd_info *vmu_flash_mtd = NULL; +/* Persistent result */ +static struct mapleq *lastmq; +static struct maple_driver dc_flashmap_driver; +char *block_buffer = NULL; + +int waken_up = 1; + /* VMU Block */ typedef struct block_s { unsigned int num; /* Block Number */ unsigned int ofs; /* Block Offset */ } block_t; +/*************************************/ +/**********Read and write routines*************/ +int maple_vmu_read_block(unsigned int num, u_char * buf) +{ + + /* async maple call + assemble maple call + wait for return */ + + + /* Sanity check */ + if (!vmu_flash_mtd) { + printk(KERN_WARNING + "VMU FLASH: Attempting to read data without having set up mtd.\n"); + return -1; + } + + struct maple_driver_data *mdd = + (struct maple_driver_data *) (vmu_flash_mtd->priv); + struct mapleq *mqu = (struct mapleq *) &(mdd->mq); + mqu->command = 11; + mqu->length = 2; + + ((unsigned long *) (mqu->recvbuf))[0] = + cpu_to_be32(MAPLE_FUNC_MEMCARD); + + ((unsigned long *) (mqu->recvbuf))[1] = num; + mqu->sendbuf = mqu->recvbuf; + if (maple_add_packet(mqu) != 0) { + printk(KERN_WARNING "VMU FLASH: Could not add packet\n"); + return -1; + } + + lastmq = NULL; + wait_queue_head_t wq_mq; + init_waitqueue_head(&wq_mq); + do { + interruptible_sleep_on_timeout(&wq_mq, 1); + } while (lastmq == NULL); + + /* Now check if we've got a proper return */ + + if (block_buffer){; + memcpy(block_buffer, buf, 512); + kfree(block_buffer); + block_buffer = NULL; + return 0; + } + + printk(KERN_WARNING "VMU FLASH: Read has failed\n"); + + return -1; + +} + +int maple_vmu_write_block(unsigned int num, u_char * buf) +{ + + /* This function does not have to sleep */ + + /* Sanity check */ + if (!vmu_flash_mtd) { + printk(KERN_WARNING + "VMU FLASH: Attempting to write data without having set up mtd.\n"); + return -1; + } + + struct maple_driver_data *mdd = + (struct maple_driver_data *) (vmu_flash_mtd->priv); + struct mapleq *mqu = (struct mapleq *) &(mdd->mq); + mqu->command = 12; + mqu->length = 514; + + ((unsigned long *) (mqu->recvbuf))[0] = + cpu_to_be32(MAPLE_FUNC_MEMCARD); + + ((unsigned long *) (mqu->recvbuf))[1] = num; + memcpy((mqu->recvbuf) + 8, buf, 512); + + mqu->sendbuf = mqu->recvbuf; + if (maple_add_packet(mqu) != 0) { + printk(KERN_WARNING "VMU FLASH: Could not add packet\n"); + return -1; + } + + return 0; + +} + +/*************************************/ + + /** * __ofs_to_block - Offset to Block Conversion * @@ -56,27 +159,29 @@ /* Zero the block */ memset(block, 0, sizeof(struct block_s)); - + /* Make sure we don't overstep our boundaries */ if (src_ofs >= VMU_NUM_BLOCKS * VMU_BLOCK_SIZE) { - printk(KERN_WARNING "Source offset exceeds total offset\n"); + printk(KERN_WARNING + "Source offset exceeds total offset\n"); kfree(block); return NULL; } /* Find the block number */ - block->num = (unsigned int)(src_ofs / VMU_BLOCK_SIZE); + block->num = (unsigned int) (src_ofs / VMU_BLOCK_SIZE); /* Validate we've got a valid block */ if (block->num > VMU_NUM_BLOCKS) { - printk(KERN_WARNING "Block number exceeds number of blocks\n"); + printk(KERN_WARNING + "Block number exceeds number of blocks\n"); kfree(block); return NULL; } - + /* Calculate remaining offset in block */ - block->ofs = (unsigned int)(src_ofs % VMU_BLOCK_SIZE); - + block->ofs = (unsigned int) (src_ofs % VMU_BLOCK_SIZE); + return block; } @@ -90,11 +195,10 @@ * Reads a byte from a VMU at the specified offset. * */ -static __ |