Browse Source

ACPI: extend support.

We are now finding devices by running AML. We are still not able to
get a route for an interrupt, but it's getting closer.

Signed-off-by: Ronald G. Minnich <rminnich@gmail.com>
Ronald G. Minnich 7 years ago
parent
commit
7277a648fd
3 changed files with 65 additions and 31 deletions
  1. 5 2
      sys/src/cmd/acpi/irq.c
  2. 59 28
      sys/src/libacpi/harvey.c
  3. 1 1
      sys/src/libacpi/olsneracpi.c

+ 5 - 2
sys/src/cmd/acpi/irq.c

@@ -69,11 +69,11 @@ main(int argc, char *argv[])
 
 	/* from acpi: */
     	/* If the Hardware Reduced flag is set, machine is always in acpi mode */
-	//AcpiGbl_ReducedHardware = 1;
+	AcpiGbl_ReducedHardware = 1;
 	print("LOADED TABLES. Hi the any key to continue\n"); //getchar();
         status = AcpiEnableSubsystem(0);
         if (ACPI_FAILURE(status))
-		sysfatal("Can't enable ACPI subsystem");
+		print("Probably does not matter: Can't enable ACPI subsystem");
 
 	print("enabled subsystem. Hi the any key to continue\n"); //getchar();
         status = AcpiInitializeObjects(0);
@@ -98,6 +98,9 @@ main(int argc, char *argv[])
 		status = RouteIRQ(&id, i, &irq);
 		print("status %d, irq %d\n", status, irq);
 	}
+	AcpiDbgLevel = 0;
+	ACPI_STATUS PrintDevices(void);
+	status = PrintDevices();
 	print("OK on init.\n");
 	exits(0);
 }

+ 59 - 28
sys/src/libacpi/harvey.c

@@ -143,49 +143,82 @@ enum
 };
 
 static int
-pcicfgrw(int tbdf, int r, int data, int rw, int w)
+pcicfgrw(int bus, int dev, int fn, int r, int data, int rw, int w)
 {
 	int o, x, er;
-
-	if(BUSDNO(tbdf) > Maxdev)
+	/* single threaded */
+	static char path[128];
+	snprint(path, sizeof(path), "/dev/pci/%d.%d.%draw", bus, dev, fn);
+	int fd = open(path, ORDWR);
+	if (fd < 0) {
+		print("%s: open %s: %r\n", __func__, path);
 		return -1;
+	}
 
-	o = r & (4-w);
-	er = (r&0xfc) | ((r & 0xf00)<<16);
-	outl(PciADDR, 0x80000000|BUSBDF(tbdf)|er);
 	if(rw == Read){
 		x = -1;
 		switch(w){
 		case 1:
-			x = inb(PciDATA+o);
-			break;
 		case 2:
-			x = ins(PciDATA+o);
-			break;
 		case 4:
-			x = inl(PciDATA+o);
+			if (pread(fd, &x, w, r) != w)
+				print("%s read@%d: %r", __func__, r);
 			break;
 		}
 	}else{
 		x = 0;
 		switch(w){
 		case 1:
-			outb(PciDATA+o, data);
-			break;
 		case 2:
-			outs(PciDATA+o, data);
-			break;
 		case 4:
-			outl(PciDATA+o, data);
-			break;
+			if (pwrite(fd, &data, w, r) != w)
+				print("%s write@%d: %r", __func__, r);
 		}
 	}
-//	outl(PciADDR, 0);
 
+	close(fd);
 	return x;
 }
 
 
+int
+pcicfgr8(int bus, int dev, int fn, int rno)
+{
+	return pcicfgrw(bus, dev, fn, rno, 0, Read, 1);
+}
+
+void
+pcicfgw8(int bus, int dev, int fn, int rno, int data)
+{
+	pcicfgrw(bus, dev, fn, rno, data, Write, 1);
+}
+
+int
+pcicfgr16(int bus, int dev, int fn, int rno)
+{
+	return pcicfgrw(bus, dev, fn, rno, 0, Read, 2);
+}
+
+void
+pcicfgw16(int bus, int dev, int fn, int rno, int data)
+{
+	pcicfgrw(bus, dev, fn, rno, data, Write, 2);
+}
+
+int
+pcicfgr32(int bus, int dev, int fn, int rno)
+{
+	return pcicfgrw(bus, dev, fn, rno, 0, Read, 4);
+}
+
+void
+pcicfgw32(int bus, int dev, int fn, int rno, int data)
+{
+	pcicfgrw(bus, dev, fn, rno, data, Write, 4);
+}
+
+
+
 ACPI_STATUS
 AcpiOsReadPciConfiguration (
     ACPI_PCI_ID             *PciId,
@@ -197,13 +230,13 @@ AcpiOsReadPciConfiguration (
 	fprint(2,"%s 0x%lx\n", __func__, dev);
 	switch(Width) {
 	case 32:
-		*Value = pcicfgr32(&p, Reg);
+		*Value = pcicfgr32(PciId->Bus, PciId->Device, PciId->Function, Reg);
 		break;
 	case 16:
-		*Value = pcicfgr16(&p, Reg);
+		*Value = pcicfgr16(PciId->Bus, PciId->Device, PciId->Function, Reg);
 		break;
 	case 8:
-		*Value = pcicfgr8(&p, Reg);
+		*Value = pcicfgr8(PciId->Bus, PciId->Device, PciId->Function, Reg);
 		break;
 	default:
 		sysfatal("Can't read pci: bad width %d\n", Width);
@@ -223,13 +256,13 @@ AcpiOsWritePciConfiguration (
 	fprint(2,"%s 0x%lx\n", __func__, dev);
 	switch(Width) {
 	case 32:
-		pcicfgw32(&p, Reg, Value);
+		pcicfgw32(PciId->Bus, PciId->Device, PciId->Function, Reg, Value);
 		break;
 	case 16:
-		pcicfgw16(&p, Reg, Value);
+		pcicfgw16(PciId->Bus, PciId->Device, PciId->Function, Reg, Value);
 		break;
 	case 8:
-		pcicfgw8(&p, Reg, Value);
+		pcicfgw8(PciId->Bus, PciId->Device, PciId->Function, Reg, Value);
 		break;
 	default:
 		sysfatal("Can't read pci: bad width %d\n", Width);
@@ -506,7 +539,7 @@ AcpiOsSleep (
     UINT64                  Milliseconds)
 {
 	fprint(2,"%s\n", __func__);
-	sysfatal("%s", __func__);
+	sleep(Milliseconds);
 }
 
 void
@@ -514,7 +547,7 @@ AcpiOsStall(
     UINT32                  Microseconds)
 {
 	fprint(2,"%s\n", __func__);
-	sysfatal("%s", __func__);
+	sleep(Microseconds/1000+1);
 }
 
 ACPI_THREAD_ID
@@ -561,7 +594,6 @@ AcpiOsReadPort (
 		break;
 	}
 	fprint(2,"%s 0x%x 0x%x\n", __func__, Address, *Value);
-	sysfatal("NOT");
 	return AE_OK;
 }
 
@@ -586,7 +618,6 @@ AcpiOsWritePort (
 		break;
 	}
 	fprint(2,"%s 0x%x 0x%x\n", __func__, Address, Value);
-	sysfatal("NOT");
 	return AE_OK;
 }
 

+ 1 - 1
sys/src/libacpi/olsneracpi.c

@@ -320,7 +320,7 @@ static ACPI_STATUS PrintDeviceCallback(ACPI_HANDLE Device, UINT32 Depth, void *C
 
 // PNP0C0F = PCI Interrupt Link Device
 // PNP0A03 = PCI Root Bridge
-static ACPI_STATUS PrintDevices(void) {
+ACPI_STATUS PrintDevices(void) {
 	ACPI_STATUS status = AE_OK;
 
 	printf("Searching for PNP0A03\n");