Skip to content

Commit

Permalink
use generic function for unsuported IOP device OPS.
Browse files Browse the repository at this point in the history
Co-authored-by: Matias Israelson <[email protected]>
  • Loading branch information
Wolf3s and israpps committed Dec 24, 2024
1 parent 0f736b9 commit 5c47ea0
Show file tree
Hide file tree
Showing 11 changed files with 192 additions and 218 deletions.
12 changes: 4 additions & 8 deletions modules/debug/ps2link/net_fsys.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,7 @@ static int fsys_pid = 0;
// static iop_device_t fsys_driver;

////////////////////////////////////////////////////////////////////////
static int dummy5()
{
printf("dummy function called\n");
return -5;
}
IOMAN_RETURN_VALUE_IMPL(5);

////////////////////////////////////////////////////////////////////////
static void fsysInit(iop_device_t *driver)
Expand Down Expand Up @@ -303,12 +299,12 @@ static int fsysDclose(int fd)
return ret;
}

iop_device_ops_t fsys_functarray = {(void *)fsysInit, (void *)fsysDestroy, (void *)dummy5,
iop_device_ops_t fsys_functarray = {(void *)fsysInit, (void *)fsysDestroy, IOMAN_RETURN_VALUE(5),
(void *)fsysOpen, (void *)fsysClose, (void *)fsysRead,
(void *)fsysWrite, (void *)fsysLseek, (void *)dummy5,
(void *)fsysWrite, (void *)fsysLseek, IOMAN_RETURN_VALUE(5),
(void *)fsysRemove, (void *)fsysMkdir, (void *)fsysRmdir,
(void *)fsysDopen, (void *)fsysDclose, (void *)fsysDread,
(void *)dummy5, (void *)dummy5};
IOMAN_RETURN_VALUE(5), IOMAN_RETURN_VALUE(5)};

iop_device_t fsys_driver = {fsname, 16, 1, "fsys driver",
&fsys_functarray};
Expand Down
32 changes: 14 additions & 18 deletions modules/debug/udptty-ingame/udptty.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,27 +41,28 @@ static int tty_init(iop_device_t *device);
static int tty_deinit(iop_device_t *device);
static int tty_stdout_fd(void);
static int tty_write(iop_file_t *file, void *buf, size_t size);
static int tty_error(void);

IOMAN_RETURN_VALUE_IMPL(EIO);

/* device ops */
static iop_device_ops_t tty_ops = {
tty_init,
tty_deinit,
(void *)tty_error,
IOMAN_RETURN_VALUE(EIO),
(void *)tty_stdout_fd,
(void *)tty_stdout_fd,
(void *)tty_error,
IOMAN_RETURN_VALUE(EIO),
(void *)tty_write,
(void *)tty_error,
(void *)tty_error,
(void *)tty_error,
(void *)tty_error,
(void *)tty_error,
(void *)tty_error,
(void *)tty_error,
(void *)tty_error,
(void *)tty_error,
(void *)tty_error};
IOMAN_RETURN_VALUE(EIO),
IOMAN_RETURN_VALUE(EIO),
IOMAN_RETURN_VALUE(EIO),
IOMAN_RETURN_VALUE(EIO),
IOMAN_RETURN_VALUE(EIO),
IOMAN_RETURN_VALUE(EIO),
IOMAN_RETURN_VALUE(EIO),
IOMAN_RETURN_VALUE(EIO),
IOMAN_RETURN_VALUE(EIO),
IOMAN_RETURN_VALUE(EIO)};

/* device descriptor */
static iop_device_t tty_device = {
Expand Down Expand Up @@ -266,8 +267,3 @@ static int tty_write(iop_file_t *file, void *buf, size_t size)

return res;
}

static int tty_error(void)
{
return -EIO;
}
49 changes: 23 additions & 26 deletions modules/hdd/xhdd/xhdd.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,7 @@ static int xhddInit(iop_device_t *device)
return 0;
}

static int xhddUnsupported(void)
{
return -1;
}
IOMANX_RETURN_VALUE_IMPL(1);

static int xhddDevctl(iop_file_t *fd, const char *name, int cmd, void *arg, unsigned int arglen, void *buf, unsigned int buflen)
{
Expand All @@ -45,28 +42,28 @@ static int xhddDevctl(iop_file_t *fd, const char *name, int cmd, void *arg, unsi

static iop_device_ops_t xhdd_ops = {
&xhddInit,
(void *)&xhddUnsupported,
(void *)&xhddUnsupported,
(void *)&xhddUnsupported,
(void *)&xhddUnsupported,
(void *)&xhddUnsupported,
(void *)&xhddUnsupported,
(void *)&xhddUnsupported,
(void *)&xhddUnsupported,
(void *)&xhddUnsupported,
(void *)&xhddUnsupported,
(void *)&xhddUnsupported,
(void *)&xhddUnsupported,
(void *)&xhddUnsupported,
(void *)&xhddUnsupported,
(void *)&xhddUnsupported,
(void *)&xhddUnsupported,
(void *)&xhddUnsupported,
(void *)&xhddUnsupported,
(void *)&xhddUnsupported,
(void *)&xhddUnsupported,
(void *)&xhddUnsupported,
(void *)&xhddUnsupported,
IOMANX_RETURN_VALUE(1),
IOMANX_RETURN_VALUE(1),
IOMANX_RETURN_VALUE(1),
IOMANX_RETURN_VALUE(1),
IOMANX_RETURN_VALUE(1),
IOMANX_RETURN_VALUE(1),
IOMANX_RETURN_VALUE(1),
IOMANX_RETURN_VALUE(1),
IOMANX_RETURN_VALUE(1),
IOMANX_RETURN_VALUE(1),
IOMANX_RETURN_VALUE(1),
IOMANX_RETURN_VALUE(1),
IOMANX_RETURN_VALUE(1),
IOMANX_RETURN_VALUE(1),
IOMANX_RETURN_VALUE(1),
IOMANX_RETURN_VALUE(1),
IOMANX_RETURN_VALUE(1),
IOMANX_RETURN_VALUE(1),
IOMANX_RETURN_VALUE(1),
IOMANX_RETURN_VALUE(1),
IOMANX_RETURN_VALUE(1),
IOMANX_RETURN_VALUE(1),
&xhddDevctl,
};

Expand Down
34 changes: 17 additions & 17 deletions modules/iopcore/cdvdman/atad.c
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ int sceAtaGetError(void)
#define ata_wait_bus_busy() gen_ata_wait_busy(ATA_WAIT_BUSBUSY)

/* 0x80 for busy, 0x88 for bus busy.
In the original ATAD, the busy and bus-busy functions were separate, but similar. */
In the original ATAD, the busy and bus-busy functions were separate, but similar. */
static int gen_ata_wait_busy(int bits)
{
USE_ATA_REGS;
Expand Down Expand Up @@ -261,20 +261,20 @@ static int ata_device_select(int device)
/* Select the device. */
ata_hwport->r_select = (device & 1) << 4;
(void)(ata_hwport->r_control);
(void)(ata_hwport->r_control); //Only done once in v1.04.
(void)(ata_hwport->r_control); // Only done once in v1.04.

return ata_wait_bus_busy();
}

/* Export 6 */
/*
28-bit LBA:
sector (7:0) -> LBA (7:0)
lcyl (7:0) -> LBA (15:8)
hcyl (7:0) -> LBA (23:16)
device (3:0) -> LBA (27:24)
28-bit LBA:
sector (7:0) -> LBA (7:0)
lcyl (7:0) -> LBA (15:8)
hcyl (7:0) -> LBA (23:16)
device (3:0) -> LBA (27:24)
48-bit LBA just involves writing the upper 24 bits in the format above into each respective register on the first write pass, before writing the lower 24 bits in the 2nd write pass. The LBA bits within the device field are not used in either write pass.
48-bit LBA just involves writing the upper 24 bits in the format above into each respective register on the first write pass, before writing the lower 24 bits in the 2nd write pass. The LBA bits within the device field are not used in either write pass.
*/
int sceAtaExecCmd(void *buf, u32 blkcount, u16 feature, u16 nsector, u16 sector, u16 lcyl, u16 hcyl, u16 select, u16 command)
{
Expand All @@ -291,7 +291,7 @@ int sceAtaExecCmd(void *buf, u32 blkcount, u16 feature, u16 nsector, u16 sector,
return res;

/* For the SCE and SMART commands, we need to search on the subcommand
specified in the feature register. */
specified in the feature register. */
if (command == ATA_C_SMART) {
cmd_table = smart_cmd_table;
cmd_table_size = SMART_CMD_TABLE_SIZE;
Expand All @@ -310,7 +310,7 @@ int sceAtaExecCmd(void *buf, u32 blkcount, u16 feature, u16 nsector, u16 sector,
}
}

if (!(atad_cmd_state.type = type & 0x7F)) //Non-SONY: ignore the 48-bit LBA flag.
if (!(atad_cmd_state.type = type & 0x7F)) // Non-SONY: ignore the 48-bit LBA flag.
return ATA_RES_ERR_CMD;

atad_cmd_state.buf = buf;
Expand All @@ -333,7 +333,7 @@ int sceAtaExecCmd(void *buf, u32 blkcount, u16 feature, u16 nsector, u16 sector,

/* Does this command need a timeout? */
using_timeout = 0;
switch (type & 0x7F) { //Non-SONY: ignore the 48-bit LBA flag.
switch (type & 0x7F) { // Non-SONY: ignore the 48-bit LBA flag.
case 1:
case 6:
using_timeout = 1;
Expand All @@ -359,11 +359,11 @@ int sceAtaExecCmd(void *buf, u32 blkcount, u16 feature, u16 nsector, u16 sector,
/* Finally! We send off the ATA command with arguments. */
ata_hwport->r_control = (using_timeout == 0) << 1;

if (type & 0x80) { //For the sake of achieving (greatly) improved performance, write the registers twice only if required! This is also required for compatibility with the buggy firmware of certain PSX units.
if (type & 0x80) { // For the sake of achieving (greatly) improved performance, write the registers twice only if required! This is also required for compatibility with the buggy firmware of certain PSX units.
/* 48-bit LBA requires writing to the address registers twice,
24 bits of the LBA address is written each time.
Writing to registers twice does not affect 28-bit LBA since
only the latest data stored in address registers is used. */
24 bits of the LBA address is written each time.
Writing to registers twice does not affect 28-bit LBA since
only the latest data stored in address registers is used. */
ata_hwport->r_feature = (feature >> 8) & 0xff;
ata_hwport->r_nsector = (nsector >> 8) & 0xff;
ata_hwport->r_sector = (sector >> 8) & 0xff;
Expand All @@ -376,7 +376,7 @@ int sceAtaExecCmd(void *buf, u32 blkcount, u16 feature, u16 nsector, u16 sector,
ata_hwport->r_sector = sector & 0xff;
ata_hwport->r_lcyl = lcyl & 0xff;
ata_hwport->r_hcyl = hcyl & 0xff;
ata_hwport->r_select = (select | ATA_SEL_LBA) & 0xff; //In v1.04, LBA was enabled in the sceAtaDmaTransfer function.
ata_hwport->r_select = (select | ATA_SEL_LBA) & 0xff; // In v1.04, LBA was enabled in the sceAtaDmaTransfer function.
ata_hwport->r_command = command & 0xff;

/* Turn on the LED. */
Expand Down Expand Up @@ -652,7 +652,7 @@ static void ata_set_dir(int dir)
val = SPD_REG16(SPD_R_IF_CTRL) & 1;
val |= (dir == ATA_DIR_WRITE) ? 0x4c : 0x4e;
SPD_REG16(SPD_R_IF_CTRL) = val;
SPD_REG16(SPD_R_XFR_CTRL) = dir | (ata_gamestar_workaround ? 0x86 : 0x6); //In v1.04, DMA was enabled here (0x86 instead of 0x6)
SPD_REG16(SPD_R_XFR_CTRL) = dir | (ata_gamestar_workaround ? 0x86 : 0x6); // In v1.04, DMA was enabled here (0x86 instead of 0x6)
}

static int ata_device_standby_immediate(int device)
Expand Down
63 changes: 32 additions & 31 deletions modules/iopcore/cdvdman/dev9.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ static void (*p_dev9_intr_cb)(int flag) = NULL;
static int dma_lock_sem = -1; /* used to arbitrate DMA */

static s16 eeprom_data[5]; /* 2-byte EEPROM status (0/-1 = invalid, 1 = valid),
6-byte MAC address,
2-byte MAC address checksum. */
6-byte MAC address,
2-byte MAC address checksum. */

/* Each driver can register callbacks that correspond to each bit of the
SMAP interrupt status register (0xbx000028). */
Expand All @@ -81,15 +81,16 @@ static int pcmcia_init(void);
static void expbay_set_stat(int stat);
static int expbay_init(void);

static int dev9x_dummy(void) { return 0; }
IOMANX_RETURN_VALUE_IMPL(0);

static int dev9x_devctl(iop_file_t *f, const char *name, int cmd, void *args, int arglen, void *buf, int buflen)
{
switch (cmd) {
case DDIOC_MODEL:
return dev9type;
case DDIOC_OFF:
//Do not let the DEV9 interface to be switched off by other software.
//Dev9CardStop();
// Do not let the DEV9 interface to be switched off by other software.
// Dev9CardStop();
return 0;
default:
return 0;
Expand All @@ -98,29 +99,29 @@ static int dev9x_devctl(iop_file_t *f, const char *name, int cmd, void *args, in

/* driver ops func tab */
static iop_device_ops_t dev9x_ops = {
(void *)dev9x_dummy,
(void *)dev9x_dummy,
(void *)dev9x_dummy,
(void *)dev9x_dummy,
(void *)dev9x_dummy,
(void *)dev9x_dummy,
(void *)dev9x_dummy,
(void *)dev9x_dummy,
(void *)dev9x_dummy,
(void *)dev9x_dummy,
(void *)dev9x_dummy,
(void *)dev9x_dummy,
(void *)dev9x_dummy,
(void *)dev9x_dummy,
(void *)dev9x_dummy,
(void *)dev9x_dummy,
(void *)dev9x_dummy,
(void *)dev9x_dummy,
(void *)dev9x_dummy,
(void *)dev9x_dummy,
(void *)dev9x_dummy,
(void *)dev9x_dummy,
(void *)dev9x_dummy,
IOMANX_RETURN_VALUE(0),
IOMANX_RETURN_VALUE(0),
IOMANX_RETURN_VALUE(0),
IOMANX_RETURN_VALUE(0),
IOMANX_RETURN_VALUE(0),
IOMANX_RETURN_VALUE(0),
IOMANX_RETURN_VALUE(0),
IOMANX_RETURN_VALUE(0),
IOMANX_RETURN_VALUE(0),
IOMANX_RETURN_VALUE(0),
IOMANX_RETURN_VALUE(0),
IOMANX_RETURN_VALUE(0),
IOMANX_RETURN_VALUE(0),
IOMANX_RETURN_VALUE(0),
IOMANX_RETURN_VALUE(0),
IOMANX_RETURN_VALUE(0),
IOMANX_RETURN_VALUE(0),
IOMANX_RETURN_VALUE(0),
IOMANX_RETURN_VALUE(0),
IOMANX_RETURN_VALUE(0),
IOMANX_RETURN_VALUE(0),
IOMANX_RETURN_VALUE(0),
IOMANX_RETURN_VALUE(0),
(void *)dev9x_devctl};

/* driver descriptor */
Expand Down Expand Up @@ -164,7 +165,7 @@ int dev9d_init(void)
void SpdRegisterIntrHandler(int intr, dev9_intr_cb_t cb)
{
#ifdef HDD_DRIVER
//Don't let anything else change the HDD interrupt handlers.
// Don't let anything else change the HDD interrupt handlers.
if (intr < 2) {
if (atad_inited)
return;
Expand Down Expand Up @@ -599,7 +600,7 @@ static int pcmcia_init(void)
}
}

//The DEV9 interface and SPEED should be already initialized.
// The DEV9 interface and SPEED should be already initialized.
_sw(0xe01a3043, SSBUS_R_1418);

if (dev9_init() != 0)
Expand Down Expand Up @@ -642,7 +643,7 @@ static int expbay_init(void)
_sw(0xe01a3043, SSBUS_R_1418);
_sw(0xef1a3043, SSBUS_R_141c);

//The DEV9 interface and SPEED should be already initialized.
// The DEV9 interface and SPEED should be already initialized.

if (dev9_init() != 0)
return 1;
Expand Down
Loading

0 comments on commit 5c47ea0

Please sign in to comment.