Skip to content

Commit

Permalink
allow enabling/disabling "presence filtering" so that it is possible to
Browse files Browse the repository at this point in the history
verify if later PC-9821's don't have the same shitty PCI bus the test
486 laptop did that necessitated the hack in the first place.
  • Loading branch information
joncampbell123 committed Sep 9, 2017
1 parent f5b6709 commit 187f057
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
12 changes: 8 additions & 4 deletions hw/pci/pci.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@

unsigned char pci_cfg_probed = 0;
unsigned char pci_cfg = PCI_CFG_NONE;
unsigned char pci_cfg_presence_filtering = 0; /* if enabled, we refuse I/O to PCI bus/device combinations we know
signed char pci_cfg_presence_filtering = -1;/* if enabled, we refuse I/O to PCI bus/device combinations we know
don't exist as a concession to shitty PCI bus implementations */
uint32_t pci_bios_protmode_entry_point = 0;
uint8_t pci_bios_hw_characteristics = 0;
Expand Down Expand Up @@ -95,7 +95,7 @@ uint32_t pci_read_cfg_TYPE1_pc(uint8_t bus,uint8_t card,uint8_t func,uint8_t reg
* fields of the PCI configuration space. */
uint32_t r = pci_read_cfg_TYPE1(bus,card,func,reg,size);

if (pci_cfg_presence_filtering) {
if (pci_cfg_presence_filtering > 0) {
if (reg == 0 && size >= 2) { /* within device ID or vendor ID fields */
uint32_t ors[0x40U>>2U],ands[0x40U>>2U];
unsigned int i,j;
Expand Down Expand Up @@ -337,7 +337,7 @@ void pci_probe_for_last_bus() {
* there's anything past bus 1, let alone bus 0. probing is slowed down as
* it is trying to differentiate between real devices and garbage on the PCI
* bus. don't waste our time. */
if (pci_cfg_presence_filtering && bus > 1) {
if (pci_cfg_presence_filtering > 0 && bus > 1) {
bus--;
continue;
}
Expand Down Expand Up @@ -434,7 +434,11 @@ int pci_probe(int preference) {
* Undefined vendor IDs either read back 0x0000 or random values up to 0xFFE1. To prevent the
* host application from enumerating junk devices, we need to enable presence filtering and
* return 0xFFFF for these devices. */
pci_cfg_presence_filtering = 1;
if (pci_cfg_presence_filtering < 0)
pci_cfg_presence_filtering = 1;
#else
if (pci_cfg_presence_filtering < 0)
pci_cfg_presence_filtering = 0;
#endif

pci_cfg_probed = 1;
Expand Down
2 changes: 1 addition & 1 deletion hw/pci/pci.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ enum {

extern unsigned char pci_cfg;
extern unsigned char pci_cfg_probed;
extern unsigned char pci_cfg_presence_filtering;
extern signed char pci_cfg_presence_filtering;
extern uint32_t pci_bios_protmode_entry_point;
extern uint8_t pci_bios_hw_characteristics;
extern uint16_t pci_bios_interface_level;
Expand Down
10 changes: 9 additions & 1 deletion hw/pci/test.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ static void help() {
#ifndef TARGET_PC98
printf(" /t2 Prefer Type 2 (0xCxxx) access\n");
#endif
printf(" /pf Enable presence filtering (for crap PCI busses)\n");
printf(" /pf- Disable presence filtering\n");
printf(" /d Dump config space too\n");
}

Expand Down Expand Up @@ -64,6 +66,12 @@ int main(int argc,char **argv) {
pref = PCI_CFG_TYPE2;
}
#endif
else if (!strcmp(a,"pf")) {
pci_cfg_presence_filtering = 1;
}
else if (!strcmp(a,"pf-")) {
pci_cfg_presence_filtering = 0;
}
else {
printf("Unknown switch '%s'\n",a);
help();
Expand Down Expand Up @@ -106,7 +114,7 @@ int main(int argc,char **argv) {
}
printf(" Last bus: %d\n",pci_bios_last_bus);
printf(" Bus decode bits: %d\n",pci_bus_decode_bits);
printf(" Presence filtering: %d (%s)\n",pci_cfg_presence_filtering,pci_cfg_presence_filtering?"yes":"no");
printf(" Presence filtering: %d (%s)\n",pci_cfg_presence_filtering,pci_cfg_presence_filtering > 0 ? "yes" : "no");

/* then enumerate the bus */
{
Expand Down

2 comments on commit 187f057

@joncampbell123
Copy link
Owner Author

@joncampbell123 joncampbell123 commented on 187f057 Sep 10, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm booting up the NEC PC-9821Ls150 now to see if Pentium class laptops of that platform have better PCI busses than the 486SX I originally wrote the PCI support for, and whether or not the "presence detect" is needed.

Result: Apparently by the time Windows 95 OSR2 came around to PC-98 the PCI bus was fixed up to enum properly. Good. I will remove some of my snarky comments and fix the hw/pci library to enable presence detect only if the CPU is a 486 or lower.

@joncampbell123
Copy link
Owner Author

@joncampbell123 joncampbell123 commented on 187f057 Sep 10, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a PC-9821La10 as a second Pentium class test case I'm booting up now. We'll see if that one also has a better PCI implementation. It's a bit slower to test as the only file transfer I have at this time is with a CF card in a PCMCIA adapter via the PCMCIA slot.

Result: Yes! It works properly. So far, it seems the "presence detect" paranoid code is only needed on pre-Pentium PC-9821 systems.

Please sign in to comment.