PCI changes :

- Each machine now specifies what PCI device IDs are used as generic card slots
- Implemented IRQ handling
- Added SIO chip to allow IRQ routing for Premiere/PCI
This commit is contained in:
SarahW 2017-06-01 20:37:09 +01:00
commit 6bd87d5718
17 changed files with 296 additions and 39 deletions

View file

@ -1,14 +1,19 @@
#include "ibm.h"
#include "io.h"
#include "mem.h"
#include "pic.h"
#include "pci.h"
void (*pci_card_write[32])(int func, int addr, uint8_t val, void *priv);
uint8_t (*pci_card_read[32])(int func, int addr, void *priv);
void *pci_priv[32];
static int pci_irq_routing[32];
static int pci_irq_active[32];
static int pci_irqs[4];
static int pci_card_valid[32];
static int pci_index, pci_func, pci_card, pci_bus, pci_enable, pci_key;
static int pci_min_card, pci_max_card;
int pci_burst_time, pci_nonburst_time;
void pci_cf8_write(uint16_t port, uint32_t val, void *p)
@ -116,8 +121,46 @@ uint8_t pci_type2_read(uint16_t port, void *priv)
}
return 0xff;
}
void pci_init(int type, int min_card, int max_card)
void pci_set_irq_routing(int pci_int, int irq)
{
pci_irqs[pci_int - 1] = irq;
// pclog("pci_set_irq_routing: pci_int=%i irq=%i\n", pci_int, irq);
}
void pci_set_card_routing(int card, int pci_int)
{
pci_irq_routing[card] = pci_int;
// pclog("pci_irq_routing: card=%i pci_int=%i\n", card, pci_int);
}
void pci_set_irq(int card, int pci_int)
{
// pclog("pci_set_irq: card=%i irq_routing=%i\n", card, pci_irq_routing[card]);
if (pci_irq_routing[card])
{
int irq = ((pci_int - PCI_INTA) + (pci_irq_routing[card] - PCI_INTA)) & 3;
// pclog(" irq=%i pci_irqs=%i active=%i\n", irq, pci_irqs[irq], pci_irq_active[card]);
if (pci_irqs[irq] != PCI_IRQ_DISABLED && !pci_irq_active[card])
picint(1 << pci_irqs[irq]);
pci_irq_active[card] = 1;
}
}
void pci_clear_irq(int card, int pci_int)
{
// pclog("pci_clear_irq: card=%i irq_routing=%i\n", card, pci_irq_routing[card]);
if (pci_irq_routing[card])
{
int irq = ((pci_int - PCI_INTA) + (pci_irq_routing[card] - PCI_INTA)) & 3;
// pclog(" irq=%i pci_irqs=%i active=%i\n", irq, pci_irqs[irq], pci_irq_active[card]);
if (pci_irqs[irq] != PCI_IRQ_DISABLED && pci_irq_active[card])
picintc(1 << pci_irqs[irq]);
pci_irq_active[card] = 0;
}
}
void pci_init(int type)
{
int c;
@ -139,10 +182,18 @@ void pci_init(int type, int min_card, int max_card)
pci_card_read[c] = NULL;
pci_card_write[c] = NULL;
pci_priv[c] = NULL;
pci_irq_routing[c] = 0;
pci_irq_active[c] = 0;
pci_card_valid[c] = 0;
}
pci_min_card = min_card;
pci_max_card = max_card;
for (c = 0; c < 4; c++)
pci_irqs[c] = PCI_IRQ_DISABLED;
}
void pci_slot(int card)
{
pci_card_valid[card] = 1;
}
void pci_add_specific(int card, uint8_t (*read)(int func, int addr, void *priv), void (*write)(int func, int addr, uint8_t val, void *priv), void *priv)
@ -152,18 +203,20 @@ void pci_add_specific(int card, uint8_t (*read)(int func, int addr, void *priv),
pci_priv[card] = priv;
}
void pci_add(uint8_t (*read)(int func, int addr, void *priv), void (*write)(int func, int addr, uint8_t val, void *priv), void *priv)
int pci_add(uint8_t (*read)(int func, int addr, void *priv), void (*write)(int func, int addr, uint8_t val, void *priv), void *priv)
{
int c;
for (c = pci_min_card; c <= pci_max_card; c++)
for (c = 0; c < 32; c++)
{
if (!pci_card_read[c] && !pci_card_write[c])
if (pci_card_valid[c] && !pci_card_read[c] && !pci_card_write[c])
{
pci_card_read[c] = read;
pci_card_write[c] = write;
pci_priv[c] = priv;
return;
return c;
}
}
return -1;
}