aboutsummaryrefslogtreecommitdiffstats
path: root/com32/lib/pci/writex.c
blob: a48a88df77b6ab43d0c3b114802a64471fa960bd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include "pci/pci.h"

void BWL(pci_write) (TYPE v, pciaddr_t a)
{
  for (;;) {
    switch ( __pci_cfg_type ) {
    case PCI_CFG_AUTO:
      pci_set_config_type(PCI_CFG_AUTO);
      break;			/* Try again */

    case PCI_CFG_TYPE1:
      {
	uint32_t oldcf8;
	cli();
	oldcf8 = inl(0xcf8);
	outl(a, 0xcf8);
	BWL(out) (v, 0xcfc + (a & 3));
	outl(oldcf8, 0xcf8);
	sti();
      }
      return;

    case PCI_CFG_TYPE2:
      {
	uint8_t oldcf8, oldcfa;
	
	if ( a & (0x10 << 11) )
	  return;
	
	cli();
	oldcf8 = inb(0xcf8);
	oldcfa = inb(0xcfa);
	outb(0xf0 + ((a >> (8-1)) & 0x0e), 0xcf8);
	outb(a >> 16, 0xcfa);
	BWL(out) (v, 0xc000 + ((a >> (11-8)) & 0xf00) + (a & 0xff));
	outb(oldcf8, 0xcf8);
	outb(oldcfa, 0xcfa);
	sti();
      }
      return;

    case PCI_CFG_BIOS:
      __pci_write_bios(BIOSCALL, v, a);
      return;

    default:
      return;
    }
  }
}