driver interface to OS implemented and tested

This commit is contained in:
Markus Fröschle
2013-12-22 14:16:59 +00:00
parent c6e5540ee3
commit 94ff279838
22 changed files with 704 additions and 162 deletions

View File

@@ -1,7 +1,7 @@
#set disassemble-next-line on #set disassemble-next-line on
define tr define tr
#target remote | m68k-bdm-gdbserver pipe /dev/bdmcf3 target remote | m68k-bdm-gdbserver pipe /dev/bdmcf3
target remote | m68k-bdm-gdbserver pipe /dev/tblcf3 #target remote | m68k-bdm-gdbserver pipe /dev/tblcf3
#target dbug /dev/ttyS0 #target dbug /dev/ttyS0
#monitor bdm-reset #monitor bdm-reset
end end

View File

@@ -80,12 +80,12 @@ CSRCS= \
pci.c \ pci.c \
dspi.c \ dspi.c \
driver_vec.c \ driver_vec.c \
driver_mem.c \
MCD_dmaApi.c \ MCD_dmaApi.c \
MCD_tasks.c \ MCD_tasks.c \
MCD_tasksInit.c \ MCD_tasksInit.c \
\ \
usb.c \ usb.c \
usb_mem.c \
ohci-hcd.c \ ohci-hcd.c \
ehci-hcd.c \ ehci-hcd.c \
usb_mouse.c \ usb_mouse.c \

View File

@@ -36,13 +36,14 @@ SECTIONS
#endif /* MACHINE_FIREBEE */ #endif /* MACHINE_FIREBEE */
OBJDIR/wait.o(.text) OBJDIR/wait.o(.text)
OBJDIR/exceptions.o(.text) OBJDIR/exceptions.o(.text)
OBJDIR/driver_vec.o(.text)
OBJDIR/interrupts.o(.text) OBJDIR/interrupts.o(.text)
OBJDIR/mmu.o(.text) OBJDIR/mmu.o(.text)
OBJDIR/BaS.o(.text) OBJDIR/BaS.o(.text)
OBJDIR/pci.o(.text) OBJDIR/pci.o(.text)
OBJDIR/usb.o(.text) OBJDIR/usb.o(.text)
OBJDIR/usb_mem.o(.text) OBJDIR/driver_mem.o(.text)
OBJDIR/usb_mouse.o(.text) OBJDIR/usb_mouse.o(.text)
OBJDIR/ohci-hcd.o(.text) OBJDIR/ohci-hcd.o(.text)
OBJDIR/ehci-hcd.o(.text) OBJDIR/ehci-hcd.o(.text)
@@ -83,7 +84,8 @@ SECTIONS
#endif #endif
#ifdef COMPILE_RAM #ifdef COMPILE_RAM
. = ALIGN(16); . = ALIGN(16);
_usb_buffer = .; _driver_mem_buffer = .;
// . = . + DRIVER_MEM_BUFFER_SIZE
#endif /* COMPILE_RAM */ #endif /* COMPILE_RAM */
} > bas_rom } > bas_rom
@@ -105,12 +107,9 @@ SECTIONS
*(.bss) *(.bss)
__BAS_BSS_END = .; __BAS_BSS_END = .;
/* The BaS copy routine assumes that tha BaS size
* is a multiple of the following value.
*/
. = ALIGN(16); . = ALIGN(16);
_usb_buffer = .; _driver_mem_buffer = .;
//. = . + USB_BUFFER_SIZE; //. = . + DRIVER_MEM_BUFFER_SIZE;
} > bas_ram } > bas_ram
#endif #endif

View File

@@ -27,6 +27,7 @@
#include "bas_printf.h" #include "bas_printf.h"
#include "bas_string.h" #include "bas_string.h"
#include "cache.h" #include "cache.h"
#include "exceptions.h"
#if MACHINE_FIREBEE #if MACHINE_FIREBEE
#include "firebee.h" #include "firebee.h"
@@ -43,6 +44,8 @@ struct dma_channel
void (*handler)(void); void (*handler)(void);
}; };
static char used_reqs[32];
static struct dma_channel dma_channel[NCHANNELS] = static struct dma_channel dma_channel[NCHANNELS] =
{ {
{-1,NULL}, {-1,NULL}, {-1,NULL}, {-1,NULL}, {-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}, {-1,NULL}, {-1,NULL}, {-1,NULL}, {-1,NULL},
}; };
/* int dma_set_initiator(int initiator)
* return the channel being initiated by the given requestor
*/
int dma_get_channel(int requestor)
{ {
int i; 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;
for (i = 0; i < NCHANNELS; i++) 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)
{ {
if (dma_channel[i].req == requestor) 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)
{ {
return i; 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;
} }
return -1; 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 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 dma_set_channel(int requestor, void (*handler)(void))
{ {
int i; int i;
/* check to see if requestor is already assigned to a channel */ /* Check to see if this requestor is already assigned to a channel */
if ((i = dma_get_channel(requestor)) != -1) if ((i = dma_get_channel(requestor)) != -1)
{
return i; return i;
}
for (i = 0; i < NCHANNELS; i++) for (i=0; i<NCHANNELS; ++i)
{ {
if (dma_channel[i].req == -1) if (dma_channel[i].req == -1)
{ {
dma_channel[i].req = requestor; dma_channel[i].req = requestor;
dma_channel[i].handler = handler; dma_channel[i].handler = handler;
return i; return i;
} }
} }
/* all channels taken */ /* All channels taken */
return -1; return -1;
} }
void dma_clear_channel(int channel)
{
if(channel >= 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)
{
uint32_t i;
for (i=0; i<NCHANNELS; ++i)
{
if (dma_channel[i].req == requestor)
return i;
}
return -1;
}
/*
* Remove the channel being initiated by the given requestor from
* the active list
*
* Parameters:
* requestor Initiator/Requestor identifier
*/
void dma_free_channel(int requestor)
{
uint32_t i;
for (i=0; i<NCHANNELS; ++i)
{
if (dma_channel[i].req == requestor)
{
dma_channel[i].req = -1;
dma_channel[i].handler = NULL;
break;
}
}
}
/*
* This is the catch-all interrupt handler for the mult-channel DMA
*/
int dma_interrupt_handler(void *arg1, void *arg2)
{
uint32_t i, interrupts;
uint32_t ipl;
(void)arg1;
(void)arg2;
ipl = set_ipl(0x2700);
/*
* Determine which interrupt(s) triggered by AND'ing the
* pending interrupts with those that aren't masked.
*/
interrupts = MCF_DMA_DIPR & ~MCF_DMA_DIMR;
/* Make sure we are here for a reason */
if (interrupts == 0)
return 0;
/* Clear the interrupt in the pending register */
MCF_DMA_DIPR = interrupts;
for (i = 0; i < 16; ++i, interrupts>>=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) void *dma_memcpy(void *dst, void *src, size_t n)
{ {
int ret; int ret;

View File

@@ -28,6 +28,44 @@
#include "driver_vec.h" #include "driver_vec.h"
#include "version.h" #include "version.h"
#include "xhdi_sd.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[] = static struct generic_interface interfaces[] =
{ {
@@ -39,7 +77,15 @@ static struct generic_interface interfaces[] =
.description = "BaS SD Card driver", .description = "BaS SD Card driver",
.version = 0, .version = 0,
.revision = 1, .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 */ /* insert new drivers here */
@@ -52,7 +98,7 @@ static struct generic_interface interfaces[] =
/* /*
* this is the driver table we expose to the OS * 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_version = MAJOR_VERSION,
.bas_revision = MINOR_VERSION, .bas_revision = MINOR_VERSION,
@@ -60,3 +106,12 @@ static struct driver_table drivers =
.interfaces = { interfaces } .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 */
);
}

View File

@@ -129,22 +129,54 @@
#define MCF_DMA_PRIOR_HLD (0x80) #define MCF_DMA_PRIOR_HLD (0x80)
/* Bit definitions and macros for MCF_DMA_IMCR */ /* Bit definitions and macros for MCF_DMA_IMCR */
#define MCF_DMA_IMCR_IMC0(x) (((x)&0x3)<<0) #define MCF_DMA_IMCR_IMC16(x) (((x)&0x3)<<0)
#define MCF_DMA_IMCR_IMC1(x) (((x)&0x3)<<0x2) #define MCF_DMA_IMCR_IMC17(x) (((x)&0x3)<<0x2)
#define MCF_DMA_IMCR_IMC2(x) (((x)&0x3)<<0x4) #define MCF_DMA_IMCR_IMC18(x) (((x)&0x3)<<0x4)
#define MCF_DMA_IMCR_IMC3(x) (((x)&0x3)<<0x6) #define MCF_DMA_IMCR_IMC19(x) (((x)&0x3)<<0x6)
#define MCF_DMA_IMCR_IMC4(x) (((x)&0x3)<<0x8) #define MCF_DMA_IMCR_IMC20(x) (((x)&0x3)<<0x8)
#define MCF_DMA_IMCR_IMC5(x) (((x)&0x3)<<0xA) #define MCF_DMA_IMCR_IMC21(x) (((x)&0x3)<<0xA)
#define MCF_DMA_IMCR_IMC6(x) (((x)&0x3)<<0xC) #define MCF_DMA_IMCR_IMC22(x) (((x)&0x3)<<0xC)
#define MCF_DMA_IMCR_IMC7(x) (((x)&0x3)<<0xE) #define MCF_DMA_IMCR_IMC23(x) (((x)&0x3)<<0xE)
#define MCF_DMA_IMCR_IMC8(x) (((x)&0x3)<<0x10) #define MCF_DMA_IMCR_IMC24(x) (((x)&0x3)<<0x10)
#define MCF_DMA_IMCR_IMC9(x) (((x)&0x3)<<0x12) #define MCF_DMA_IMCR_IMC25(x) (((x)&0x3)<<0x12)
#define MCF_DMA_IMCR_IMC10(x) (((x)&0x3)<<0x14) #define MCF_DMA_IMCR_IMC26(x) (((x)&0x3)<<0x14)
#define MCF_DMA_IMCR_IMC11(x) (((x)&0x3)<<0x16) #define MCF_DMA_IMCR_IMC27(x) (((x)&0x3)<<0x16)
#define MCF_DMA_IMCR_IMC12(x) (((x)&0x3)<<0x18) #define MCF_DMA_IMCR_IMC28(x) (((x)&0x3)<<0x18)
#define MCF_DMA_IMCR_IMC13(x) (((x)&0x3)<<0x1A) #define MCF_DMA_IMCR_IMC29(x) (((x)&0x3)<<0x1A)
#define MCF_DMA_IMCR_IMC14(x) (((x)&0x3)<<0x1C) #define MCF_DMA_IMCR_IMC30(x) (((x)&0x3)<<0x1C)
#define MCF_DMA_IMCR_IMC15(x) (((x)&0x3)<<0x1E) #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 */ /* Bit definitions and macros for MCF_DMA_TSKSZ0 */
#define MCF_DMA_TSKSZ0_DSTSZ7(x) (((x)&0x3)<<0) #define MCF_DMA_TSKSZ0_DSTSZ7(x) (((x)&0x3)<<0)

View File

@@ -23,15 +23,20 @@
#ifndef _DMA_H_ #ifndef _DMA_H_
#define _DMA_H_ #define _DMA_H_
#include <MCF5475.h> #include "MCF5475.h"
#include "MCD_dma.h"
#include "bas_string.h"
#define DMA_INTC_LVL 6 #define DMA_INTC_LVL 6
#define DMA_INTC_PRI 0 #define DMA_INTC_PRI 0
void *dma_memcpy(void *dst, void *src, size_t n);
extern int dma_init(void); extern int dma_init(void);
extern int dma_get_channel(int requestor); extern int dma_get_channel(int requestor);
extern int dma_set_channel(int, void (*)(void)); extern int dma_set_channel(int, void (*)(void));
extern void dma_free_channel(int requestor); extern void dma_free_channel(int requestor);
extern void dma_clear_channel(int channel);
extern uint32_t dma_get_initiator(int requestor); extern uint32_t dma_get_initiator(int requestor);
extern int dma_set_initiator(int initiator); extern int dma_set_initiator(int initiator);
extern void dma_free_initiator(int initiator); extern void dma_free_initiator(int initiator);

View File

@@ -26,6 +26,7 @@
#define _DRIVER_VEC_H_ #define _DRIVER_VEC_H_
#include "xhdi_sd.h" #include "xhdi_sd.h"
#include "MCD_dma.h"
enum driver_type enum driver_type
{ {
@@ -34,6 +35,7 @@ enum driver_type
CHARDEV_DRIVER, CHARDEV_DRIVER,
VIDEO_DRIVER, VIDEO_DRIVER,
XHDI_DRIVER, XHDI_DRIVER,
MCD_DRIVER,
}; };
struct generic_driver_interface struct generic_driver_interface
@@ -44,6 +46,31 @@ struct generic_driver_interface
uint32_t (*ioctl)(uint32_t request, ...); 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 struct xhdi_driver_interface
{ {
uint32_t (*xhdivec)(); uint32_t (*xhdivec)();
@@ -51,8 +78,9 @@ struct xhdi_driver_interface
union interface union interface
{ {
struct generic_driver_interface gdi; struct generic_driver_interface *gdi;
struct xhdi_driver_interface xhdi; struct xhdi_driver_interface *xhdi;
struct dma_driver_interface *dma;
}; };
struct generic_interface struct generic_interface

View File

@@ -43,7 +43,7 @@
#endif /* COMPILE_RAM */ #endif /* COMPILE_RAM */
#define USB_BUFFER_SIZE 0x80000 #define DRIVER_MEM_BUFFER_SIZE 0x80000
#define EMUTOS_BASE_ADDRESS 0xe0600000 #define EMUTOS_BASE_ADDRESS 0xe0600000

View File

@@ -42,7 +42,7 @@
#define TARGET_ADDRESS BOOTFLASH_BASE_ADDRESS #define TARGET_ADDRESS BOOTFLASH_BASE_ADDRESS
#endif /* COMPILE_RAM */ #endif /* COMPILE_RAM */
#define USB_BUFFER_SIZE 0x80000 #define DRIVER_MEM_BUFFER_SIZE 0x80000
#define EMUTOS_BASE_ADDRESS 0xe0100000 #define EMUTOS_BASE_ADDRESS 0xe0100000

View File

@@ -9,7 +9,7 @@
#define DMA_DSPI_TXFIFO (2) #define DMA_DSPI_TXFIFO (2)
#define DMA_DREQ0 (3) #define DMA_DREQ0 (3)
#define DMA_PSC0_RX (4) #define DMA_PSC0_RX (4)
#define DMA_PSCO_TX (5) #define DMA_PSC0_TX (5)
#define DMA_USB_EP0 (6) #define DMA_USB_EP0 (6)
#define DMA_USB_EP1 (7) #define DMA_USB_EP1 (7)
#define DMA_USB_EP2 (8) #define DMA_USB_EP2 (8)

View File

@@ -28,6 +28,7 @@
//#include <stdlib.h> //#include <stdlib.h>
#include <bas_string.h> #include <bas_string.h>
#include "driver_mem.h"
#include "pci.h" #include "pci.h"
#include "mod_devicetable.h" #include "mod_devicetable.h"
#include "pci_ids.h" #include "pci_ids.h"

View File

@@ -29,7 +29,7 @@
*/ */
#define MAJOR_VERSION 0 #define MAJOR_VERSION 0
#define MINOR_VERSION 8 #define MINOR_VERSION 82
#endif /* VERSION_H_ */ #endif /* VERSION_H_ */

View File

@@ -908,7 +908,7 @@ static void hc_free_buffers(struct ehci *ehci)
if (ehci->descriptor != NULL) if (ehci->descriptor != NULL)
{ {
usb_free(ehci->descriptor); driver_mem_free(ehci->descriptor);
ehci->descriptor = NULL; ehci->descriptor = NULL;
} }
@@ -916,20 +916,20 @@ static void hc_free_buffers(struct ehci *ehci)
{ {
if (ehci->td_unaligned[i] != NULL) if (ehci->td_unaligned[i] != NULL)
{ {
usb_free(ehci->td_unaligned[i]); driver_mem_free(ehci->td_unaligned[i]);
ehci->td_unaligned[i] = NULL; ehci->td_unaligned[i] = NULL;
} }
} }
if (ehci->qh_unaligned != NULL) if (ehci->qh_unaligned != NULL)
{ {
usb_free(ehci->qh_unaligned); driver_mem_free(ehci->qh_unaligned);
ehci->qh_unaligned = NULL; ehci->qh_unaligned = NULL;
} }
if (ehci->qh_list_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; 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 */ else if (!gehci.handle) /* for restart USB cmd */
return(-1); 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) if (gehci.qh_list_unaligned == NULL)
{ {
debug("QHs malloc failed"); 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); gehci.qh_list = (struct QH *)(((uint32_t)gehci.qh_list_unaligned + 31) & ~31);
memset(gehci.qh_list, 0, sizeof(struct QH)); 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) 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++) 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) if (gehci.td_unaligned[i] == NULL)
{ {
debug("TDs malloc failed"); 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)); 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) if (gehci.descriptor == NULL)
{ {
debug("decriptor malloc failed"); debug("decriptor malloc failed");

View File

@@ -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 stat = 0;
int maxsize = usb_maxpacket(dev, pipe); int maxsize = usb_maxpacket(dev, pipe);
int timeout; 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) if (urb == NULL)
{ {
@@ -2021,17 +2021,17 @@ static void hc_free_buffers(ohci_t *ohci)
{ {
if (ohci->td_unaligned != NULL) if (ohci->td_unaligned != NULL)
{ {
/* FIXME: usb_free(ohci->td_unaligned); */ /* FIXME: driver_mem_free(ohci->td_unaligned); */
ohci->td_unaligned = NULL; ohci->td_unaligned = NULL;
} }
if (ohci->ohci_dev_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; ohci->ohci_dev_unaligned = NULL;
} }
if (ohci->hcca_unaligned != NULL) if (ohci->hcca_unaligned != NULL)
{ {
/* FIXME: usb_free(ohci->hcca_unaligned); */ /* FIXME: driver_mem_free(ohci->hcca_unaligned); */
ohci->hcca_unaligned = NULL; 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 */ ohci->controller = (ohci->handle >> 16) & 3; /* PCI function */
/* this must be aligned to a 256 byte boundary */ /* 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) if (ohci->hcca_unaligned == NULL)
{ {
err("HCCA malloc failed"); 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); ohci->hcca = (struct ohci_hcca *) (((uint32_t)ohci->hcca_unaligned + 255) & ~255);
memset(ohci->hcca, 0, sizeof(struct ohci_hcca)); memset(ohci->hcca, 0, sizeof(struct ohci_hcca));
info("aligned ghcca %p", 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) if (ohci->ohci_dev_unaligned == NULL)
{ {
err("EDs malloc failed"); 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)); memset(ohci->ohci_dev, 0, sizeof(struct ohci_device));
info("aligned EDs %p", ohci->ohci_dev); 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) if (ohci->td_unaligned == NULL)
{ {
err("TDs malloc failed"); err("TDs malloc failed");

View File

@@ -148,6 +148,7 @@ __attribute__((interrupt)) void xlb_pci_interrupt(void)
__attribute__((interrupt)) void 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) 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 */ /* check if device requests an interrupt */
il = pci_read_config_byte(handle, PCIIPR); 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 */ /* if so, register interrupts */

View File

@@ -25,9 +25,9 @@
#include <stdbool.h> #include <stdbool.h>
#include "MCF5475.h" #include "MCF5475.h"
#include "MCF5475_SLT.h"
#include "startcf.h" #include "startcf.h"
#include "sysinit.h" #include "sysinit.h"
#include "util.h"
#include "cache.h" #include "cache.h"
#include "bas_printf.h" #include "bas_printf.h"
#include "bas_string.h" #include "bas_string.h"
@@ -56,8 +56,6 @@ extern uint8_t _EMUTOS[];
extern uint8_t _EMUTOS_SIZE[]; extern uint8_t _EMUTOS_SIZE[];
#define EMUTOS_SIZE ((uint32_t)_EMUTOS_SIZE) /* size of EmuTOS, in bytes */ #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 * check if it is possible to transfer data to PIC
*/ */

View File

@@ -40,7 +40,6 @@
.extern _video_tlb .extern _video_tlb
.extern _video_sbt .extern _video_sbt
.extern _flush_and_invalidate_caches .extern _flush_and_invalidate_caches
.extern _xhdi_sd_install /* trap #0 exception vector for installation of xhdi SD card driver */
/* PCI interrupt handlers */ /* PCI interrupt handlers */
.extern _irq5_handler .extern _irq5_handler
@@ -270,9 +269,9 @@ init_vec_loop:
lea access(pc),a1 // set illegal access exception handler lea access(pc),a1 // set illegal access exception handler
move.l a1,0x08(a0) move.l a1,0x08(a0)
// trap #0 (without any parameters for now) is used to provide BaS' XHDI .extern _get_bas_drivers
// routine address to EmuTOS. // trap #0 (without any parameters for now) is used to provide BaS' driver addresses to the OS
lea _xhdi_sd_install,a1 lea _get_bas_drivers(pc),a1
move.l a1,0x80(a0) // trap #0 exception vector move.l a1,0x80(a0) // trap #0 exception vector
#ifdef MACHINE_FIREBEE #ifdef MACHINE_FIREBEE

View File

@@ -1105,13 +1105,15 @@ void initialize_hardware(void)
dvi_on(); dvi_on();
#endif /* MACHINE_FIREBEE */ #endif /* MACHINE_FIREBEE */
init_pci(); init_pci();
/* do not try to init USB for now on the Firebee, it hangs the machine */
#ifndef MACHINE_FIREBEE
init_usb(); init_usb();
#endif
#if MACHINE_FIREBEE #if MACHINE_FIREBEE
init_ac97(); init_ac97();
#endif /* MACHINE_FIREBEE */ #endif /* MACHINE_FIREBEE */
//hexdump(0x6a000000, 8192);
xprintf("initialize and test DMA\r\n");
dma_init(); dma_init();
/* jump into the BaS */ /* jump into the BaS */

View File

@@ -56,7 +56,7 @@
extern int usb_stor_curr_dev; extern int usb_stor_curr_dev;
extern uint32_t usb_1st_disk_drive; extern uint32_t usb_1st_disk_drive;
#define USB_DEBUG //#define USB_DEBUG
#ifdef USB_DEBUG #ifdef USB_DEBUG
#define debug_printf(fmt, args...) xprintf(fmt , ##args) #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; asynch_allowed = 1;
if (handle && (ent != NULL)) if (handle && (ent != NULL))
{ {
if (usb_mem_init()) if (driver_mem_init())
{ {
usb_started = 0; usb_started = 0;
return -1; /* out of memoy */ return -1; /* out of memoy */
} }
if (usb_dev == NULL) 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) if (usb_dev == NULL)
{ {
usb_started = 0; 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 /* if lowlevel init is OK, scan the bus for devices
* i.e. search HUBs and configure them */ * i.e. search HUBs and configure them */
if (setup_packet == NULL) 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) if (setup_packet == NULL)
{ {
usb_started = 0; usb_started = 0;
@@ -207,7 +207,7 @@ int usb_stop(void)
asynch_allowed = 1; asynch_allowed = 1;
usb_started = 0; usb_started = 0;
usb_hub_reset(bus_index); usb_hub_reset(bus_index);
usb_free(setup_packet); driver_mem_free(setup_packet);
for (i = 0; i < USB_MAX_BUS; i++) for (i = 0; i < USB_MAX_BUS; i++)
{ {
struct hci *priv = controller_priv[i]; struct hci *priv = controller_priv[i];
@@ -234,7 +234,7 @@ int usb_stop(void)
} }
} }
bus_index = 0; bus_index = 0;
usb_mem_stop(); driver_mem_stop();
} }
return res; 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) if (size <= 0 || !buf || !index)
return -1; return -1;
buf[0] = 0; buf[0] = 0;
tbuf = (unsigned char *)usb_malloc(USB_BUFSIZ); tbuf = (unsigned char *)driver_mem_alloc(USB_BUFSIZ);
if (tbuf == NULL) if (tbuf == NULL)
{ {
debug_printf("usb_string: malloc failure\r\n"); 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) if (err < 0)
{ {
debug_printf("error getting string descriptor 0 (error=%lx)\r\n", dev->status); debug_printf("error getting string descriptor 0 (error=%lx)\r\n", dev->status);
usb_free(tbuf); driver_mem_free(tbuf);
return -1; return -1;
} }
else if (tbuf[0] < 4) else if (tbuf[0] < 4)
{ {
debug_printf("string descriptor 0 too short\r\n"); debug_printf("string descriptor 0 too short\r\n");
usb_free(tbuf); driver_mem_free(tbuf);
return -1; return -1;
} }
else 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); err = usb_string_sub(dev, dev->string_langid, index, tbuf);
if (err < 0) if (err < 0)
{ {
usb_free(tbuf); driver_mem_free(tbuf);
return err; return err;
} }
size--; /* leave room for trailing NULL char in output buffer */ 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; buf[idx] = 0;
err = idx; err = idx;
usb_free(tbuf); driver_mem_free(tbuf);
return err; return err;
} }
@@ -926,7 +926,7 @@ int usb_new_device(struct usb_device *dev)
addr = dev->devnum; addr = dev->devnum;
dev->devnum = 0; dev->devnum = 0;
tmpbuf = (unsigned char *) usb_malloc(USB_BUFSIZ); tmpbuf = (unsigned char *) driver_mem_alloc(USB_BUFSIZ);
if (tmpbuf == NULL) if (tmpbuf == NULL)
{ {
debug_printf("usb_new_device: malloc failure\r\n"); debug_printf("usb_new_device: malloc failure\r\n");
@@ -947,7 +947,7 @@ int usb_new_device(struct usb_device *dev)
if (err < 8) if (err < 8)
{ {
debug_printf("\r\nUSB device not responding, giving up (status=%lX)\r\n", dev->status); debug_printf("\r\nUSB device not responding, giving up (status=%lX)\r\n", dev->status);
usb_free(tmpbuf); driver_mem_free(tmpbuf);
return 1; return 1;
} }
#else #else
@@ -972,7 +972,7 @@ int usb_new_device(struct usb_device *dev)
if (err < 0) if (err < 0)
{ {
debug_printf("usb_new_device: usb_get_descriptor() failed\r\n"); debug_printf("usb_new_device: usb_get_descriptor() failed\r\n");
usb_free(tmpbuf); driver_mem_free(tmpbuf);
return 1; return 1;
} }
dev->descriptor.bMaxPacketSize0 = desc->bMaxPacketSize0; dev->descriptor.bMaxPacketSize0 = desc->bMaxPacketSize0;
@@ -992,7 +992,7 @@ int usb_new_device(struct usb_device *dev)
if (port < 0) if (port < 0)
{ {
debug_printf("usb_new_device: cannot locate device's port.\r\n"); debug_printf("usb_new_device: cannot locate device's port.\r\n");
usb_free(tmpbuf); driver_mem_free(tmpbuf);
return 1; return 1;
} }
/* reset the port for the second time */ /* reset the port for the second time */
@@ -1000,7 +1000,7 @@ int usb_new_device(struct usb_device *dev)
if (err < 0) if (err < 0)
{ {
debug_printf("\r\nCouldn't reset port %d\r\n", port); debug_printf("\r\nCouldn't reset port %d\r\n", port);
usb_free(tmpbuf); driver_mem_free(tmpbuf);
return 1; return 1;
} }
} }
@@ -1019,7 +1019,7 @@ int usb_new_device(struct usb_device *dev)
if (err < 0) if (err < 0)
{ {
debug_printf("\r\nUSB device not accepting new address (error=%lX)\r\n", dev->status); debug_printf("\r\nUSB device not accepting new address (error=%lX)\r\n", dev->status);
usb_free(tmpbuf); driver_mem_free(tmpbuf);
return 1; return 1;
} }
wait(10 * 1000); /* Let the SET_ADDRESS settle */ 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); debug_printf("unable to get device descriptor (error=%d)\r\n", err);
else else
debug_printf("USB device descriptor short read (expected %i, got %i)\r\n", tmp, err); debug_printf("USB device descriptor short read (expected %i, got %i)\r\n", tmp, err);
usb_free(tmpbuf); driver_mem_free(tmpbuf);
return 1; return 1;
} }
/* correct le values */ /* correct le values */
@@ -1047,7 +1047,7 @@ int usb_new_device(struct usb_device *dev)
if (usb_set_configuration(dev, dev->config.bConfigurationValue)) 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); 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; return -1;
} }
debug_printf("new device strings: Mfr=%d, Product=%d, SerialNumber=%d\r\n", 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); debug_printf("SerialNumber %s\r\n", dev->serial);
/* now prode if the device is a hub */ /* now prode if the device is a hub */
usb_hub_probe(dev, 0); usb_hub_probe(dev, 0);
usb_free(tmpbuf); driver_mem_free(tmpbuf);
return 0; return 0;
} }
@@ -1117,7 +1117,7 @@ void usb_scan_devices(void *priv)
* Probes device for being a hub and configurate it * Probes device for being a hub and configurate it
*/ */
#define USB_HUB_DEBUG //#define USB_HUB_DEBUG
#ifdef USB_HUB_DEBUG #ifdef USB_HUB_DEBUG
#define dbg_hub(fmt, args...) xprintf(fmt , ##args) #define dbg_hub(fmt, args...) xprintf(fmt , ##args)
@@ -1462,7 +1462,7 @@ int usb_hub_configure(struct usb_device *dev)
if (hub == NULL) if (hub == NULL)
return -1; return -1;
hub->pusb_dev = dev; hub->pusb_dev = dev;
buffer = (unsigned char *)usb_malloc(USB_BUFSIZ); buffer = (unsigned char *)driver_mem_alloc(USB_BUFSIZ);
if (buffer == NULL) if (buffer == NULL)
{ {
dbg_hub("usb_hub_configure: malloc failure\r\n"); 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) 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); 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; return -1;
} }
dbg_hub("bLength:%02X bDescriptorType:%02X bNbrPorts:%02X\r\n", buffer[0], buffer[1], buffer[2]); 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) if (i > USB_BUFSIZ)
{ {
dbg_hub("usb_hub_configure: failed to get hub descriptor - too long: %d\r\n", descriptor->bLength); 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; return -1;
} }
if (usb_get_hub_descriptor(dev, buffer, descriptor->bLength) < 0) 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); 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; return -1;
} }
memcpy((unsigned char *)&hub->desc, buffer, descriptor->bLength); 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) if (sizeof(struct usb_hub_status) > USB_BUFSIZ)
{ {
dbg_hub("usb_hub_configure: failed to get Status - too long: %d\r\n", descriptor->bLength); 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; return -1;
} }
if (usb_get_hub_status(dev, buffer) < 0) if (usb_get_hub_status(dev, buffer) < 0)
{ {
dbg_hub("usb_hub_configure: failed to get Status %lX\r\n", dev->status); dbg_hub("usb_hub_configure: failed to get Status %lX\r\n", dev->status);
usb_free(buffer); driver_mem_free(buffer);
return -1; return -1;
} }
@@ -1583,7 +1583,7 @@ int usb_hub_configure(struct usb_device *dev)
if (queue_poll_hub == NULL) if (queue_poll_hub == NULL)
#endif #endif
usb_hub_events(dev); usb_hub_events(dev);
usb_free(buffer); driver_mem_free(buffer);
return 0; return 0;
} }

View File

@@ -1,5 +1,5 @@
/* /*
* usb_mem.c * driver_mem.c
* *
* based from Emutos / BDOS * based from Emutos / BDOS
* *
@@ -30,18 +30,18 @@
#define TRUE 1 #define TRUE 1
#endif #endif
#undef USB_MEM_DEBUG #undef DRIVER_MEM_DEBUG
#ifdef USB_MEM_DEBUG #ifdef DRIVER_MEM_DEBUG
#define USB_MEM_PRINTF(fmt, args...) xprintf(fmt, ##args) #define dbg(fmt, args...) xprintf(fmt, ##args)
#else #else
#define USB_MEM_PRINTF(fmt, args...) #define dbg(fmt, args...)
#endif #endif
extern void *info_fvdi; extern void *info_fvdi;
extern long offscren_reserved(void); 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 */ /* MD - Memory Descriptor */
@@ -74,7 +74,8 @@ static MPB pmd;
static void *xmgetblk(void) static void *xmgetblk(void)
{ {
int i; int i;
for(i = 0; i < MAXMD; i++)
for (i = 0; i < MAXMD; i++)
{ {
if (tab_md[i].m_own == NULL) if (tab_md[i].m_own == NULL)
{ {
@@ -82,14 +83,16 @@ static void *xmgetblk(void)
return(&tab_md[i]); return(&tab_md[i]);
} }
} }
return(NULL); return NULL;
} }
static void xmfreblk(void *m) 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)) if ((i > 0) && (i < MAXMD))
{
tab_md[i].m_own = NULL; tab_md[i].m_own = NULL;
}
} }
static MD *ffit(long amount, MPB *mp) 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 */ MD *p, *q, *p1; /* free list is composed of MD's */
int maxflg; int maxflg;
long maxval; long maxval;
if (amount != -1) if (amount != -1)
{ {
amount += 15; /* 16 bytes alignment */ amount += 15; /* 16 bytes alignment */
amount &= 0xFFFFFFF0; amount &= 0xFFFFFFF0;
} }
if ((q = mp->mp_rover) == 0) /* get rotating pointer */ if ((q = mp->mp_rover) == 0) /* get rotating pointer */
return(0) ; {
return 0;
}
maxval = 0; maxval = 0;
maxflg = ((amount == -1) ? TRUE : FALSE) ; maxflg = ((amount == -1) ? TRUE : FALSE) ;
p = q->m_link; /* start with next MD */ p = q->m_link; /* start with next MD */
@@ -119,14 +127,21 @@ static MD *ffit(long amount, MPB *mp)
{ {
/* big enough */ /* big enough */
if (p->m_length == amount) if (p->m_length == amount)
{
q->m_link = p->m_link; /* take the whole thing */ q->m_link = p->m_link; /* take the whole thing */
}
else 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(); p1 = xmgetblk();
if (p1 == NULL) if (p1 == NULL)
{
return(NULL); return(NULL);
}
/* init new MD */ /* init new MD */
p1->m_length = p->m_length - amount; p1->m_length = p->m_length - amount;
p1->m_start = p->m_start + amount; p1->m_start = p->m_start + amount;
@@ -144,101 +159,146 @@ static MD *ffit(long amount, MPB *mp)
else if (p->m_length > maxval) else if (p->m_length > maxval)
maxval = p->m_length; maxval = p->m_length;
p = ( q=p )->m_link; p = ( q=p )->m_link;
} } while(q != mp->mp_rover);
while(q != mp->mp_rover);
/* return either the max, or 0 (error) */ /*
* return either the max, or 0 (error)
*/
if (maxflg) if (maxflg)
{ {
maxval -= 15; /* 16 bytes alignment */ maxval -= 15; /* 16 bytes alignment */
if (maxval < 0) if (maxval < 0)
{
maxval = 0; maxval = 0;
}
else else
{
maxval &= 0xFFFFFFF0; maxval &= 0xFFFFFFF0;
} }
}
return(maxflg ? (MD *) maxval : 0); return(maxflg ? (MD *) maxval : 0);
} }
static void freeit(MD *m, MPB *mp) static void freeit(MD *m, MPB *mp)
{ {
MD *p, *q; MD *p, *q;
q = 0; 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) if (m->m_start <= p->m_start)
{
break; break;
} }
}
m->m_link = p; m->m_link = p;
if (q) if (q)
{
q->m_link = m; q->m_link = m;
}
else else
{
mp->mp_mfl = m; mp->mp_mfl = m;
}
if (!mp->mp_rover) if (!mp->mp_rover)
{
mp->mp_rover = m; mp->mp_rover = m;
}
if (p) if (p)
{ {
if (m->m_start + m->m_length == p->m_start) 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_length += p->m_length;
m->m_link = p->m_link; m->m_link = p->m_link;
if (p == mp->mp_rover) if (p == mp->mp_rover)
{
mp->mp_rover = m; mp->mp_rover = m;
}
xmfreblk(p); xmfreblk(p);
} }
} }
if (q) if (q)
{ {
if (q->m_start + q->m_length == m->m_start) 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_length += m->m_length;
q->m_link = m->m_link; q->m_link = m->m_link;
if (m == mp->mp_rover) if (m == mp->mp_rover)
{
mp->mp_rover = q; mp->mp_rover = q;
}
xmfreblk(m); xmfreblk(m);
} }
} }
} }
int usb_free(void *addr) int driver_mem_free(void *addr)
{ {
int level; int level;
MD *p, **q; MD *p, **q;
MPB *mpb; MPB *mpb;
mpb = &pmd; mpb = &pmd;
level = set_ipl(7); level = set_ipl(7);
for(p = *(q = &mpb->mp_mal); p; p = *(q = &p->m_link)) 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; break;
} }
}
if (!p) if (!p)
{ {
set_ipl(level); set_ipl(level);
return(-1); return(-1);
} }
*q = p->m_link; *q = p->m_link;
freeit(p, mpb); freeit(p, mpb);
set_ipl(level); set_ipl(level);
USB_MEM_PRINTF("usb_free(0x%08X)\r\n", addr);
dbg("driver_mem_free(0x%08X)\r\n", addr);
return(0); return(0);
} }
void *usb_malloc(long amount) void *driver_mem_alloc(long amount)
{ {
void *ret = NULL; void *ret = NULL;
int level; int level;
MD *m; MD *m;
if (amount == -1L) if (amount == -1L)
{
return((void *)ffit(-1L, &pmd)); return((void *)ffit(-1L, &pmd));
}
if (amount <= 0 ) if (amount <= 0 )
{
return(0); return(0);
}
if ((amount & 1)) if ((amount & 1))
{
amount++; amount++;
}
level = set_ipl(7); level = set_ipl(7);
m = ffit(amount, &pmd); m = ffit(amount, &pmd);
if (m != NULL) if (m != NULL)
{
ret = (void *)m->m_start; ret = (void *)m->m_start;
}
set_ipl(level); 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); return(ret);
} }
@@ -247,21 +307,25 @@ void *usb_malloc(long amount)
int usb_mem_init(void) int usb_mem_init(void)
{ {
#ifdef USE_RADEON_MEMORY #ifdef USE_RADEON_MEMORY
usb_buffer = (void *)offscren_reserved(); driver_mem_buffer = (void *) offscren_reserved();
if (usb_buffer == NULL) if (driver_mem_buffer == NULL)
#endif #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); return(-1);
}
pmd.mp_mfl = pmd.mp_rover = &tab_md[0]; pmd.mp_mfl = pmd.mp_rover = &tab_md[0];
tab_md[0].m_link = (MD *)NULL; tab_md[0].m_link = (MD *) NULL;
tab_md[0].m_start = ((long)usb_buffer + 15) & ~15; tab_md[0].m_start = ((long) driver_mem_buffer + 15) & ~15;
tab_md[0].m_length = USB_BUFFER_SIZE; tab_md[0].m_length = DRIVER_MEM_BUFFER_SIZE;
tab_md[0].m_own = (void *)1L; tab_md[0].m_own = (void *) 1L;
pmd.mp_mal = (MD *)NULL; pmd.mp_mal = (MD *) NULL;
memset(usb_buffer, 0, tab_md[0].m_length); memset(driver_mem_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); dbg("driver memory buffer at 0x%08X size %d\r\n", tab_md[0].m_start, tab_md[0].m_length);
return(0); return(0);
} }
@@ -269,7 +333,7 @@ void usb_mem_stop(void)
{ {
#ifndef CONFIG_USB_MEM_NO_CACHE #ifndef CONFIG_USB_MEM_NO_CACHE
#ifdef USE_RADEON_MEMORY #ifdef USE_RADEON_MEMORY
if (usb_buffer == (void *)offscren_reserved()) if (driver_mem_buffer == (void *) offscren_reserved())
return; return;
#endif #endif
#endif #endif

View File

@@ -24,6 +24,7 @@
#include "bas_printf.h" #include "bas_printf.h"
#include "usb.h" #include "usb.h"
#include "exceptions.h" #include "exceptions.h"
#include "driver_mem.h"
#undef USB_MOUSE_DEBUG #undef USB_MOUSE_DEBUG
#ifdef USB_MOUSE_DEBUG #ifdef USB_MOUSE_DEBUG
@@ -49,7 +50,7 @@ int usb_mouse_deregister(struct usb_device *dev)
dev->irq_handle = NULL; dev->irq_handle = NULL;
if(new != NULL) if(new != NULL)
{ {
usb_free(new); driver_mem_free(new);
new = NULL; new = NULL;
} }
mouse_installed = 0; mouse_installed = 0;
@@ -83,9 +84,9 @@ int drv_usb_mouse_init(void)
for(i = 0; i < USB_MAX_DEVICE; i++) for(i = 0; i < USB_MAX_DEVICE; i++)
{ {
struct usb_device *dev = usb_get_dev_index(i, j); /* get device */ struct usb_device *dev = usb_get_dev_index(i, j); /* get device */
if(dev == NULL) if (dev == NULL)
break; break;
if(usb_mouse_register(dev) > 0) if (usb_mouse_register(dev) > 0)
return 1; return 1;
} }
} }
@@ -212,7 +213,7 @@ static int usb_mouse_probe(struct usb_device *dev, unsigned int ifnum)
return 0; return 0;
if((ep->bmAttributes & 3) != 3) if((ep->bmAttributes & 3) != 3)
return 0; return 0;
new = (unsigned char *)usb_malloc(8); new = (unsigned char *)driver_mem_alloc(8);
if(new == NULL) if(new == NULL)
return 0; return 0;
mse_printf("USB MOUSE found set protocol...\r\n"); mse_printf("USB MOUSE found set protocol...\r\n");