Skip to content

Commit

Permalink
Upload all OHCI work done so far
Browse files Browse the repository at this point in the history
No idea why SMM <-> OS handover is not working, although there's a gross workaround for that in the stub implementation
  • Loading branch information
Cacodemon345 committed May 26, 2024
1 parent 7078e90 commit 9a85282
Show file tree
Hide file tree
Showing 16 changed files with 1,859 additions and 8 deletions.
4 changes: 4 additions & 0 deletions src/chipset/ali1543.c
Original file line number Diff line number Diff line change
Expand Up @@ -1600,6 +1600,7 @@ static void *
ali1543_init(const device_t *info)
{
ali1543_t *dev = (ali1543_t *) malloc(sizeof(ali1543_t));
usb_params_t usb_param = { NULL, NULL };
memset(dev, 0, sizeof(ali1543_t));

/* Device 02: M1533 Southbridge */
Expand Down Expand Up @@ -1640,7 +1641,10 @@ ali1543_init(const device_t *info)
dev->smbus = device_add(&ali7101_smbus_device);

/* USB */
usb_param.pci_conf = dev->usb_conf;
usb_param.pci_dev = &dev->usb_slot;
dev->usb = device_add(&usb_device);
ohci_register_usb(dev->usb);

dev->type = info->local & 0xff;
dev->offset = (info->local >> 8) & 0x7f;
Expand Down
5 changes: 4 additions & 1 deletion src/chipset/intel_piix.c
Original file line number Diff line number Diff line change
Expand Up @@ -1573,7 +1573,10 @@ piix_init(const device_t *info)

if (dev->type >= 3) {
dev->usb = device_add_params(&usb_device, &params);
uhci_register_usb(dev->usb);
if (dev->type > 4)
ohci_register_usb(dev->usb);
else
uhci_register_usb(dev->usb);
}

if (dev->type > 3) {
Expand Down
3 changes: 3 additions & 0 deletions src/chipset/sis_5571.c
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,9 @@ sis_5571_init(UNUSED(const device_t *info))

dev->sis = device_add(&sis_55xx_common_device);

/* We need this for USB interrupts. */
dev->sis->sb_southbridge_slot = &dev->sb_slot;

dev->h2p = device_add_linked(&sis_5571_h2p_device, dev->sis);
dev->p2i = device_add_linked(&sis_5572_p2i_device, dev->sis);
dev->ide = device_add_linked(&sis_5572_ide_device, dev->sis);
Expand Down
4 changes: 4 additions & 0 deletions src/chipset/sis_5572_usb.c
Original file line number Diff line number Diff line change
Expand Up @@ -267,13 +267,17 @@ static void *
sis_5572_usb_init(UNUSED(const device_t *info))
{
sis_5572_usb_t *dev = (sis_5572_usb_t *) calloc(1, sizeof(sis_5572_usb_t));
usb_params_t usb_param = { NULL, NULL };

dev->rev = info->local;

dev->sis = device_get_common_priv();

/* USB */
usb_param.pci_conf = dev->pci_conf;
usb_param.pci_dev = dev->sis->sb_southbridge_slot;
dev->usb = device_add(&usb_device);
ohci_register_usb(dev->usb);

sis_5572_usb_reset(dev);

Expand Down
4 changes: 3 additions & 1 deletion src/chipset/stpc.c
Original file line number Diff line number Diff line change
Expand Up @@ -920,10 +920,12 @@ stpc_init(const device_t *info)
pci_add_card(PCI_ADD_NORTHBRIDGE, stpc_nb_read, stpc_nb_write, dev, &dev->nb_slot);
pci_add_card(PCI_ADD_SOUTHBRIDGE, stpc_isab_read, stpc_isab_write, dev, &dev->sb_slot);
if (dev->local == STPC_ATLAS) {
usb_params_t usb_params = { .pci_conf = dev->pci_conf[3], .pci_dev = &dev->usb_slot };
pci_add_card(PCI_ADD_SOUTHBRIDGE_IDE, stpc_ide_read, stpc_ide_write, dev, &dev->ide_slot);

dev->usb = device_add(&usb_device);
dev->usb = device_add_params(&usb_device, &usb_params);
pci_add_card(PCI_ADD_SOUTHBRIDGE_USB, stpc_usb_read, stpc_usb_write, dev, &dev->usb_slot);
ohci_register_usb(dev->usb);
}

dev->bm[0] = device_add_inst(&sff8038i_device, 1);
Expand Down
27 changes: 27 additions & 0 deletions src/include/86box/io.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,35 @@
#ifndef EMU_IO_H
#define EMU_IO_H

typedef struct _io_range_ {
uint8_t (*inb)(uint16_t addr, void *priv);
uint16_t (*inw)(uint16_t addr, void *priv);
uint32_t (*inl)(uint16_t addr, void *priv);

void (*outb)(uint16_t addr, uint8_t val, void *priv);
void (*outw)(uint16_t addr, uint16_t val, void *priv);
void (*outl)(uint16_t addr, uint32_t val, void *priv);

void *priv;

uint16_t start;
uint16_t end;

uint8_t enable;
} io_range_t;

extern void io_init(void);

extern io_range_t* io_range_addhandler(uint16_t start, uint16_t end,
uint8_t (*inb)(uint16_t addr, void *priv),
uint16_t (*inw)(uint16_t addr, void *priv),
uint32_t (*inl)(uint16_t addr, void *priv),
void (*outb)(uint16_t addr, uint8_t val, void *priv),
void (*outw)(uint16_t addr, uint16_t val, void *priv),
void (*outl)(uint16_t addr, uint32_t val, void *priv),
uint8_t enable,
void *priv);

extern void io_sethandler_common(uint16_t base, int size,
uint8_t (*inb)(uint16_t addr, void *priv),
uint16_t (*inw)(uint16_t addr, void *priv),
Expand Down
34 changes: 34 additions & 0 deletions src/include/86box/pcmcia.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
struct pcmcia_socket_t;
typedef struct pcmcia_socket_t pcmcia_socket_t;

struct pcmcia_socket_t {
/* Socket number (zero-based) */
uint8_t socket_num;

/* Card I/O Read and Write functions. */
uint8_t (*io_read)(uint16_t port, void* priv);
uint16_t (*io_readw)(uint16_t port, void* priv);
void (*io_write)(uint16_t port, uint8_t val, void* priv);
void (*io_writew)(uint16_t port, uint16_t val, void* priv);

/* Card Memory Read and Write functions. */
uint8_t (*mem_read)(uint16_t port, int reg, void* priv);
uint16_t (*mem_readw)(uint16_t port, int reg, void* priv);
void (*mem_write)(uint16_t port, uint8_t val, int reg, void* priv);
void (*mem_writew)(uint16_t port, uint16_t val, int reg, void* priv);

/* Signals power status change to the card. */
void (*power_status_change)(pcmcia_socket_t* socket);

/* Signals card insertion/removal to the socket. */
void (*card_inserted)(bool inserted, pcmcia_socket_t* socket);

/* Opaque pointer to card-specific information. */
void *card_priv;

/* Opaque pointer to socket-specific information. */
void *socket_priv;

/* Card power status. */
bool powered_on;
};
1 change: 1 addition & 0 deletions src/include/86box/sis_55xx.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
typedef struct
{
uint8_t sb_pci_slot;
uint8_t *sb_southbridge_slot;
uint8_t ide_bits_1_3_writable;
uint8_t usb_enabled;

Expand Down
2 changes: 2 additions & 0 deletions src/include/86box/usb.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ typedef struct usb_t {
mem_mapping_t ohci_mmio_mapping;

void* usb_uhci_priv;
void* usb_ohci_priv;
} usb_t;

typedef struct usb_port_t {
Expand All @@ -58,6 +59,7 @@ extern void uhci_update_io_mapping(usb_t *dev, uint8_t base_l, uint8_t base_h, i
extern void ohci_update_mem_mapping(usb_t *dev, uint8_t base1, uint8_t base2, uint8_t base3, int enable);

extern void uhci_register_usb(usb_t *dev);
extern void ohci_register_usb(usb_t *dev);

/* Returns NULL if none found, else pointer to port. */
extern usb_port_t* usb_search_for_ports(void);
Expand Down
122 changes: 122 additions & 0 deletions src/io.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ int initialized = 0;
io_t *io[NPORTS];
io_t *io_last[NPORTS];

io_range_t io_ranges[256];
uint32_t io_ranges_num = 0;

#ifdef ENABLE_IO_LOG
int io_do_log = ENABLE_IO_LOG;

Expand All @@ -84,6 +87,8 @@ io_init(void)
io_t *p;
io_t *q;

io_ranges_num = 0;

if (!initialized) {
for (c = 0; c < NPORTS; c++)
io[c] = io_last[c] = NULL;
Expand All @@ -108,6 +113,35 @@ io_init(void)
}
}

io_range_t*
io_range_addhandler(uint16_t start, uint16_t end,
uint8_t (*inb)(uint16_t addr, void *priv),
uint16_t (*inw)(uint16_t addr, void *priv),
uint32_t (*inl)(uint16_t addr, void *priv),
void (*outb)(uint16_t addr, uint8_t val, void *priv),
void (*outw)(uint16_t addr, uint16_t val, void *priv),
void (*outl)(uint16_t addr, uint32_t val, void *priv),
uint8_t enable,
void *priv)
{
io_range_t* io_range = NULL;
if (io_ranges_num >= 256)
return NULL;

io_range = &io_ranges[io_ranges_num];
io_range->inb = inb;
io_range->inw = inw;
io_range->inl = inl;
io_range->outb = outb;
io_range->outw = outw;
io_range->outl = outl;
io_range->priv = priv;
io_range->enable = enable;
io_ranges_num++;

return io_range;
}

void
io_sethandler_common(uint16_t base, int size,
uint8_t (*inb)(uint16_t addr, void *priv),
Expand Down Expand Up @@ -359,6 +393,7 @@ inb(uint16_t port)
qfound = 1;
#endif
} else {
int i = 0;
p = io[port];
while (p) {
q = p->next;
Expand All @@ -371,6 +406,15 @@ inb(uint16_t port)
}
p = q;
}

if (UNLIKELY(io_ranges_num)) {
for (i = 0; i < io_ranges_num; i++) {
if (io_ranges[i].start >= port && port <= io_ranges[i].end && io_ranges[i].enable && io_ranges[i].inb) {
ret &= io_ranges[i].inb(port, io_ranges[i].priv);
found |= 1;
}
}
}
}

if (amstrad_latch & 0x80000000) {
Expand Down Expand Up @@ -435,6 +479,16 @@ outb(uint16_t port, uint8_t val)
}
p = q;
}

if (UNLIKELY(io_ranges_num)) {
int i = 0;
for (i = 0; i < io_ranges_num; i++) {
if (io_ranges[i].start >= port && port <= io_ranges[i].end && io_ranges[i].enable && io_ranges[i].outb) {
io_ranges[i].outb(port, val, io_ranges[i].priv);
found |= 1;
}
}
}
}

if (!found) {
Expand Down Expand Up @@ -509,6 +563,19 @@ inw(uint16_t port)
}
}
ret = (ret8[1] << 8) | ret8[0];

if (UNLIKELY(io_ranges_num)) {
int i = 0;
for (i = 0; i < io_ranges_num; i++) {
if (io_ranges[i].start >= port && port <= io_ranges[i].end && io_ranges[i].enable) {
if (io_ranges[i].inw)
ret &= io_ranges[i].inw(port, io_ranges[i].priv);
else
ret &= (io_ranges[i].inb(port, io_ranges[i].priv)) | (io_ranges[i].inb(port + 1, io_ranges[i].priv) << 8);
found |= 1;
}
}
}
}

if (amstrad_latch & 0x80000000) {
Expand Down Expand Up @@ -582,6 +649,21 @@ outw(uint16_t port, uint16_t val)
p = q;
}
}

if (UNLIKELY(io_ranges_num)) {
int i = 0;
for (i = 0; i < io_ranges_num; i++) {
if (io_ranges[i].start >= port && port <= io_ranges[i].end && io_ranges[i].enable) {
if (io_ranges[i].outw)
io_ranges[i].outw(port, val, io_ranges[i].priv);
else {
io_ranges[i].outb(port, val & 0xFF, io_ranges[i].priv);
io_ranges[i].outb(port + 1, val >> 8, io_ranges[i].priv);
}
found |= 1;
}
}
}
}

if (!found) {
Expand Down Expand Up @@ -688,6 +770,24 @@ inl(uint16_t port)
}
}
ret = (ret8[3] << 24) | (ret8[2] << 16) | (ret8[1] << 8) | ret8[0];

if (UNLIKELY(io_ranges_num)) {
int i = 0;
for (i = 0; i < io_ranges_num; i++) {
if (io_ranges[i].start >= port && port <= io_ranges[i].end && io_ranges[i].enable) {
if (io_ranges[i].inl)
ret &= io_ranges[i].inl(port, io_ranges[i].priv);
else if (io_ranges[i].inw)
ret &= io_ranges[i].inw(port, io_ranges[i].priv) | (io_ranges[i].inw(port + 2, io_ranges[i].priv) << 16);
else
ret &= io_ranges[i].inb(port, io_ranges[i].priv)
| (io_ranges[i].inb(port + 1, io_ranges[i].priv) << 8)
| (io_ranges[i].inb(port + 2, io_ranges[i].priv) << 16)
| (io_ranges[i].inb(port + 3, io_ranges[i].priv) << 24);
found |= 1;
}
}
}
}

if (amstrad_latch & 0x80000000) {
Expand Down Expand Up @@ -779,6 +879,28 @@ outl(uint16_t port, uint32_t val)
p = q;
}
}

if (UNLIKELY(io_ranges_num)) {
int i = 0;
for (i = 0; i < io_ranges_num; i++) {
if (io_ranges[i].start >= port && port <= io_ranges[i].end && io_ranges[i].enable) {
if (io_ranges[i].outl) {
io_ranges[i].outl(port, val, io_ranges[i].priv);
}
else if (io_ranges[i].outw) {
io_ranges[i].outw(port, val, io_ranges[i].priv);
io_ranges[i].outw(port + 2, val >> 16, io_ranges[i].priv);
}
else {
io_ranges[i].outb(port, val & 0xFF, io_ranges[i].priv);
io_ranges[i].outb(port + 1, val >> 8, io_ranges[i].priv);
io_ranges[i].outb(port + 2, val >> 16, io_ranges[i].priv);
io_ranges[i].outb(port + 3, val >> 24, io_ranges[i].priv);
}
found |= 1;
}
}
}
}

if (!found) {
Expand Down
4 changes: 2 additions & 2 deletions src/machine/machine_table.c
Original file line number Diff line number Diff line change
Expand Up @@ -8618,8 +8618,8 @@ const machine_t machines[] = {
.min_multi = 2.0,
.max_multi = 2.0
},
.bus_flags = MACHINE_PS2_PCI,
.flags = MACHINE_IDE_DUAL | MACHINE_APM,
.bus_flags = MACHINE_PS2_PCI | MACHINE_BUS_USB,
.flags = MACHINE_IDE_DUAL | MACHINE_APM | MACHINE_USB,
.ram = {
.min = 32768,
.max = 131072,
Expand Down
12 changes: 12 additions & 0 deletions src/pcmcia.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#include <stdarg.h>
#include <stdio.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <wchar.h>
#define HAVE_STDARG_H
#include <86box/86box.h>
#include <86box/io.h>
#include <86box/timer.h>
#include <86box/pcmcia.h>
Loading

0 comments on commit 9a85282

Please sign in to comment.