Commits

Anonymous committed cbd29ee

*Updated all DEV9 and ATAD module code.

Comments (0)

Files changed (5)

modules/dev9/imports.lst

 
 dmacman_IMPORTS_start
-I_dmac_set_dpcr2
-I_dmac_get_dpcr2
+I_dmac_enable
+I_dmac_transfer
+I_dmac_request
+I_dmac_ch_get_chcr
 dmacman_IMPORTS_end
 
 intrman_IMPORTS_start

modules/dev9/ps2dev9.c

 # Licenced under Academic Free License version 2.0
 # Review ps2sdk README & LICENSE files for further details.
 #
-# $Id: ps2dev9.c 1454 2007-11-04 23:19:57Z roman_ps2dev $
+# $Id$
 # DEV9 Device Driver.
 */
 
-#include "types.h"
-#include "defs.h"
-#include "loadcore.h"
-#include "intrman.h"
-#include "dmacman.h"
-#include "thbase.h"
-#include "thsemap.h"
+#include <types.h>
+#include <defs.h>
+#include <loadcore.h>
+#include <intrman.h>
+#include <dmacman.h>
+#include <thbase.h>
+#include <thsemap.h>
 #ifdef DEBUG
-#include "stdio.h"
+#include <stdio.h>
 #endif
-#include "dev9.h"
+#include <dev9.h>
 #ifdef POWEROFF
-#include "poweroff.h"
+#include <poweroff.h>
 #endif
 #ifdef DEV9X_DEV
-#include "ioman.h"
+#include <ioman.h>
 #include "ioman_add.h"
 #endif
 
-#include "dev9regs.h"
-#include "speedregs.h"
-#include "smapregs.h"
+#include <dev9regs.h>
+#include <speedregs.h>
+#include <smapregs.h>
 
 #define MODNAME "dev9_driver"
 #define DRIVERNAME "dev9"
 #define VERSION "1.0"
 #define BANNER "\nDEV9 device driver v%s - Copyright (c) 2003 Marcus R. Brown\n\n"
 
-#define DEV9_INTR		13
-
 /* SSBUS registers.  */
 #define SSBUS_R_1418		0xbf801418
 #define SSBUS_R_141c		0xbf80141c
 
 static void (*p_dev9_intr_cb)(int flag) = NULL;
 static int dma_lock_sem = -1;	/* used to arbitrate DMA */
-static int dma_complete_sem = -1; /* signalled on DMA transfer completion.  */
 
 #ifdef PCMCIA
 static int pcic_cardtype;	/* Translated value of bits 0-1 of 0xbf801462 */
 static dev9_dma_cb_t dev9_predma_cbs[4], dev9_postdma_cbs[4];
 
 static int dev9_intr_dispatch(int flag);
-static int dev9_dma_intr(void *arg);
 
 #ifdef POWEROFF
 static void dev9x_on_shutdown(void*);
 	return 0;
 }
 
-/* Signal the end of a DMA transfer.  */
-static int dev9_dma_intr(void *arg)
-{
-	int sem = *(int *)arg;
-
-	iSignalSema(sem);
-	return 1;
-}
-
 static void smap_set_stat(int stat)
 {
 	if (dev9type == 0)
 }
 
 /* Export 5 */
-/* This differs from the "official" dev9 in that it puts the calling thread to
-   sleep when doing the actual DMA transfer.  I'm not sure why SCEI didn't do
-   this in dev9.irx, when they do it in PS2Linux's dmarelay.irx.  Anyway,
-   since this no longer blocks, it should speed up anything else on the IOP
-   when HDD or SMAP are doing DMA.  */
 int dev9DmaTransfer(int ctrl, void *buf, int bcr, int dir)
 {
 	USE_SPD_REGS;
-	volatile iop_dmac_chan_t *dev9_chan = (iop_dmac_chan_t *)DEV9_DMAC_BASE;
-	int stat, res = 0, dmactrl;
+	int res = 0, dmactrl;
 
 	switch(ctrl){
 	case 0:
 	if ((res = WaitSema(dma_lock_sem)) < 0)
 		return res;
 
-	if (SPD_REG16(SPD_R_REV_1) < 17)
-		dmactrl = (dmactrl & 0x03) | 0x04;
-	else
-		dmactrl = (dmactrl & 0x01) | 0x06;
-	SPD_REG16(SPD_R_DMA_CTRL) = dmactrl;
+	SPD_REG16(SPD_R_DMA_CTRL) = (SPD_REG16(SPD_R_REV_1)<17)?(dmactrl&0x03)|0x04:(dmactrl&0x01)|0x06;
 
 	if (dev9_predma_cbs[ctrl])
 		dev9_predma_cbs[ctrl](bcr, dir);
 
-	EnableIntr(IOP_IRQ_DMA_DEV9);
-	dev9_chan->madr = (u32)buf;
-	dev9_chan->bcr  = bcr;
-	dev9_chan->chcr = DMAC_CHCR_30|DMAC_CHCR_TR|DMAC_CHCR_CO|
-		(dir & DMAC_CHCR_DR);
+	dmac_request(IOP_DMAC_8, buf, bcr&0xFFFF, bcr>>16, dir);
+	dmac_transfer(IOP_DMAC_8);
 
-	/* Wait for DMA to complete.  */
-	if ((res = WaitSema(dma_complete_sem)) >= 0)
-		res = 0;
-
-	DisableIntr(IOP_IRQ_DMA_DEV9, &stat);
+	/* Wait for DMA to complete. Do not use a semaphore as thread switching hurts throughput greatly.  */
+	while(dmac_ch_get_chcr(IOP_DMAC_8)&DMAC_CHCR_TR){}
+	res = 0;
 
 	if (dev9_postdma_cbs[ctrl])
 		dev9_postdma_cbs[ctrl](bcr, dir);
 
 static int smap_subsys_init(void)
 {
-	int i, stat, flags;
+	int i;
 
 	if ((dma_lock_sem = CreateMutex(IOP_MUTEX_UNLOCKED)) < 0)
 		return -1;
-	if ((dma_complete_sem = CreateMutex(IOP_MUTEX_LOCKED)) < 0)
-		return -1;
 
-	DisableIntr(IOP_IRQ_DMA_DEV9, &stat);
-	CpuSuspendIntr(&flags);
 	/* Enable the DEV9 DMAC channel.  */
-	RegisterIntrHandler(IOP_IRQ_DMA_DEV9, 1, dev9_dma_intr, &dma_complete_sem);
-	dmac_set_dpcr2(dmac_get_dpcr2() | 0x80);
-	CpuResumeIntr(flags);
+	dmac_enable(IOP_DMAC_8);
 
 	/* Not quite sure what this enables yet.  */
 	smap_set_stat(0x103);
 {
 	USE_DEV9_REGS;
 	int *mode;
-	int flags;
 	u16 cstc1, cstc2;
 
 	_sw(0x51011, SSBUS_R_1420);
 	if (smap_subsys_init() != 0)
 		return 1;
 
-	CpuSuspendIntr(&flags);
-	RegisterIntrHandler(DEV9_INTR, 1, pcmcia_intr, NULL);
-	EnableIntr(DEV9_INTR);
-	CpuResumeIntr(flags);
+	RegisterIntrHandler(IOP_IRQ_DEV9, 1, pcmcia_intr, NULL);
+	EnableIntr(IOP_IRQ_DEV9);
 
 	DEV9_REG(DEV9_R_147E) = 0;
 	M_PRINTF("CXD9566 (PCMCIA type) initialized.\n");
 static int expbay_init(void)
 {
 	USE_DEV9_REGS;
-	int flags;
 
 	_sw(0x51011, SSBUS_R_1420);
 	_sw(0xe01a3043, SSBUS_R_1418);
 	if (smap_subsys_init() != 0)
 		return 1;
 
-	CpuSuspendIntr(&flags);
-	RegisterIntrHandler(DEV9_INTR, 1, expbay_intr, NULL);
-	EnableIntr(DEV9_INTR);
-	CpuResumeIntr(flags);
+	RegisterIntrHandler(IOP_IRQ_DEV9, 1, expbay_intr, NULL);
+	EnableIntr(IOP_IRQ_DEV9);
 
 	DEV9_REG(DEV9_R_1466) = 0;
 	M_PRINTF("CXD9611 (Expansion Bay type) initialized.\n");

modules/iopcore/cdvdman/atad.c

 #include <thevent.h>
 #include <stdio.h>
 #include <sysclib.h>
-#include "dev9.h"
-#include "atad.h"
+#include <dev9.h>
+#include <atad.h>
 
 #include <speedregs.h>
 #include <atahw.h>
 
 static void ata_dma_set_dir(int dir);
 
+static void AtadPreDmaCb(int bcr, int dir){
+	USE_SPD_REGS;
+
+	SPD_REG16(SPD_R_XFR_CTRL)|=0x80;
+}
+
+static void AtadPostDmaCb(int bcr, int dir){
+	USE_SPD_REGS;
+
+	SPD_REG16(SPD_R_XFR_CTRL)&=~0x80;
+}
+
 int atad_start(void)
 {
+#ifdef DEV9_DEBUG
 	USE_SPD_REGS;
+#endif
 	iop_event_t event;
 	int res = 1;
 
 	M_PRINTF(BANNER, VERSION);
 
+#ifdef DEV9_DEBUG
 	if (!(SPD_REG16(SPD_R_REV_3) & SPD_CAPS_ATA) || !(SPD_REG16(SPD_R_REV_8) & 0x02)) {
 		M_PRINTF("HDD is not connected, exiting.\n");
 		goto out;
 	}
+#endif
 
 	event.attr = 0;
 	event.bits = 0;
-	if ((ata_evflg = CreateEventFlag(&event)) < 0) {
+	ata_evflg = CreateEventFlag(&event);
+#ifdef DEV9_DEBUG
+	if (ata_evflg < 0) {
 		M_PRINTF("Couldn't create event flag, exiting.\n");
 		res = 1;
 		goto out;
 	}
+#endif
 
 	dev9RegisterIntrCb(1, ata_intr_cb);
 	dev9RegisterIntrCb(0, ata_intr_cb);
+	dev9RegisterPreDmaCb(0, &AtadPreDmaCb);
+	dev9RegisterPostDmaCb(0, &AtadPostDmaCb);
 
 #ifdef VMC_DRIVER
 	iop_sema_t smp;
 
 	res = 0;
 	M_PRINTF("Driver loaded.\n");
+#ifdef DEV9_DEBUG
 out:
+#endif
 	return res;
 }
 
 }
 
 /* Export 6 */
-int ata_io_start(void *buf, u32 blkcount, u16 feature, u16 nsector, u16 sector,
-		u16 lcyl, u16 hcyl, u16 select, u16 command)
+int ata_io_start(void *buf, unsigned int blkcount, unsigned short int feature, unsigned short int nsector, unsigned short int sector, unsigned short int lcyl, unsigned short int hcyl, unsigned short int select, unsigned short int command)
 {
 	USE_ATA_REGS;
-	USE_SPD_REGS;
 	iop_sys_clock_t cmd_timeout;
 	ata_cmd_info_t *cmd_table;
 	int i, res, type, cmd_table_size;
 	ata_hwport->r_command = command & 0xff;
 
 	/* Turn on the LED.  */
-	SPD_REG8(SPD_R_PIO_DIR) = 1;
-	SPD_REG8(SPD_R_PIO_DATA) = 0;
+	dev9LEDCtl(1);
 
 	return 0;
 }
 	/* The command has completed (with an error or not), so clean things up.  */
 	CancelAlarm((void *)ata_alarm_cb, NULL);
 	/* Turn off the LED.  */
-	SPD_REG8(SPD_R_PIO_DIR) = 1;
-	SPD_REG8(SPD_R_PIO_DATA) = 1;
+	dev9LEDCtl(0);
 
 	return res;
 }
 
 /* Export 9 */
-int ata_device_dma_transfer(int device, void *buf, u32 lba, u32 nsectors, int dir)
+int ata_device_dma_transfer(int device, void *buf, unsigned int lba, unsigned int nsectors, int dir)
 {
 	int res = 0;
 	u32 nbytes;
 	val = SPD_REG16(SPD_R_IF_CTRL) & 1;
 	val |= (dir == 1) ? 0x4c : 0x4e;
 	SPD_REG16(SPD_R_IF_CTRL) = val;
-	SPD_REG16(SPD_R_XFR_CTRL) = dir | 0x86;
+	SPD_REG16(SPD_R_XFR_CTRL) = dir | 0x6;
 }

modules/iopcore/cdvdman/dev9.c

 
 static void (*p_dev9_intr_cb)(int flag) = NULL;
 static int dma_lock_sem = -1;	/* used to arbitrate DMA */
-static int dma_complete_sem = -1; /* signalled on DMA transfer completion.  */
 
 #ifdef PCMCIA
 static int pcic_cardtype;	/* Translated value of bits 0-1 of 0xbf801462 */
 static dev9_dma_cb_t dev9_predma_cbs[4], dev9_postdma_cbs[4];
 
 static int dev9_intr_dispatch(int flag);
-static int dev9_dma_intr(void *arg);
 
 static void smap_set_stat(int stat);
 static int read_eeprom_data(void);
 	return 0;
 }
 
-/* Signal the end of a DMA transfer.  */
-static int dev9_dma_intr(void *arg)
-{
-	int sem = *(int *)arg;
-
-	iSignalSema(sem);
-	return 1;
-}
-
 static void smap_set_stat(int stat)
 {
 	if (dev9type == 0)
 int dev9DmaTransfer(int ctrl, void *buf, int bcr, int dir)
 {
 	USE_SPD_REGS;
-	volatile iop_dmac_chan_t *dev9_chan = (iop_dmac_chan_t *)DEV9_DMAC_BASE;
-	int stat, res = 0, dmactrl;
+	int res = 0, dmactrl;
 
 	switch(ctrl){
 	case 0:
 	if ((res = WaitSema(dma_lock_sem)) < 0)
 		return res;
 
-	if (SPD_REG16(SPD_R_REV_1) < 17)
-		dmactrl = (dmactrl & 0x03) | 0x04;
-	else
-		dmactrl = (dmactrl & 0x01) | 0x06;
-	SPD_REG16(SPD_R_DMA_CTRL) = dmactrl;
+	SPD_REG16(SPD_R_DMA_CTRL) = (SPD_REG16(SPD_R_REV_1)<17)?(dmactrl&0x03)|0x04:(dmactrl&0x01)|0x06;
 
 	if (dev9_predma_cbs[ctrl])
 		dev9_predma_cbs[ctrl](bcr, dir);
 
-	EnableIntr(IOP_IRQ_DMA_DEV9);
-	dev9_chan->madr = (u32)buf;
-	dev9_chan->bcr  = bcr;
-	dev9_chan->chcr = DMAC_CHCR_30|DMAC_CHCR_TR|DMAC_CHCR_CO|
-		(dir & DMAC_CHCR_DR);
+	dmac_request(IOP_DMAC_8, buf, bcr&0xFFFF, bcr>>16, dir);
+	dmac_transfer(IOP_DMAC_8);
 
-	/* Wait for DMA to complete.  */
-	if ((res = WaitSema(dma_complete_sem)) >= 0)
-		res = 0;
-
-	DisableIntr(IOP_IRQ_DMA_DEV9, &stat);
+	/* Wait for DMA to complete. Do not use a semaphore as thread switching hurts throughput greatly.  */
+	while(dmac_ch_get_chcr(IOP_DMAC_8)&DMAC_CHCR_TR){}
+	res=0;
 
 	if (dev9_postdma_cbs[ctrl])
 		dev9_postdma_cbs[ctrl](bcr, dir);
 
 static int smap_subsys_init(void)
 {
-	int i, stat, flags;
+	int i;
 
 	if ((dma_lock_sem = CreateMutex(IOP_MUTEX_UNLOCKED)) < 0)
 		return -1;
-	if ((dma_complete_sem = CreateMutex(IOP_MUTEX_LOCKED)) < 0)
-		return -1;
 
-	DisableIntr(IOP_IRQ_DMA_DEV9, &stat);
-	CpuSuspendIntr(&flags);
 	/* Enable the DEV9 DMAC channel.  */
-	ReleaseIntrHandler(IOP_IRQ_DMA_DEV9);
-	RegisterIntrHandler(IOP_IRQ_DMA_DEV9, 1, dev9_dma_intr, &dma_complete_sem);
-	dmac_set_dpcr2(dmac_get_dpcr2() | 0x80);
-	CpuResumeIntr(flags);
+	dmac_enable(IOP_DMAC_8);
 
 	/* Not quite sure what this enables yet.  */
 	smap_set_stat(0x103);
 {
 	USE_DEV9_REGS;
 	int *mode;
-	int flags;
 	u16 cstc1, cstc2;
 
 	_sw(0x51011, SSBUS_R_1420);
 	if (smap_subsys_init() != 0)
 		return 1;
 
-	CpuSuspendIntr(&flags);
-	RegisterIntrHandler(DEV9_INTR, 1, pcmcia_intr, NULL);
-	EnableIntr(DEV9_INTR);
-	CpuResumeIntr(flags);
+	RegisterIntrHandler(IOP_IRQ_DEV9, 1, pcmcia_intr, NULL);
+	EnableIntr(IOP_IRQ_DEV9);
 
 	DEV9_REG(DEV9_R_147E) = 0;
 	M_PRINTF("CXD9566 (PCMCIA type) initialized.\n");
 static int expbay_init(void)
 {
 	USE_DEV9_REGS;
-	int flags;
 
 	_sw(0x51011, SSBUS_R_1420);
 	_sw(0xe01a3043, SSBUS_R_1418);
 	if (smap_subsys_init() != 0)
 		return 1;
 
-	CpuSuspendIntr(&flags);
-	ReleaseIntrHandler(DEV9_INTR);
-	RegisterIntrHandler(DEV9_INTR, 1, expbay_intr, NULL);
-	EnableIntr(DEV9_INTR);
-	CpuResumeIntr(flags);
+	ReleaseIntrHandler(IOP_IRQ_DEV9);
+	RegisterIntrHandler(IOP_IRQ_DEV9, 1, expbay_intr, NULL);
+	EnableIntr(IOP_IRQ_DEV9);
 
 	DEV9_REG(DEV9_R_1466) = 0;
 	M_PRINTF("CXD9611 (Expansion Bay type) initialized.\n");

modules/iopcore/cdvdman/imports.lst

 stdio_IMPORTS_end
 
 dmacman_IMPORTS_start
-I_dmac_get_dpcr2
-I_dmac_set_dpcr2
+I_dmac_enable
+I_dmac_transfer
+I_dmac_request
+I_dmac_ch_get_chcr
 dmacman_IMPORTS_end
 
 intrman_IMPORTS_start