Example #1
0
int
apm_init(void)
{
  struct olsr_apm_info ainfo;

  method = -1;
  OLSR_PRINTF(3, "Initializing APM\n");

  if ((((fd_index = acpi_probe()) >= 0) || ac_power_on) && apm_read_acpi(&ainfo))
    method = USE_ACPI;
  else if (apm_read_apm(&ainfo))
    method = USE_APM;

  if (method != -1)
    apm_printinfo(&ainfo);

  return method;
}
Example #2
0
int main(int argc,char **argv) {
    struct acpi_rsdt_header sdth;
    acpi_memaddr_t addr;
    unsigned long i,max;
    uint32_t tmp32,tmplen;
    char tmp[32];

    for (i=1;i < (unsigned long)argc;) {
        const char *a = argv[(unsigned int)(i++)];

        if (*a == '-' || *a == '/') {
            do { a++; } while (*a == '-' || *a == '/');

            if (!strcmp(a,"?") || !strcmp(a,"h") || !strcmp(a,"help")) {
                help();
                return 1;
            }
            else if (!strcmp(a,"32")) {
                acpi_use_rsdt_32 = 1;
            }
            else {
                fprintf(stderr,"Unknown switch '%s'\n",a);
                help();
                return 1;
            }
        }
        else {
            fprintf(stderr,"Unknown arg '%s'\n",a);
            help();
            return 1;
        }
    }

    if (!probe_8254()) {
        printf("Cannot init 8254 timer\n");
        return 1;
    }
    if (!probe_8259()) {
        printf("Cannot init 8259 PIC\n");
        return 1;
    }
    cpu_probe();
    probe_dos();
    detect_windows();
#if TARGET_MSDOS == 32
    probe_dpmi();
    dos_ltp_probe();
#endif

#if TARGET_MSDOS == 16
    if (!flatrealmode_setup(FLATREALMODE_4GB)) {
        printf("Unable to set up flat real mode (needed for 16-bit builds)\n");
        printf("Most ACPI functions require access to the full 4GB range.\n");
        return 1;
    }
#endif

    if (!acpi_probe()) {
        printf("ACPI BIOS not found\n");
        return 1;
    }
    assert(acpi_rsdp != NULL);
    printf("ACPI %u.0 structure at 0x%05lX\n",acpi_rsdp->revision+1,(unsigned long)acpi_rsdp_location);

    memcpy(tmp,(char*)(&(acpi_rsdp->OEM_id)),6); tmp[6]=0;
    printf("ACPI OEM ID '%s', RSDT address (32-bit) 0x%08lX Length %lu\n",tmp,
        (unsigned long)(acpi_rsdp->rsdt_address),
        (unsigned long)(acpi_rsdp->length));
    if (acpi_rsdp->revision != 0)
        printf("   XSDT address (64-bit) 0x%016llX\n",
            (unsigned long long)(acpi_rsdp->xsdt_address));

    printf("Chosen RSDT/XSDT at 0x%08llX\n",(unsigned long long)acpi_rsdt_location);

    if (acpi_rsdt != NULL) {
        memcpy(tmp,(void*)(acpi_rsdt->signature),4); tmp[4] = 0;
        printf("  '%s': len=%lu rev=%u\n",tmp,(unsigned long)acpi_rsdt->length,
            acpi_rsdt->revision);

        memcpy(tmp,(void*)(acpi_rsdt->OEM_id),6); tmp[6] = 0;
        printf("  OEM id: '%s'\n",tmp);

        memcpy(tmp,(void*)(acpi_rsdt->OEM_table_id),8); tmp[8] = 0;
        printf("  OEM table id: '%s' rev %lu\n",tmp,
            (unsigned long)acpi_rsdt->OEM_revision);

        memcpy(tmp,(void*)(&(acpi_rsdt->creator_id)),4); tmp[4] = 0;
        printf("  Creator: '%s' rev %lu\n",tmp,
            (unsigned long)acpi_rsdt->creator_revision);
    }

    max = acpi_rsdt_entries();
    if (acpi_rsdt_is_xsdt()) {
        printf("Showing XSDT, %lu entries\n",max);
    }
    else {
        printf("Showing RSDT, %lu entries\n",max);
    }

    for (i=0;i < max;i++) {
        addr = acpi_rsdt_entry(i);
        printf(" [%lu] 0x%08llX ",i,(unsigned long long)addr);
        if (addr != 0ULL) {
            tmp32 = acpi_mem_readd(addr);
            tmplen = 0;

            memcpy(tmp,&tmp32,4); tmp[4] = 0;
            if (acpi_probe_rsdt_check(addr,tmp32,&tmplen)) {
                acpi_memcpy_from_phys(&sdth,addr,sizeof(struct acpi_rsdt_header));

                printf("'%s' len=0x%lX rev=%u ",tmp,(unsigned long)tmplen,sdth.revision);

                memcpy(tmp,&sdth.OEM_id,6); tmp[6] = 0;
                printf("OEM id: '%s'\n",tmp);

                memcpy(tmp,&sdth.OEM_table_id,8); tmp[8] = 0;
                printf("OEM table id: '%s' rev %u ",tmp,sdth.OEM_revision);

                memcpy(tmp,&sdth.creator_id,4); tmp[4] = 0;
                printf("Creator id: '%s' rev %u",tmp,sdth.creator_revision);

                if (!memcmp(sdth.signature,"MCFG",4)) {
                    struct acpi_mcfg_entry entry;
                    uint64_t o = addr + 44;
                    unsigned int count;

                    printf("\nPCI Express map:");
                    assert(sizeof(struct acpi_mcfg_entry) == 16);
                    count = (unsigned int)(tmplen / sizeof(struct acpi_mcfg_entry));
                    while (count != 0) {
                        acpi_memcpy_from_phys(&entry,o,sizeof(struct acpi_mcfg_entry));
                        o += sizeof(struct acpi_mcfg_entry);

                        /* Some bioses I test against seem to return enough for 3 but fill in only 1? */
                        if (entry.base_address != 0ULL || entry.start_pci_bus_number != 0 || entry.end_pci_bus_number != 0) {
                            uint64_t sz;

                            if (entry.start_pci_bus_number > entry.end_pci_bus_number)
                                entry.start_pci_bus_number = entry.end_pci_bus_number;

                            sz = (((unsigned long long)(entry.end_pci_bus_number - entry.start_pci_bus_number)) + 1ULL) << 20ULL;
                            printf("\n  @0x%08llX-0x%08llX seg=%u bus=%u-%u",
                                (unsigned long long)entry.base_address,
                                (unsigned long long)(entry.base_address + sz - 1ULL),
                                (unsigned int)entry.pci_segment_group_number,
                                (unsigned int)entry.start_pci_bus_number,
                                (unsigned int)entry.end_pci_bus_number);
                        }

                        count--;
                    }
                }
            }
            else {
                printf("'%s' check failed",tmp);
            }
        }
        printf("\n");
    }

    acpi_free();
    return 0;
}
Example #3
0
/*
 * Attach the mainbus.
 */
void
mainbus_attach(device_t parent, device_t self, void *aux)
{
	union mainbus_attach_args mba;
#if defined(DOM0OPS) && defined(XEN3)
	int numcpus = 0;
#ifdef MPBIOS
	int mpbios_present = 0;
#endif
#if NACPI > 0 || defined(MPBIOS)
	int numioapics = 0;     
#endif
#endif /* defined(DOM0OPS) && defined(XEN3) */

	aprint_naive("\n");
	aprint_normal("\n");

#ifndef XEN3
	memset(&mba.mba_caa, 0, sizeof(mba.mba_caa));
	mba.mba_caa.cpu_number = 0;
	mba.mba_caa.cpu_role = CPU_ROLE_SP;
	mba.mba_caa.cpu_func = 0;
	config_found_ia(self, "cpubus", &mba.mba_caa, mainbus_print);
#else /* XEN3 */
#ifdef DOM0OPS
	if (xendomain_is_dom0()) {
#ifdef MPBIOS
		mpbios_present = mpbios_probe(self);
#endif
#if NPCI > 0
		/* ACPI needs to be able to access PCI configuration space. */
		pci_mode = pci_mode_detect();
#ifdef PCI_BUS_FIXUP
		pci_maxbus = pci_bus_fixup(NULL, 0);
		aprint_debug_dev(self, "PCI bus max, after pci_bus_fixup: %i\n",
		    pci_maxbus);
#ifdef PCI_ADDR_FIXUP
		pciaddr.extent_port = NULL;
		pciaddr.extent_mem = NULL;
		pci_addr_fixup(NULL, pci_maxbus);
#endif /* PCI_ADDR_FIXUP */
#endif /* PCI_BUS_FIXUP */
#if NACPI > 0
		acpi_present = acpi_probe();
		if (acpi_present)
			mpacpi_active = mpacpi_scan_apics(self,
			    &numcpus, &numioapics);
		if (!mpacpi_active)
#endif
		{
#ifdef MPBIOS
			if (mpbios_present)
				mpbios_scan(self, &numcpus, &numioapics);       
			else
#endif
			if (numcpus == 0) {
				memset(&mba.mba_caa, 0, sizeof(mba.mba_caa));
				mba.mba_caa.cpu_number = 0;
				mba.mba_caa.cpu_role = CPU_ROLE_SP;
				mba.mba_caa.cpu_func = 0;
				config_found_ia(self, "cpubus",
				    &mba.mba_caa, mainbus_print);
			}
		}
#if NIOAPIC > 0
	ioapic_enable();
#endif
#endif /* NPCI */
	}
#endif /* DOM0OPS */
#endif /* XEN3 */

#if NIPMI > 0
	memset(&mba.mba_ipmi, 0, sizeof(mba.mba_ipmi));
	mba.mba_ipmi.iaa_iot = X86_BUS_SPACE_IO;
	mba.mba_ipmi.iaa_memt = X86_BUS_SPACE_MEM;
	if (ipmi_probe(&mba.mba_ipmi))
		config_found_ia(self, "ipmibus", &mba.mba_ipmi, 0);
#endif

#if NHYPERVISOR > 0
	mba.mba_haa.haa_busname = "hypervisor";
	config_found_ia(self, "hypervisorbus", &mba.mba_haa, mainbus_print);
#endif
}
Example #4
0
static int
apm_read_acpi(struct olsr_apm_info *ainfo)
{
  FILE *fd;
  int bat_max = 5000;                  /* Find some sane value */
  int bat_val = 0;

  /* reporbe in case ac status changed */
  fd_index = acpi_probe();

  /* No battery was found */
  if (fd_index < 0) {
    /* but we have ac */
    if (ac_power_on) {
      ainfo->ac_line_status = OLSR_AC_POWERED;

      ainfo->battery_percentage = -1;

      return 1;
    }

    /* not enough info */
    return 0;
  }

  /* Get maxvalue */
  if ((fd = fopen(acpi_info[fd_index], "r")) == NULL)
    return 0;

  for (;;) {
    char s1[32], s2[32], s3[32], s4[32], inbuff[127];
    if (fgets(inbuff, sizeof(inbuff), fd) == NULL)
      break;

    sscanf(inbuff, "%32s %32s %32s %32s", s1, s2, s3, s4);
    if (!strcasecmp(s2, "full"))
      bat_max = atoi(s4);
  }
  fclose(fd);

  if ((fd = fopen(acpi_state[fd_index], "r")) == NULL)
    return 0;

  /* Extract battery status */
  for (;;) {
    char s1[32], s2[32], s3[32], s4[32], inbuff[127];
    if (fgets(inbuff, sizeof(inbuff), fd) == NULL)
      break;
    sscanf(inbuff, "%32s %32s %32s %32s", s1, s2, s3, s4);

    /* find remaining juice */
    if (!strcasecmp(s1, "Remaining"))
      bat_val = atoi(s3);
  }
  fclose(fd);

  ainfo->ac_line_status = ac_power_on ? OLSR_AC_POWERED : OLSR_BATTERY_POWERED;

  /* sanitise ACPI battery data */
  bat_max = abs(bat_max);
  bat_val = abs(bat_val);
  if (bat_val > bat_max) {
    bat_val = bat_max;
  }

  if (bat_max == 0) {
    /* protection against stupid acpi data */
    ainfo->battery_percentage = 0;
  }
  else {
    ainfo->battery_percentage = (bat_val >= bat_max) ? 100 : (bat_val * 100 / bat_max);
  }

  return 1;
}
Example #5
0
/*
 * Attach the mainbus.
 */
void
mainbus_attach(device_t parent, device_t self, void *aux)
{
#if NPCI > 0
	union mainbus_attach_args mba;
#endif
#if NACPI > 0
	int acpi_present = 0;
#endif
#ifdef MPBIOS
	int mpbios_present = 0;
#endif
	int mpacpi_active = 0;
	int numcpus = 0;
#if NACPI > 0 || defined(MPBIOS)
	int numioapics = 0;
#endif
#if defined(PCI_BUS_FIXUP)
	int pci_maxbus = 0;
#endif

	aprint_naive("\n");
	aprint_normal("\n");

#ifdef MPBIOS
	mpbios_present = mpbios_probe(self);
#endif

#if NPCI > 0
	pci_mode = pci_mode_detect();
#if defined(PCI_BUS_FIXUP)
	if (pci_mode != 0) {
		pci_maxbus = pci_bus_fixup(NULL, 0);
		aprint_debug("PCI bus max, after pci_bus_fixup: %i\n",
		    pci_maxbus);
#if defined(PCI_ADDR_FIXUP)
		pciaddr.extent_port = NULL;
		pciaddr.extent_mem = NULL;
		pci_addr_fixup(NULL, pci_maxbus);
#endif
	}
#endif
#endif

#if NACPI > 0
	if ((boothowto & RB_MD2) == 0 && acpi_check(self, "acpibus"))
		acpi_present = acpi_probe();
	/*
	 * First, see if the MADT contains CPUs, and possibly I/O APICs.
	 * Building the interrupt routing structures can only
	 * be done later (via a callback).
	 */
	if (acpi_present)
		mpacpi_active = mpacpi_scan_apics(self, &numcpus, &numioapics);
#endif

	if (!mpacpi_active) {
#ifdef MPBIOS
		if (mpbios_present)
			mpbios_scan(self, &numcpus, &numioapics);
		else
#endif
		if (numcpus == 0) {
			struct cpu_attach_args caa;
                        
			memset(&caa, 0, sizeof(caa));
			caa.cpu_number = 0;
			caa.cpu_role = CPU_ROLE_SP;
			caa.cpu_func = 0;
                        
			config_found_ia(self, "cpubus", &caa, mainbus_print);
		}
	}

#if NISADMA > 0 && NACPI > 0
	/*
	 * ACPI needs ISA DMA initialized before they start probing.
	 */
	isa_dmainit(&x86_isa_chipset, X86_BUS_SPACE_IO, &isa_bus_dma_tag,
	    self);
#endif


#if NACPI > 0
	if (acpi_present) {
		mba.mba_acpi.aa_iot = X86_BUS_SPACE_IO;
		mba.mba_acpi.aa_memt = X86_BUS_SPACE_MEM;
		mba.mba_acpi.aa_pc = NULL;
		mba.mba_acpi.aa_pciflags =
		    PCI_FLAGS_IO_ENABLED | PCI_FLAGS_MEM_ENABLED |
		    PCI_FLAGS_MRL_OKAY | PCI_FLAGS_MRM_OKAY |
		    PCI_FLAGS_MWI_OKAY;
		mba.mba_acpi.aa_ic = &x86_isa_chipset;
		config_found_ia(self, "acpibus", &mba.mba_acpi, 0);
	}
#endif

#if NIPMI > 0
	memset(&mba.mba_ipmi, 0, sizeof(mba.mba_ipmi));
	mba.mba_ipmi.iaa_iot = X86_BUS_SPACE_IO;
	mba.mba_ipmi.iaa_memt = X86_BUS_SPACE_MEM;
	if (ipmi_probe(&mba.mba_ipmi))
		config_found_ia(self, "ipmibus", &mba.mba_ipmi, 0);
#endif

#if NPCI > 0
	if (pci_mode != 0) {
		mba.mba_pba.pba_iot = X86_BUS_SPACE_IO;
		mba.mba_pba.pba_memt = X86_BUS_SPACE_MEM;
		mba.mba_pba.pba_dmat = &pci_bus_dma_tag;
		mba.mba_pba.pba_dmat64 = &pci_bus_dma64_tag;
		mba.mba_pba.pba_pc = NULL;
		mba.mba_pba.pba_flags = pci_bus_flags();
		mba.mba_pba.pba_bus = 0;
		mba.mba_pba.pba_bridgetag = NULL;
#if NACPI > 0 && defined(ACPI_SCANPCI)
		if (mpacpi_active)
			mpacpi_scan_pci(self, &mba.mba_pba, pcibusprint);
		else
#endif
#if defined(MPBIOS) && defined(MPBIOS_SCANPCI)
		if (mpbios_scanned != 0)
			mpbios_scan_pci(self, &mba.mba_pba, pcibusprint);
		else
#endif
		config_found_ia(self, "pcibus", &mba.mba_pba, pcibusprint);

#if NACPI > 0
		if (mp_verbose)
			acpi_pci_link_state();
#endif

	}
#endif

#if NISA > 0
	if (isa_has_been_seen == 0)
		config_found_ia(self, "isabus", &mba_iba, isabusprint);
#endif

	if (!pmf_device_register(self, NULL, NULL))
		aprint_error_dev(self, "couldn't establish power handler\n");
}