sunrise: redo the bounce buffer logic
authorAlan Cox <alan@linux.intel.com>
Sun, 7 Apr 2019 12:38:16 +0000 (13:38 +0100)
committerAlan Cox <alan@linux.intel.com>
Sun, 7 Apr 2019 12:38:16 +0000 (13:38 +0100)
We can't just use tmpbuf because there might not be a free buffer and we'd
then get into a mess recursing through our I/O subystem. Instead grab a bit
of spare high memory for the moment.

Once the buffer reclaim logic is added we will turn discard and friends into
buffers but keep the last 512 bytes before FFFF as a bounce buffer that drivers
can share.

(FFFF itself is slot switching so magic and reserved)

Kernel/platform-msx1/devide_sunrise.c
Kernel/platform-msx1/main.c
Kernel/platform-msx1/msx.h

index 2db663f..09a7fcc 100644 (file)
@@ -33,7 +33,9 @@ static uint8_t sunrise_transfer_sector(void)
         blk_op.blkdev->driver_data |= FLAG_CACHE_DIRTY;
     /* Shortcut: this range can only occur for a user mode I/O */
     if (addr >= (uint8_t *)0x3E00U && addr < (uint8_t *)0x8000U) {
-        blk_op.addr = tmpbuf();
+        /* We can't just use tmpbuf because the buffer might be dirty which would
+           trigger a recursive I/O and then badness happens */
+        blk_op.addr = bouncebuffer;
         blk_op.is_user = 0;
 //        kprintf("bounced do_ide_xfer %p %x:", addr, mask);
         if (blk_op.is_read) {
@@ -45,7 +47,6 @@ static uint8_t sunrise_transfer_sector(void)
             if (do_ide_xfer(mask))
                 goto fail;
         }
-        tmpfree(blk_op.addr);
 //        kprintf("bounced done.\n");
         blk_op.addr = addr;
         blk_op.is_user = old_user;
index 9917083..078a3b6 100644 (file)
@@ -3,6 +3,7 @@
 #include <kdata.h>
 #include <printf.h>
 #include <devtty.h>
+#include <msx.h>
 
 /* These are set by the msx startup asm code */
 extern uint16_t vdpport;
@@ -11,6 +12,7 @@ uint16_t swap_dev = 0xFFFF;
 uint16_t ramtop = 0xC000;
 uint8_t machine_type;
 uint8_t vdptype;
+uint8_t *bouncebuffer;
 
 void platform_idle(void)
 {
@@ -42,5 +44,7 @@ void platform_interrupt(void)
 
 void platform_discard(void)
 {
-    /* Until we tackle the buffers */
+    /* Until we tackle the buffers. When we do we will reserve 512 bytes
+       at the end (probably FDFE-FFFE (FFFF being magic)) */
+    bouncebuffer = (uint8_t *)0xFD00;  /* Hack for now */
 }
index 74f991b..9f13471 100644 (file)
@@ -36,4 +36,6 @@ extern uint8_t *map_slot1_user(uint8_t slotinfo) __z88dk_fastcall;
 
 extern void copy_vectors(void);
 
+extern uint8_t *bouncebuffer;
+
 #endif