diff --git a/BaS_gcc/.gdbinit b/BaS_gcc/.gdbinit index 64c2100..598dbde 100644 --- a/BaS_gcc/.gdbinit +++ b/BaS_gcc/.gdbinit @@ -1,7 +1,7 @@ #set disassemble-next-line on define tr - #target remote | m68k-bdm-gdbserver pipe /dev/bdmcf3 - target remote | m68k-bdm-gdbserver pipe /dev/tblcf3 + target remote | m68k-bdm-gdbserver pipe /dev/bdmcf3 + #target remote | m68k-bdm-gdbserver pipe /dev/tblcf3 #target dbug /dev/ttyS0 #monitor bdm-reset end diff --git a/BaS_gcc/Makefile b/BaS_gcc/Makefile index ef428c1..07f809a 100644 --- a/BaS_gcc/Makefile +++ b/BaS_gcc/Makefile @@ -80,12 +80,12 @@ CSRCS= \ pci.c \ dspi.c \ driver_vec.c \ + driver_mem.c \ MCD_dmaApi.c \ MCD_tasks.c \ MCD_tasksInit.c \ \ usb.c \ - usb_mem.c \ ohci-hcd.c \ ehci-hcd.c \ usb_mouse.c \ diff --git a/BaS_gcc/bas.lk.in b/BaS_gcc/bas.lk.in index 54bf34f..9488fdd 100644 --- a/BaS_gcc/bas.lk.in +++ b/BaS_gcc/bas.lk.in @@ -36,13 +36,14 @@ SECTIONS #endif /* MACHINE_FIREBEE */ OBJDIR/wait.o(.text) OBJDIR/exceptions.o(.text) + OBJDIR/driver_vec.o(.text) OBJDIR/interrupts.o(.text) OBJDIR/mmu.o(.text) OBJDIR/BaS.o(.text) OBJDIR/pci.o(.text) OBJDIR/usb.o(.text) - OBJDIR/usb_mem.o(.text) + OBJDIR/driver_mem.o(.text) OBJDIR/usb_mouse.o(.text) OBJDIR/ohci-hcd.o(.text) OBJDIR/ehci-hcd.o(.text) @@ -83,7 +84,8 @@ SECTIONS #endif #ifdef COMPILE_RAM . = ALIGN(16); - _usb_buffer = .; + _driver_mem_buffer = .; + // . = . + DRIVER_MEM_BUFFER_SIZE #endif /* COMPILE_RAM */ } > bas_rom @@ -105,12 +107,9 @@ SECTIONS *(.bss) __BAS_BSS_END = .; - /* The BaS copy routine assumes that tha BaS size - * is a multiple of the following value. - */ . = ALIGN(16); - _usb_buffer = .; - //. = . + USB_BUFFER_SIZE; + _driver_mem_buffer = .; + //. = . + DRIVER_MEM_BUFFER_SIZE; } > bas_ram #endif diff --git a/BaS_gcc/dma/dma.c b/BaS_gcc/dma/dma.c index 97f4315..3fb86df 100644 --- a/BaS_gcc/dma/dma.c +++ b/BaS_gcc/dma/dma.c @@ -27,6 +27,7 @@ #include "bas_printf.h" #include "bas_string.h" #include "cache.h" +#include "exceptions.h" #if MACHINE_FIREBEE #include "firebee.h" @@ -43,6 +44,8 @@ struct dma_channel void (*handler)(void); }; +static char used_reqs[32]; + static struct dma_channel dma_channel[NCHANNELS] = { {-1,NULL}, {-1,NULL}, {-1,NULL}, {-1,NULL}, @@ -51,48 +54,402 @@ static struct dma_channel dma_channel[NCHANNELS] = {-1,NULL}, {-1,NULL}, {-1,NULL}, {-1,NULL}, }; +int dma_set_initiator(int initiator) +{ + switch (initiator) + { + /* these initiators are always active */ + case DMA_ALWAYS: + case DMA_DSPI_RXFIFO: + case DMA_DSPI_TXFIFO: + case DMA_DREQ0: + case DMA_PSC0_RX: + case DMA_PSC0_TX: + case DMA_USB_EP0: + case DMA_USB_EP1: + case DMA_USB_EP2: + case DMA_USB_EP3: + case DMA_PCI_TX: + case DMA_PCI_RX: + case DMA_PSC1_RX: + case DMA_I2C_RX: + case DMA_I2C_TX: + break; + + case DMA_FEC0_RX: + MCF_DMA_IMCR = (MCF_DMA_IMCR & ~MCF_DMA_IMCR_IMC16(3)) + | MCF_DMA_IMCR_IMC16_FEC0RX; + used_reqs[16] = DMA_FEC0_RX; + break; + case DMA_FEC0_TX: + MCF_DMA_IMCR = (MCF_DMA_IMCR & ~MCF_DMA_IMCR_IMC17(3)) + | MCF_DMA_IMCR_IMC17_FEC0TX; + used_reqs[17] = DMA_FEC0_TX; + break; + case DMA_FEC1_RX: + MCF_DMA_IMCR = (MCF_DMA_IMCR & ~MCF_DMA_IMCR_IMC20(3)) + | MCF_DMA_IMCR_IMC20_FEC1RX; + used_reqs[20] = DMA_FEC1_RX; + break; + case DMA_FEC1_TX: + if (used_reqs[21] == 0) + { + MCF_DMA_IMCR = (MCF_DMA_IMCR & ~MCF_DMA_IMCR_IMC21(3)) + | MCF_DMA_IMCR_IMC21_FEC1TX; + used_reqs[21] = DMA_FEC1_TX; + } + else if (used_reqs[25] == 0) + { + MCF_DMA_IMCR = (MCF_DMA_IMCR & ~MCF_DMA_IMCR_IMC25(3)) + | MCF_DMA_IMCR_IMC25_FEC1TX; + used_reqs[25] = DMA_FEC1_TX; + } + else if (used_reqs[31] == 0) + { + MCF_DMA_IMCR = (MCF_DMA_IMCR & ~MCF_DMA_IMCR_IMC31(3)) + | MCF_DMA_IMCR_IMC31_FEC1TX; + used_reqs[31] = DMA_FEC1_TX; + } + else /* No empty slots */ + return 1; + break; + case DMA_DREQ1: + if (used_reqs[29] == 0) + { + MCF_DMA_IMCR = (MCF_DMA_IMCR & ~MCF_DMA_IMCR_IMC29(3)) + | MCF_DMA_IMCR_IMC29_DREQ1; + used_reqs[29] = DMA_DREQ1; + } + else if (used_reqs[21] == 0) + { + MCF_DMA_IMCR = (MCF_DMA_IMCR & ~MCF_DMA_IMCR_IMC21(3)) + | MCF_DMA_IMCR_IMC21_DREQ1; + used_reqs[21] = DMA_DREQ1; + } + else /* No empty slots */ + return 1; + break; + case DMA_CTM0: + if (used_reqs[24] == 0) + { + MCF_DMA_IMCR = (MCF_DMA_IMCR & ~MCF_DMA_IMCR_IMC24(3)) + | MCF_DMA_IMCR_IMC24_CTM0; + used_reqs[24] = DMA_CTM0; + } + else /* No empty slots */ + return 1; + break; + case DMA_CTM1: + if (used_reqs[25] == 0) + { + MCF_DMA_IMCR = (MCF_DMA_IMCR & ~MCF_DMA_IMCR_IMC25(3)) + | MCF_DMA_IMCR_IMC25_CTM1; + used_reqs[25] = DMA_CTM1; + } + else /* No empty slots */ + return 1; + break; + case DMA_CTM2: + if (used_reqs[26] == 0) + { + MCF_DMA_IMCR = (MCF_DMA_IMCR & ~MCF_DMA_IMCR_IMC26(3)) + | MCF_DMA_IMCR_IMC26_CTM2; + used_reqs[26] = DMA_CTM2; + } + else /* No empty slots */ + return 1; + break; + case DMA_CTM3: + if (used_reqs[27] == 0) + { + MCF_DMA_IMCR = (MCF_DMA_IMCR & ~MCF_DMA_IMCR_IMC27(3)) + | MCF_DMA_IMCR_IMC27_CTM3; + used_reqs[27] = DMA_CTM3; + } + else /* No empty slots */ + return 1; + break; + case DMA_CTM4: + if (used_reqs[28] == 0) + { + MCF_DMA_IMCR = (MCF_DMA_IMCR & ~MCF_DMA_IMCR_IMC28(3)) + | MCF_DMA_IMCR_IMC28_CTM4; + used_reqs[28] = DMA_CTM4; + } + else /* No empty slots */ + return 1; + break; + case DMA_CTM5: + if (used_reqs[29] == 0) + { + MCF_DMA_IMCR = (MCF_DMA_IMCR & ~MCF_DMA_IMCR_IMC29(3)) + | MCF_DMA_IMCR_IMC29_CTM5; + used_reqs[29] = DMA_CTM5; + } + else /* No empty slots */ + return 1; + break; + case DMA_CTM6: + if (used_reqs[30] == 0) + { + MCF_DMA_IMCR = (MCF_DMA_IMCR & ~MCF_DMA_IMCR_IMC30(3)) + | MCF_DMA_IMCR_IMC30_CTM6; + used_reqs[30] = DMA_CTM6; + } + else /* No empty slots */ + return 1; + break; + case DMA_CTM7: + if (used_reqs[31] == 0) + { + MCF_DMA_IMCR = (MCF_DMA_IMCR & ~MCF_DMA_IMCR_IMC31(3)) + | MCF_DMA_IMCR_IMC31_CTM7; + used_reqs[31] = DMA_CTM7; + } + else /* No empty slots */ + return 1; + break; + case DMA_USBEP4: + if (used_reqs[26] == 0) + { + MCF_DMA_IMCR = (MCF_DMA_IMCR & ~MCF_DMA_IMCR_IMC26(3)) + | MCF_DMA_IMCR_IMC26_USBEP4; + used_reqs[26] = DMA_USBEP4; + } + else /* No empty slots */ + return 1; + break; + case DMA_USBEP5: + if (used_reqs[27] == 0) + { + MCF_DMA_IMCR = (MCF_DMA_IMCR & ~MCF_DMA_IMCR_IMC27(3)) + | MCF_DMA_IMCR_IMC27_USBEP5; + used_reqs[27] = DMA_USBEP5; + } + else /* No empty slots */ + return 1; + break; + case DMA_USBEP6: + if (used_reqs[28] == 0) + { + MCF_DMA_IMCR = (MCF_DMA_IMCR & ~MCF_DMA_IMCR_IMC28(3)) + | MCF_DMA_IMCR_IMC28_USBEP6; + used_reqs[28] = DMA_USBEP6; + } + else /* No empty slots */ + return 1; + break; + case DMA_PSC2_RX: + if (used_reqs[28] == 0) + { + MCF_DMA_IMCR = (MCF_DMA_IMCR & ~MCF_DMA_IMCR_IMC28(3)) + | MCF_DMA_IMCR_IMC28_PSC2RX; + used_reqs[28] = DMA_PSC2_RX; } + else /* No empty slots */ + return 1; + break; + case DMA_PSC2_TX: + if (used_reqs[29] == 0) + { + MCF_DMA_IMCR = (MCF_DMA_IMCR & ~MCF_DMA_IMCR_IMC29(3)) + | MCF_DMA_IMCR_IMC29_PSC2TX; + used_reqs[29] = DMA_PSC2_TX; + } + else /* No empty slots */ + return 1; + break; + case DMA_PSC3_RX: + if (used_reqs[30] == 0) + { + MCF_DMA_IMCR = (MCF_DMA_IMCR & ~MCF_DMA_IMCR_IMC30(3)) + | MCF_DMA_IMCR_IMC30_PSC3RX; + used_reqs[30] = DMA_PSC3_RX; + } + else /* No empty slots */ + return 1; + break; + case DMA_PSC3_TX: + if (used_reqs[31] == 0) + { + MCF_DMA_IMCR = (MCF_DMA_IMCR & ~MCF_DMA_IMCR_IMC31(3)) + | MCF_DMA_IMCR_IMC31_PSC3TX; + used_reqs[31] = DMA_PSC3_TX; + } + else /* No empty slots */ + return 1; + break; + default: + return 1; + } + return 0; +} + /* - * return the channel being initiated by the given requestor + * Return the initiator number for the given requestor + * + * Parameters: + * requestor Initiator/Requestor identifier + * + * Return Value: + * The initiator number (0-31) if initiator has been assigned + * 0 (always initiator) otherwise + */ +uint32_t dma_get_initiator(int requestor) +{ + uint32_t i; + + for (i = 0; i < sizeof(used_reqs); ++i) + { + if (used_reqs[i] == requestor) + return i; + } + return 0; +} + +/* + * Remove the given initiator from the active list + * + * Parameters: + * requestor Initiator/Requestor identifier + */ +void dma_free_initiator(int requestor) +{ + uint32_t i; + + for (i = 16; i < sizeof(used_reqs); ++i) + { + if (used_reqs[i] == requestor) + { + used_reqs[i] = 0; + break; + } + } +} + +/* + * Attempt to find an available channel and mark it as used + * + * Parameters: + * requestor Initiator/Requestor identifier + * + * Return Value: + * First available channel or -1 if they are all occupied + */ +int dma_set_channel(int requestor, void (*handler)(void)) +{ + int i; + + /* Check to see if this requestor is already assigned to a channel */ + if ((i = dma_get_channel(requestor)) != -1) + return i; + + for (i=0; i= 0 && channel < NCHANNELS) + { + dma_channel[channel].req = -1; + dma_channel[channel].handler = NULL; + } +} +/* + * Return the channel being initiated by the given requestor + * + * Parameters: + * requestor Initiator/Requestor identifier + * + * Return Value: + * Channel that the requestor is controlling or -1 if hasn't been + * activated */ int dma_get_channel(int requestor) { - int i; + uint32_t i; - for (i = 0; i < NCHANNELS; i++) - { - if (dma_channel[i].req == requestor) - { - return i; - } - } - return -1; + for (i=0; i>=1) + { + if (interrupts & 0x1) + { + /* If there is a handler, call it */ + if (dma_channel[i].handler != NULL) + dma_channel[i].handler(); + } + } + + set_ipl(ipl); + return 1; +} +/********************************************************************/ + void *dma_memcpy(void *dst, void *src, size_t n) { int ret; diff --git a/BaS_gcc/if/driver_vec.c b/BaS_gcc/if/driver_vec.c index 214eb92..98aa2c6 100644 --- a/BaS_gcc/if/driver_vec.c +++ b/BaS_gcc/if/driver_vec.c @@ -28,6 +28,44 @@ #include "driver_vec.h" #include "version.h" #include "xhdi_sd.h" +#include "dma.h" +#include "driver_mem.h" + +/* + * driver interface struct for the SD card BaS driver + */ +static struct xhdi_driver_interface xhdi_call_interface = +{ + xhdi_call +}; + +/* + * driver interface struct for the BaS multichannel DMA driver + * This is exactly the same thing FireTOS provides and the MiNT FEC drivers expect. + * It can be directly used in TOS to register the corresponding cookie ("DMAC"). + */ +static struct dma_driver_interface dma_interface = +{ + .version = 0x0101, + .magic = 'DMAC', + .dma_set_initiator = &dma_set_initiator, + .dma_get_initiator = dma_get_initiator, + .dma_free_initiator = dma_free_initiator, + .dma_set_channel = dma_set_channel, + .dma_get_channel = dma_get_channel, + .dma_free_channel = dma_free_channel, + .dma_clear_channel = dma_clear_channel, + .MCD_startDma = MCD_startDma, + .MCD_dmaStatus = MCD_dmaStatus, + .MCD_XferProgrQuery = MCD_XferProgrQuery, + .MCD_killDma = MCD_killDma, + .MCD_continDma = MCD_continDma, + .MCD_pauseDma = MCD_pauseDma, + .MCD_resumeDma = MCD_resumeDma, + .MCD_csumQuery = MCD_csumQuery, + .dma_malloc = driver_mem_alloc, + .dma_free = driver_mem_free +}; static struct generic_interface interfaces[] = { @@ -39,7 +77,15 @@ static struct generic_interface interfaces[] = .description = "BaS SD Card driver", .version = 0, .revision = 1, - .interface.xhdi = { xhdi_call } + .interface.xhdi = &xhdi_call_interface + }, + { + .type = MCD_DRIVER, + .name = "MCDDMA", + .description = "BaS Multichannel DMA driver", + .version = 0, + .revision = 1, + .interface.dma = &dma_interface, }, /* insert new drivers here */ @@ -52,7 +98,7 @@ static struct generic_interface interfaces[] = /* * this is the driver table we expose to the OS */ -static struct driver_table drivers = +static struct driver_table bas_drivers = { .bas_version = MAJOR_VERSION, .bas_revision = MINOR_VERSION, @@ -60,3 +106,12 @@ static struct driver_table drivers = .interfaces = { interfaces } }; +void __attribute__((interrupt)) get_bas_drivers(void) +{ + __asm__ __volatile__( + "move.l #%[drivers],d0\n\t" + : /* no output */ + : [drivers] "o" (bas_drivers) /* input */ + : /* clobber */ + ); +} diff --git a/BaS_gcc/include/MCF5475_DMA.h b/BaS_gcc/include/MCF5475_DMA.h index 3334cca..4e6f916 100644 --- a/BaS_gcc/include/MCF5475_DMA.h +++ b/BaS_gcc/include/MCF5475_DMA.h @@ -129,22 +129,54 @@ #define MCF_DMA_PRIOR_HLD (0x80) /* Bit definitions and macros for MCF_DMA_IMCR */ -#define MCF_DMA_IMCR_IMC0(x) (((x)&0x3)<<0) -#define MCF_DMA_IMCR_IMC1(x) (((x)&0x3)<<0x2) -#define MCF_DMA_IMCR_IMC2(x) (((x)&0x3)<<0x4) -#define MCF_DMA_IMCR_IMC3(x) (((x)&0x3)<<0x6) -#define MCF_DMA_IMCR_IMC4(x) (((x)&0x3)<<0x8) -#define MCF_DMA_IMCR_IMC5(x) (((x)&0x3)<<0xA) -#define MCF_DMA_IMCR_IMC6(x) (((x)&0x3)<<0xC) -#define MCF_DMA_IMCR_IMC7(x) (((x)&0x3)<<0xE) -#define MCF_DMA_IMCR_IMC8(x) (((x)&0x3)<<0x10) -#define MCF_DMA_IMCR_IMC9(x) (((x)&0x3)<<0x12) -#define MCF_DMA_IMCR_IMC10(x) (((x)&0x3)<<0x14) -#define MCF_DMA_IMCR_IMC11(x) (((x)&0x3)<<0x16) -#define MCF_DMA_IMCR_IMC12(x) (((x)&0x3)<<0x18) -#define MCF_DMA_IMCR_IMC13(x) (((x)&0x3)<<0x1A) -#define MCF_DMA_IMCR_IMC14(x) (((x)&0x3)<<0x1C) -#define MCF_DMA_IMCR_IMC15(x) (((x)&0x3)<<0x1E) +#define MCF_DMA_IMCR_IMC16(x) (((x)&0x3)<<0) +#define MCF_DMA_IMCR_IMC17(x) (((x)&0x3)<<0x2) +#define MCF_DMA_IMCR_IMC18(x) (((x)&0x3)<<0x4) +#define MCF_DMA_IMCR_IMC19(x) (((x)&0x3)<<0x6) +#define MCF_DMA_IMCR_IMC20(x) (((x)&0x3)<<0x8) +#define MCF_DMA_IMCR_IMC21(x) (((x)&0x3)<<0xA) +#define MCF_DMA_IMCR_IMC22(x) (((x)&0x3)<<0xC) +#define MCF_DMA_IMCR_IMC23(x) (((x)&0x3)<<0xE) +#define MCF_DMA_IMCR_IMC24(x) (((x)&0x3)<<0x10) +#define MCF_DMA_IMCR_IMC25(x) (((x)&0x3)<<0x12) +#define MCF_DMA_IMCR_IMC26(x) (((x)&0x3)<<0x14) +#define MCF_DMA_IMCR_IMC27(x) (((x)&0x3)<<0x16) +#define MCF_DMA_IMCR_IMC28(x) (((x)&0x3)<<0x18) +#define MCF_DMA_IMCR_IMC29(x) (((x)&0x3)<<0x1A) +#define MCF_DMA_IMCR_IMC30(x) (((x)&0x3)<<0x1C) +#define MCF_DMA_IMCR_IMC31(x) (((x)&0x3)<<0x1E) + + +#define MCF_DMA_IMCR_IMC16_FEC0RX (0x00000000) +#define MCF_DMA_IMCR_IMC17_FEC0TX (0x00000000) +#define MCF_DMA_IMCR_IMC18_FEC0RX (0x00000020) +#define MCF_DMA_IMCR_IMC19_FEC0TX (0x00000080) +#define MCF_DMA_IMCR_IMC20_FEC1RX (0x00000100) +#define MCF_DMA_IMCR_IMC21_DREQ1 (0x00000000) +#define MCF_DMA_IMCR_IMC21_FEC1TX (0x00000400) +#define MCF_DMA_IMCR_IMC22_FEC0RX (0x00001000) +#define MCF_DMA_IMCR_IMC23_FEC0TX (0x00004000) +#define MCF_DMA_IMCR_IMC24_CTM0 (0x00010000) +#define MCF_DMA_IMCR_IMC24_FEC1RX (0x00020000) +#define MCF_DMA_IMCR_IMC25_CTM1 (0x00040000) +#define MCF_DMA_IMCR_IMC25_FEC1TX (0x00080000) +#define MCF_DMA_IMCR_IMC26_USBEP4 (0x00000000) +#define MCF_DMA_IMCR_IMC26_CTM2 (0x00200000) +#define MCF_DMA_IMCR_IMC27_USBEP5 (0x00000000) +#define MCF_DMA_IMCR_IMC27_CTM3 (0x00800000) +#define MCF_DMA_IMCR_IMC28_USBEP6 (0x00000000) +#define MCF_DMA_IMCR_IMC28_CTM4 (0x01000000) +#define MCF_DMA_IMCR_IMC28_DREQ1 (0x02000000) +#define MCF_DMA_IMCR_IMC28_PSC2RX (0x03000000) +#define MCF_DMA_IMCR_IMC29_DREQ1 (0x04000000) +#define MCF_DMA_IMCR_IMC29_CTM5 (0x08000000) +#define MCF_DMA_IMCR_IMC29_PSC2TX (0x0C000000) +#define MCF_DMA_IMCR_IMC30_FEC1RX (0x00000000) +#define MCF_DMA_IMCR_IMC30_CTM6 (0x10000000) +#define MCF_DMA_IMCR_IMC30_PSC3RX (0x30000000) +#define MCF_DMA_IMCR_IMC31_FEC1TX (0x00000000) +#define MCF_DMA_IMCR_IMC31_CTM7 (0x80000000) +#define MCF_DMA_IMCR_IMC31_PSC3TX (0xC0000000) /* Bit definitions and macros for MCF_DMA_TSKSZ0 */ #define MCF_DMA_TSKSZ0_DSTSZ7(x) (((x)&0x3)<<0) diff --git a/BaS_gcc/include/dma.h b/BaS_gcc/include/dma.h index 4edcc95..53a34a9 100644 --- a/BaS_gcc/include/dma.h +++ b/BaS_gcc/include/dma.h @@ -23,15 +23,20 @@ #ifndef _DMA_H_ #define _DMA_H_ -#include +#include "MCF5475.h" +#include "MCD_dma.h" +#include "bas_string.h" #define DMA_INTC_LVL 6 #define DMA_INTC_PRI 0 + +void *dma_memcpy(void *dst, void *src, size_t n); extern int dma_init(void); extern int dma_get_channel(int requestor); extern int dma_set_channel(int, void (*)(void)); extern void dma_free_channel(int requestor); +extern void dma_clear_channel(int channel); extern uint32_t dma_get_initiator(int requestor); extern int dma_set_initiator(int initiator); extern void dma_free_initiator(int initiator); diff --git a/BaS_gcc/include/driver_vec.h b/BaS_gcc/include/driver_vec.h index 7e63f9d..791500c 100644 --- a/BaS_gcc/include/driver_vec.h +++ b/BaS_gcc/include/driver_vec.h @@ -26,6 +26,7 @@ #define _DRIVER_VEC_H_ #include "xhdi_sd.h" +#include "MCD_dma.h" enum driver_type { @@ -34,6 +35,7 @@ enum driver_type CHARDEV_DRIVER, VIDEO_DRIVER, XHDI_DRIVER, + MCD_DRIVER, }; struct generic_driver_interface @@ -44,6 +46,31 @@ struct generic_driver_interface uint32_t (*ioctl)(uint32_t request, ...); }; +struct dma_driver_interface +{ + int32_t version; + int32_t magic; + int32_t (*dma_set_initiator)(int initiator); + uint32_t (*dma_get_initiator)(int requestor); + void (*dma_free_initiator)(int requestor); + int32_t (*dma_set_channel)(int requestor, void (*handler)(void)); + int (*dma_get_channel)(int requestor); + void (*dma_free_channel)(int requestor); + void (*dma_clear_channel)(int channel); + int (*MCD_startDma)(int channel, int8_t *srcAddr, int16_t srcIncr, int8_t *destAddr, int16_t destIncr, + uint32_t dmaSize, uint32_t xferSize, uint32_t initiator, int32_t priority, uint32_t flags, + uint32_t funcDesc); + int (*MCD_dmaStatus)(int channel); + int (*MCD_XferProgrQuery)(int channel, MCD_XferProg *progRep); + int (*MCD_killDma)(int channel); + int (*MCD_continDma)(int channel); + int (*MCD_pauseDma)(int channel); + int (*MCD_resumeDma)(int channel); + int (*MCD_csumQuery)(int channel, uint32_t *csum); + void *(*dma_malloc)(long amount); + int (*dma_free)(void *addr); +}; + struct xhdi_driver_interface { uint32_t (*xhdivec)(); @@ -51,8 +78,9 @@ struct xhdi_driver_interface union interface { - struct generic_driver_interface gdi; - struct xhdi_driver_interface xhdi; + struct generic_driver_interface *gdi; + struct xhdi_driver_interface *xhdi; + struct dma_driver_interface *dma; }; struct generic_interface diff --git a/BaS_gcc/include/firebee.h b/BaS_gcc/include/firebee.h index 7ebc2e5..2077d9d 100644 --- a/BaS_gcc/include/firebee.h +++ b/BaS_gcc/include/firebee.h @@ -43,7 +43,7 @@ #endif /* COMPILE_RAM */ -#define USB_BUFFER_SIZE 0x80000 +#define DRIVER_MEM_BUFFER_SIZE 0x80000 #define EMUTOS_BASE_ADDRESS 0xe0600000 diff --git a/BaS_gcc/include/m5484l.h b/BaS_gcc/include/m5484l.h index 8795285..250bc6a 100644 --- a/BaS_gcc/include/m5484l.h +++ b/BaS_gcc/include/m5484l.h @@ -42,7 +42,7 @@ #define TARGET_ADDRESS BOOTFLASH_BASE_ADDRESS #endif /* COMPILE_RAM */ -#define USB_BUFFER_SIZE 0x80000 +#define DRIVER_MEM_BUFFER_SIZE 0x80000 #define EMUTOS_BASE_ADDRESS 0xe0100000 diff --git a/BaS_gcc/include/mcd_initiators.h b/BaS_gcc/include/mcd_initiators.h index f42cba1..c6f41ca 100644 --- a/BaS_gcc/include/mcd_initiators.h +++ b/BaS_gcc/include/mcd_initiators.h @@ -9,7 +9,7 @@ #define DMA_DSPI_TXFIFO (2) #define DMA_DREQ0 (3) #define DMA_PSC0_RX (4) -#define DMA_PSCO_TX (5) +#define DMA_PSC0_TX (5) #define DMA_USB_EP0 (6) #define DMA_USB_EP1 (7) #define DMA_USB_EP2 (8) diff --git a/BaS_gcc/include/usb.h b/BaS_gcc/include/usb.h index b63029f..2454869 100644 --- a/BaS_gcc/include/usb.h +++ b/BaS_gcc/include/usb.h @@ -28,6 +28,7 @@ //#include #include +#include "driver_mem.h" #include "pci.h" #include "mod_devicetable.h" #include "pci_ids.h" diff --git a/BaS_gcc/include/version.h b/BaS_gcc/include/version.h index c6fff8c..23f6869 100644 --- a/BaS_gcc/include/version.h +++ b/BaS_gcc/include/version.h @@ -29,7 +29,7 @@ */ #define MAJOR_VERSION 0 -#define MINOR_VERSION 8 +#define MINOR_VERSION 82 #endif /* VERSION_H_ */ diff --git a/BaS_gcc/pci/ehci-hcd.c b/BaS_gcc/pci/ehci-hcd.c index 5f71097..d8bd896 100644 --- a/BaS_gcc/pci/ehci-hcd.c +++ b/BaS_gcc/pci/ehci-hcd.c @@ -908,7 +908,7 @@ static void hc_free_buffers(struct ehci *ehci) if (ehci->descriptor != NULL) { - usb_free(ehci->descriptor); + driver_mem_free(ehci->descriptor); ehci->descriptor = NULL; } @@ -916,20 +916,20 @@ static void hc_free_buffers(struct ehci *ehci) { if (ehci->td_unaligned[i] != NULL) { - usb_free(ehci->td_unaligned[i]); + driver_mem_free(ehci->td_unaligned[i]); ehci->td_unaligned[i] = NULL; } } if (ehci->qh_unaligned != NULL) { - usb_free(ehci->qh_unaligned); + driver_mem_free(ehci->qh_unaligned); ehci->qh_unaligned = NULL; } if (ehci->qh_list_unaligned != NULL) { - usb_free(ehci->qh_list_unaligned); + driver_mem_free(ehci->qh_list_unaligned); ehci->qh_list_unaligned = NULL; } } @@ -952,7 +952,7 @@ int ehci_usb_lowlevel_init(long handle, const struct pci_device_id *ent, void ** else if (!gehci.handle) /* for restart USB cmd */ return(-1); - gehci.qh_list_unaligned = (struct QH *)usb_malloc(sizeof(struct QH) + 32); + gehci.qh_list_unaligned = (struct QH *)driver_mem_alloc(sizeof(struct QH) + 32); if (gehci.qh_list_unaligned == NULL) { debug("QHs malloc failed"); @@ -962,7 +962,7 @@ int ehci_usb_lowlevel_init(long handle, const struct pci_device_id *ent, void ** gehci.qh_list = (struct QH *)(((uint32_t)gehci.qh_list_unaligned + 31) & ~31); memset(gehci.qh_list, 0, sizeof(struct QH)); - gehci.qh_unaligned = (struct QH *)usb_malloc(sizeof(struct QH) + 32); + gehci.qh_unaligned = (struct QH *)driver_mem_alloc(sizeof(struct QH) + 32); if (gehci.qh_unaligned == NULL) { @@ -975,7 +975,7 @@ int ehci_usb_lowlevel_init(long handle, const struct pci_device_id *ent, void ** for (i = 0; i < 3; i++) { - gehci.td_unaligned[i] = (struct qTD *)usb_malloc(sizeof(struct qTD) + 32); + gehci.td_unaligned[i] = (struct qTD *)driver_mem_alloc(sizeof(struct qTD) + 32); if (gehci.td_unaligned[i] == NULL) { debug("TDs malloc failed"); @@ -986,7 +986,7 @@ int ehci_usb_lowlevel_init(long handle, const struct pci_device_id *ent, void ** memset(gehci.td[i], 0, sizeof(struct qTD)); } - gehci.descriptor = (struct descriptor *)usb_malloc(sizeof(struct descriptor)); + gehci.descriptor = (struct descriptor *)driver_mem_alloc(sizeof(struct descriptor)); if (gehci.descriptor == NULL) { debug("decriptor malloc failed"); diff --git a/BaS_gcc/pci/ohci-hcd.c b/BaS_gcc/pci/ohci-hcd.c index b0d26f7..482c62f 100644 --- a/BaS_gcc/pci/ohci-hcd.c +++ b/BaS_gcc/pci/ohci-hcd.c @@ -226,7 +226,7 @@ static void urb_free_priv(urb_priv_t *urb) } } } - /* FIXME: usb_free(urb); */ + /* FIXME: driver_mem_free(urb); */ } /*-------------------------------------------------------------------------*/ @@ -1509,7 +1509,7 @@ static int submit_common_msg(ohci_t *ohci, struct usb_device *dev, uint32_t pipe int stat = 0; int maxsize = usb_maxpacket(dev, pipe); int timeout; - urb_priv_t *urb = (urb_priv_t *) usb_malloc(sizeof(urb_priv_t)); + urb_priv_t *urb = (urb_priv_t *) driver_mem_alloc(sizeof(urb_priv_t)); if (urb == NULL) { @@ -2021,17 +2021,17 @@ static void hc_free_buffers(ohci_t *ohci) { if (ohci->td_unaligned != NULL) { - /* FIXME: usb_free(ohci->td_unaligned); */ + /* FIXME: driver_mem_free(ohci->td_unaligned); */ ohci->td_unaligned = NULL; } if (ohci->ohci_dev_unaligned != NULL) { - /* FIXME: usb_free(ohci->ohci_dev_unaligned); */ + /* FIXME: driver_mem_free(ohci->ohci_dev_unaligned); */ ohci->ohci_dev_unaligned = NULL; } if (ohci->hcca_unaligned != NULL) { - /* FIXME: usb_free(ohci->hcca_unaligned); */ + /* FIXME: driver_mem_free(ohci->hcca_unaligned); */ ohci->hcca_unaligned = NULL; } } @@ -2060,7 +2060,7 @@ int ohci_usb_lowlevel_init(int32_t handle, const struct pci_device_id *ent, void ohci->controller = (ohci->handle >> 16) & 3; /* PCI function */ /* this must be aligned to a 256 byte boundary */ - ohci->hcca_unaligned = (struct ohci_hcca *) usb_malloc(sizeof(struct ohci_hcca) + 256); + ohci->hcca_unaligned = (struct ohci_hcca *) driver_mem_alloc(sizeof(struct ohci_hcca) + 256); if (ohci->hcca_unaligned == NULL) { err("HCCA malloc failed"); @@ -2071,7 +2071,7 @@ int ohci_usb_lowlevel_init(int32_t handle, const struct pci_device_id *ent, void ohci->hcca = (struct ohci_hcca *) (((uint32_t)ohci->hcca_unaligned + 255) & ~255); memset(ohci->hcca, 0, sizeof(struct ohci_hcca)); info("aligned ghcca %p", ohci->hcca); - ohci->ohci_dev_unaligned = (struct ohci_device *) usb_malloc(sizeof(struct ohci_device) + 8); + ohci->ohci_dev_unaligned = (struct ohci_device *) driver_mem_alloc(sizeof(struct ohci_device) + 8); if (ohci->ohci_dev_unaligned == NULL) { err("EDs malloc failed"); @@ -2082,7 +2082,7 @@ int ohci_usb_lowlevel_init(int32_t handle, const struct pci_device_id *ent, void memset(ohci->ohci_dev, 0, sizeof(struct ohci_device)); info("aligned EDs %p", ohci->ohci_dev); - ohci->td_unaligned = (struct td *) usb_malloc(sizeof(struct td) * (NUM_TD + 1)); + ohci->td_unaligned = (struct td *) driver_mem_alloc(sizeof(struct td) * (NUM_TD + 1)); if (ohci->td_unaligned == NULL) { err("TDs malloc failed"); diff --git a/BaS_gcc/pci/pci.c b/BaS_gcc/pci/pci.c index cf4ac38..a09615a 100644 --- a/BaS_gcc/pci/pci.c +++ b/BaS_gcc/pci/pci.c @@ -148,6 +148,7 @@ __attribute__((interrupt)) void xlb_pci_interrupt(void) __attribute__((interrupt)) void pci_interrupt(void) { + debug_printf("PCI interrupt\r\n"); } static int32_t pci_get_interrupt_cause(int32_t *handles) @@ -646,7 +647,7 @@ static void pci_device_config(uint16_t bus, uint16_t device, uint16_t function) /* check if device requests an interrupt */ il = pci_read_config_byte(handle, PCIIPR); - xprintf("device requests interrupts on interrupt pin %d\r\n", il); + debug_printf("device requests interrupts on interrupt pin %d\r\n", il); /* if so, register interrupts */ diff --git a/BaS_gcc/sys/BaS.c b/BaS_gcc/sys/BaS.c index a58ac7e..e3ce9ec 100644 --- a/BaS_gcc/sys/BaS.c +++ b/BaS_gcc/sys/BaS.c @@ -25,9 +25,9 @@ #include #include "MCF5475.h" -#include "MCF5475_SLT.h" #include "startcf.h" #include "sysinit.h" +#include "util.h" #include "cache.h" #include "bas_printf.h" #include "bas_string.h" @@ -56,8 +56,6 @@ extern uint8_t _EMUTOS[]; extern uint8_t _EMUTOS_SIZE[]; #define EMUTOS_SIZE ((uint32_t)_EMUTOS_SIZE) /* size of EmuTOS, in bytes */ -#define NOP() __asm__ __volatile__("nop\n\t" : : : "memory") /* need this to force pipeline sync after MMUCR write */ - /* * check if it is possible to transfer data to PIC */ diff --git a/BaS_gcc/sys/exceptions.S b/BaS_gcc/sys/exceptions.S index 11340ab..97766b6 100644 --- a/BaS_gcc/sys/exceptions.S +++ b/BaS_gcc/sys/exceptions.S @@ -40,7 +40,6 @@ .extern _video_tlb .extern _video_sbt .extern _flush_and_invalidate_caches - .extern _xhdi_sd_install /* trap #0 exception vector for installation of xhdi SD card driver */ /* PCI interrupt handlers */ .extern _irq5_handler @@ -270,9 +269,9 @@ init_vec_loop: lea access(pc),a1 // set illegal access exception handler move.l a1,0x08(a0) -// trap #0 (without any parameters for now) is used to provide BaS' XHDI -// routine address to EmuTOS. - lea _xhdi_sd_install,a1 + .extern _get_bas_drivers +// trap #0 (without any parameters for now) is used to provide BaS' driver addresses to the OS + lea _get_bas_drivers(pc),a1 move.l a1,0x80(a0) // trap #0 exception vector #ifdef MACHINE_FIREBEE @@ -439,7 +438,7 @@ zd_end: move.l (a7)+,d0 move.l (a7)+,a0 rte - + #ifdef _NOT_USED_ linea: move.w #0x2700,sr // disable interrupt diff --git a/BaS_gcc/sys/sysinit.c b/BaS_gcc/sys/sysinit.c index d23b15d..eeb20e1 100644 --- a/BaS_gcc/sys/sysinit.c +++ b/BaS_gcc/sys/sysinit.c @@ -1105,13 +1105,15 @@ void initialize_hardware(void) dvi_on(); #endif /* MACHINE_FIREBEE */ init_pci(); + + /* do not try to init USB for now on the Firebee, it hangs the machine */ +#ifndef MACHINE_FIREBEE init_usb(); +#endif + #if MACHINE_FIREBEE init_ac97(); #endif /* MACHINE_FIREBEE */ - - //hexdump(0x6a000000, 8192); - xprintf("initialize and test DMA\r\n"); dma_init(); /* jump into the BaS */ diff --git a/BaS_gcc/usb/usb.c b/BaS_gcc/usb/usb.c index bb276c4..bcda079 100644 --- a/BaS_gcc/usb/usb.c +++ b/BaS_gcc/usb/usb.c @@ -56,7 +56,7 @@ extern int usb_stor_curr_dev; extern uint32_t usb_1st_disk_drive; -#define USB_DEBUG +//#define USB_DEBUG #ifdef USB_DEBUG #define debug_printf(fmt, args...) xprintf(fmt , ##args) @@ -121,13 +121,13 @@ int usb_init(int32_t handle, const struct pci_device_id *ent) asynch_allowed = 1; if (handle && (ent != NULL)) { - if (usb_mem_init()) + if (driver_mem_init()) { usb_started = 0; return -1; /* out of memoy */ } if (usb_dev == NULL) - usb_dev = (struct usb_device *)usb_malloc(sizeof(struct usb_device) * USB_MAX_BUS * USB_MAX_DEVICE); + usb_dev = (struct usb_device *) driver_mem_alloc(sizeof(struct usb_device) * USB_MAX_BUS * USB_MAX_DEVICE); if (usb_dev == NULL) { usb_started = 0; @@ -174,7 +174,7 @@ int usb_init(int32_t handle, const struct pci_device_id *ent) /* if lowlevel init is OK, scan the bus for devices * i.e. search HUBs and configure them */ if (setup_packet == NULL) - setup_packet = (void *)usb_malloc(sizeof(struct devrequest)); + setup_packet = (void *)driver_mem_alloc(sizeof(struct devrequest)); if (setup_packet == NULL) { usb_started = 0; @@ -207,7 +207,7 @@ int usb_stop(void) asynch_allowed = 1; usb_started = 0; usb_hub_reset(bus_index); - usb_free(setup_packet); + driver_mem_free(setup_packet); for (i = 0; i < USB_MAX_BUS; i++) { struct hci *priv = controller_priv[i]; @@ -234,7 +234,7 @@ int usb_stop(void) } } bus_index = 0; - usb_mem_stop(); + driver_mem_stop(); } return res; } @@ -767,7 +767,7 @@ int usb_string(struct usb_device *dev, int index, char *buf, size_t size) if (size <= 0 || !buf || !index) return -1; buf[0] = 0; - tbuf = (unsigned char *)usb_malloc(USB_BUFSIZ); + tbuf = (unsigned char *)driver_mem_alloc(USB_BUFSIZ); if (tbuf == NULL) { debug_printf("usb_string: malloc failure\r\n"); @@ -780,13 +780,13 @@ int usb_string(struct usb_device *dev, int index, char *buf, size_t size) if (err < 0) { debug_printf("error getting string descriptor 0 (error=%lx)\r\n", dev->status); - usb_free(tbuf); + driver_mem_free(tbuf); return -1; } else if (tbuf[0] < 4) { debug_printf("string descriptor 0 too short\r\n"); - usb_free(tbuf); + driver_mem_free(tbuf); return -1; } else @@ -800,7 +800,7 @@ int usb_string(struct usb_device *dev, int index, char *buf, size_t size) err = usb_string_sub(dev, dev->string_langid, index, tbuf); if (err < 0) { - usb_free(tbuf); + driver_mem_free(tbuf); return err; } size--; /* leave room for trailing NULL char in output buffer */ @@ -815,7 +815,7 @@ int usb_string(struct usb_device *dev, int index, char *buf, size_t size) } buf[idx] = 0; err = idx; - usb_free(tbuf); + driver_mem_free(tbuf); return err; } @@ -926,7 +926,7 @@ int usb_new_device(struct usb_device *dev) addr = dev->devnum; dev->devnum = 0; - tmpbuf = (unsigned char *) usb_malloc(USB_BUFSIZ); + tmpbuf = (unsigned char *) driver_mem_alloc(USB_BUFSIZ); if (tmpbuf == NULL) { debug_printf("usb_new_device: malloc failure\r\n"); @@ -947,7 +947,7 @@ int usb_new_device(struct usb_device *dev) if (err < 8) { debug_printf("\r\nUSB device not responding, giving up (status=%lX)\r\n", dev->status); - usb_free(tmpbuf); + driver_mem_free(tmpbuf); return 1; } #else @@ -972,7 +972,7 @@ int usb_new_device(struct usb_device *dev) if (err < 0) { debug_printf("usb_new_device: usb_get_descriptor() failed\r\n"); - usb_free(tmpbuf); + driver_mem_free(tmpbuf); return 1; } dev->descriptor.bMaxPacketSize0 = desc->bMaxPacketSize0; @@ -992,7 +992,7 @@ int usb_new_device(struct usb_device *dev) if (port < 0) { debug_printf("usb_new_device: cannot locate device's port.\r\n"); - usb_free(tmpbuf); + driver_mem_free(tmpbuf); return 1; } /* reset the port for the second time */ @@ -1000,7 +1000,7 @@ int usb_new_device(struct usb_device *dev) if (err < 0) { debug_printf("\r\nCouldn't reset port %d\r\n", port); - usb_free(tmpbuf); + driver_mem_free(tmpbuf); return 1; } } @@ -1019,7 +1019,7 @@ int usb_new_device(struct usb_device *dev) if (err < 0) { debug_printf("\r\nUSB device not accepting new address (error=%lX)\r\n", dev->status); - usb_free(tmpbuf); + driver_mem_free(tmpbuf); return 1; } wait(10 * 1000); /* Let the SET_ADDRESS settle */ @@ -1031,7 +1031,7 @@ int usb_new_device(struct usb_device *dev) debug_printf("unable to get device descriptor (error=%d)\r\n", err); else debug_printf("USB device descriptor short read (expected %i, got %i)\r\n", tmp, err); - usb_free(tmpbuf); + driver_mem_free(tmpbuf); return 1; } /* correct le values */ @@ -1047,7 +1047,7 @@ int usb_new_device(struct usb_device *dev) if (usb_set_configuration(dev, dev->config.bConfigurationValue)) { debug_printf("failed to set default configuration len %d, status %lX\r\n", dev->act_len, dev->status); - usb_free(tmpbuf); + driver_mem_free(tmpbuf); return -1; } debug_printf("new device strings: Mfr=%d, Product=%d, SerialNumber=%d\r\n", @@ -1067,7 +1067,7 @@ int usb_new_device(struct usb_device *dev) debug_printf("SerialNumber %s\r\n", dev->serial); /* now prode if the device is a hub */ usb_hub_probe(dev, 0); - usb_free(tmpbuf); + driver_mem_free(tmpbuf); return 0; } @@ -1117,7 +1117,7 @@ void usb_scan_devices(void *priv) * Probes device for being a hub and configurate it */ -#define USB_HUB_DEBUG +//#define USB_HUB_DEBUG #ifdef USB_HUB_DEBUG #define dbg_hub(fmt, args...) xprintf(fmt , ##args) @@ -1462,7 +1462,7 @@ int usb_hub_configure(struct usb_device *dev) if (hub == NULL) return -1; hub->pusb_dev = dev; - buffer = (unsigned char *)usb_malloc(USB_BUFSIZ); + buffer = (unsigned char *)driver_mem_alloc(USB_BUFSIZ); if (buffer == NULL) { dbg_hub("usb_hub_configure: malloc failure\r\n"); @@ -1472,7 +1472,7 @@ int usb_hub_configure(struct usb_device *dev) if (usb_get_hub_descriptor(dev, buffer, 4) < 0) { dbg_hub("usb_hub_configure: failed to get hub descriptor, giving up %lX\r\n", dev->status); - usb_free(buffer); + driver_mem_free(buffer); return -1; } dbg_hub("bLength:%02X bDescriptorType:%02X bNbrPorts:%02X\r\n", buffer[0], buffer[1], buffer[2]); @@ -1482,13 +1482,13 @@ int usb_hub_configure(struct usb_device *dev) if (i > USB_BUFSIZ) { dbg_hub("usb_hub_configure: failed to get hub descriptor - too long: %d\r\n", descriptor->bLength); - usb_free(buffer); + driver_mem_free(buffer); return -1; } if (usb_get_hub_descriptor(dev, buffer, descriptor->bLength) < 0) { dbg_hub("usb_hub_configure: failed to get hub descriptor 2nd giving up %lX\r\n", dev->status); - usb_free(buffer); + driver_mem_free(buffer); return -1; } memcpy((unsigned char *)&hub->desc, buffer, descriptor->bLength); @@ -1539,13 +1539,13 @@ int usb_hub_configure(struct usb_device *dev) if (sizeof(struct usb_hub_status) > USB_BUFSIZ) { dbg_hub("usb_hub_configure: failed to get Status - too long: %d\r\n", descriptor->bLength); - usb_free(buffer); + driver_mem_free(buffer); return -1; } if (usb_get_hub_status(dev, buffer) < 0) { dbg_hub("usb_hub_configure: failed to get Status %lX\r\n", dev->status); - usb_free(buffer); + driver_mem_free(buffer); return -1; } @@ -1583,7 +1583,7 @@ int usb_hub_configure(struct usb_device *dev) if (queue_poll_hub == NULL) #endif usb_hub_events(dev); - usb_free(buffer); + driver_mem_free(buffer); return 0; } diff --git a/BaS_gcc/usb/usb_mem.c b/BaS_gcc/usb/usb_mem.c index edfb3ff..cc7364b 100644 --- a/BaS_gcc/usb/usb_mem.c +++ b/BaS_gcc/usb/usb_mem.c @@ -1,5 +1,5 @@ /* - * usb_mem.c + * driver_mem.c * * based from Emutos / BDOS * @@ -30,18 +30,18 @@ #define TRUE 1 #endif -#undef USB_MEM_DEBUG +#undef DRIVER_MEM_DEBUG -#ifdef USB_MEM_DEBUG -#define USB_MEM_PRINTF(fmt, args...) xprintf(fmt, ##args) +#ifdef DRIVER_MEM_DEBUG +#define dbg(fmt, args...) xprintf(fmt, ##args) #else -#define USB_MEM_PRINTF(fmt, args...) +#define dbg(fmt, args...) #endif extern void *info_fvdi; extern long offscren_reserved(void); -extern uint8_t usb_buffer[USB_BUFFER_SIZE]; /* defined in linker control file */ +extern uint8_t driver_mem[DRIVER_MEM_SIZE]; /* defined in linker control file */ /* MD - Memory Descriptor */ @@ -74,7 +74,8 @@ static MPB pmd; static void *xmgetblk(void) { int i; - for(i = 0; i < MAXMD; i++) + + for (i = 0; i < MAXMD; i++) { if (tab_md[i].m_own == NULL) { @@ -82,14 +83,16 @@ static void *xmgetblk(void) return(&tab_md[i]); } } - return(NULL); + return NULL; } static void xmfreblk(void *m) { - int i = (int)(((long)m - (long)tab_md) / sizeof(MD)); + int i = (int)(((long) m - (long) tab_md) / sizeof(MD)); if ((i > 0) && (i < MAXMD)) + { tab_md[i].m_own = NULL; + } } static MD *ffit(long amount, MPB *mp) @@ -97,13 +100,18 @@ static MD *ffit(long amount, MPB *mp) MD *p, *q, *p1; /* free list is composed of MD's */ int maxflg; long maxval; + if (amount != -1) { amount += 15; /* 16 bytes alignment */ amount &= 0xFFFFFFF0; } + if ((q = mp->mp_rover) == 0) /* get rotating pointer */ - return(0) ; + { + return 0; + } + maxval = 0; maxflg = ((amount == -1) ? TRUE : FALSE) ; p = q->m_link; /* start with next MD */ @@ -119,14 +127,21 @@ static MD *ffit(long amount, MPB *mp) { /* big enough */ if (p->m_length == amount) + { q->m_link = p->m_link; /* take the whole thing */ + } else { - /* break it up - 1st allocate a new - MD to describe the remainder */ + /* + * break it up - 1st allocate a new + * MD to describe the remainder + */ p1 = xmgetblk(); if (p1 == NULL) + { return(NULL); + } + /* init new MD */ p1->m_length = p->m_length - amount; p1->m_start = p->m_start + amount; @@ -144,16 +159,22 @@ static MD *ffit(long amount, MPB *mp) else if (p->m_length > maxval) maxval = p->m_length; p = ( q=p )->m_link; - } - while(q != mp->mp_rover); - /* return either the max, or 0 (error) */ + } while(q != mp->mp_rover); + + /* + * return either the max, or 0 (error) + */ if (maxflg) { - maxval -= 15; /* 16 bytes alignment */ + maxval -= 15; /* 16 bytes alignment */ if (maxval < 0) + { maxval = 0; + } else + { maxval &= 0xFFFFFFF0; + } } return(maxflg ? (MD *) maxval : 0); } @@ -161,84 +182,123 @@ static MD *ffit(long amount, MPB *mp) static void freeit(MD *m, MPB *mp) { MD *p, *q; + q = 0; - for(p = mp->mp_mfl; p ; p = (q=p) -> m_link) + for (p = mp->mp_mfl; p ; p = (q = p) -> m_link) { if (m->m_start <= p->m_start) + { break; + } } m->m_link = p; + if (q) + { q->m_link = m; + } else + { mp->mp_mfl = m; + } + if (!mp->mp_rover) + { mp->mp_rover = m; + } + if (p) { if (m->m_start + m->m_length == p->m_start) - { /* join to higher neighbor */ + { + /* join to higher neighbor */ m->m_length += p->m_length; m->m_link = p->m_link; if (p == mp->mp_rover) + { mp->mp_rover = m; + } xmfreblk(p); } } if (q) { if (q->m_start + q->m_length == m->m_start) - { /* join to lower neighbor */ + { + /* join to lower neighbor */ q->m_length += m->m_length; q->m_link = m->m_link; if (m == mp->mp_rover) + { mp->mp_rover = q; + } xmfreblk(m); } } } -int usb_free(void *addr) +int driver_mem_free(void *addr) { int level; MD *p, **q; MPB *mpb; mpb = &pmd; level = set_ipl(7); + for(p = *(q = &mpb->mp_mal); p; p = *(q = &p->m_link)) { - if ((long)addr == p->m_start) + if ((long) addr == p->m_start) + { break; + } } + if (!p) { set_ipl(level); return(-1); } + *q = p->m_link; freeit(p, mpb); set_ipl(level); - USB_MEM_PRINTF("usb_free(0x%08X)\r\n", addr); + + dbg("driver_mem_free(0x%08X)\r\n", addr); + return(0); } -void *usb_malloc(long amount) +void *driver_mem_alloc(long amount) { void *ret = NULL; int level; MD *m; + if (amount == -1L) + { return((void *)ffit(-1L, &pmd)); + } + if (amount <= 0 ) + { return(0); + } + if ((amount & 1)) + { amount++; + } + level = set_ipl(7); m = ffit(amount, &pmd); + if (m != NULL) + { ret = (void *)m->m_start; + } set_ipl(level); - USB_MEM_PRINTF("usb_malloc(%d) = 0x%08X\r\n", amount, ret); + dbg("driver_mem_alloc(%d) = 0x%08X\r\n", amount, ret); + return(ret); } @@ -247,21 +307,25 @@ void *usb_malloc(long amount) int usb_mem_init(void) { #ifdef USE_RADEON_MEMORY - usb_buffer = (void *)offscren_reserved(); - if (usb_buffer == NULL) + driver_mem_buffer = (void *) offscren_reserved(); + if (driver_mem_buffer == NULL) #endif - memset(usb_buffer, 0, USB_BUFFER_SIZE); + memset(driver_mem_buffer, 0, DRIVER_MEM_BUFFER_SIZE); - if (usb_buffer == NULL) + if (driver_mem_buffer == NULL) + { return(-1); + } + pmd.mp_mfl = pmd.mp_rover = &tab_md[0]; - tab_md[0].m_link = (MD *)NULL; - tab_md[0].m_start = ((long)usb_buffer + 15) & ~15; - tab_md[0].m_length = USB_BUFFER_SIZE; - tab_md[0].m_own = (void *)1L; - pmd.mp_mal = (MD *)NULL; - memset(usb_buffer, 0, tab_md[0].m_length); - USB_MEM_PRINTF("USB malloc buffer at 0x%08X size %d\r\n", tab_md[0].m_start, tab_md[0].m_length); + tab_md[0].m_link = (MD *) NULL; + tab_md[0].m_start = ((long) driver_mem_buffer + 15) & ~15; + tab_md[0].m_length = DRIVER_MEM_BUFFER_SIZE; + tab_md[0].m_own = (void *) 1L; + pmd.mp_mal = (MD *) NULL; + memset(driver_mem_buffer, 0, tab_md[0].m_length); + dbg("driver memory buffer at 0x%08X size %d\r\n", tab_md[0].m_start, tab_md[0].m_length); + return(0); } @@ -269,7 +333,7 @@ void usb_mem_stop(void) { #ifndef CONFIG_USB_MEM_NO_CACHE #ifdef USE_RADEON_MEMORY - if (usb_buffer == (void *)offscren_reserved()) + if (driver_mem_buffer == (void *) offscren_reserved()) return; #endif #endif diff --git a/BaS_gcc/usb/usb_mouse.c b/BaS_gcc/usb/usb_mouse.c index 1a51952..1016ce4 100644 --- a/BaS_gcc/usb/usb_mouse.c +++ b/BaS_gcc/usb/usb_mouse.c @@ -24,6 +24,7 @@ #include "bas_printf.h" #include "usb.h" #include "exceptions.h" +#include "driver_mem.h" #undef USB_MOUSE_DEBUG #ifdef USB_MOUSE_DEBUG @@ -49,7 +50,7 @@ int usb_mouse_deregister(struct usb_device *dev) dev->irq_handle = NULL; if(new != NULL) { - usb_free(new); + driver_mem_free(new); new = NULL; } mouse_installed = 0; @@ -83,9 +84,9 @@ int drv_usb_mouse_init(void) for(i = 0; i < USB_MAX_DEVICE; i++) { struct usb_device *dev = usb_get_dev_index(i, j); /* get device */ - if(dev == NULL) + if (dev == NULL) break; - if(usb_mouse_register(dev) > 0) + if (usb_mouse_register(dev) > 0) return 1; } } @@ -212,7 +213,7 @@ static int usb_mouse_probe(struct usb_device *dev, unsigned int ifnum) return 0; if((ep->bmAttributes & 3) != 3) return 0; - new = (unsigned char *)usb_malloc(8); + new = (unsigned char *)driver_mem_alloc(8); if(new == NULL) return 0; mse_printf("USB MOUSE found set protocol...\r\n");