static int battery_read(void) /* {{{ */ { int status; if (query_statefs) return battery_read_statefs(); DEBUG("battery plugin: Trying sysfs ..."); status = read_sysfs(); if (status == 0) return (0); DEBUG("battery plugin: Trying acpi ..."); status = read_acpi(); if (status == 0) return (0); DEBUG("battery plugin: Trying pmu ..."); status = read_pmu(); if (status == 0) return (0); ERROR("battery plugin: All available input methods failed."); return (-1); } /* }}} int battery_read */
static void add_usb_callback(const char *d_name) { class usb_tunable *usb; char filename[PATH_MAX]; DIR *dir; snprintf(filename, sizeof(filename), "/sys/bus/usb/devices/%s/power/control", d_name); if (access(filename, R_OK) != 0) return; snprintf(filename, sizeof(filename), "/sys/bus/usb/devices/%s/power/active_duration", d_name); if (access(filename, R_OK)!=0) return; /* every interface of this device should support autosuspend */ snprintf(filename, sizeof(filename), "/sys/bus/usb/devices/%s", d_name); if ((dir = opendir(filename))) { struct dirent *entry; while ((entry = readdir(dir))) { /* dirname: <busnum>-<devnum>...:<config num>-<interface num> */ if (!isdigit(entry->d_name[0])) continue; snprintf(filename, sizeof(filename), "/sys/bus/usb/devices/%s/%s/supports_autosuspend", d_name, entry->d_name); if (access(filename, R_OK) == 0 && read_sysfs(filename) == 0) break; } closedir(dir); if (entry) return; } snprintf(filename, sizeof(filename), "/sys/bus/usb/devices/%s", d_name); usb = new class usb_tunable(filename, d_name); all_tunables.push_back(usb); }
static int read_sysfs_adapter(struct cxl_adapter_h *adapter, enum cxl_sysfs_attr attr, long *majorp, long *minorp) { if ((adapter == NULL) || (adapter->sysfs_path == NULL)) { errno = EINVAL; return -1; } return read_sysfs(adapter->sysfs_path, attr, majorp, minorp); }
static int read_sysfs_afu(struct cxl_afu_h *afu, enum cxl_sysfs_attr attr, long *majorp, long *minorp) { if ((afu == NULL) || (afu->sysfs_path == NULL)) { errno = EINVAL; return -1; } return read_sysfs(afu->sysfs_path, attr, majorp, minorp); }
bool sysfs_power_meter::get_sysfs_attr(const char *attribute, int *value) { char filename[PATH_MAX]; bool ok; snprintf(filename, sizeof(filename), "/sys/class/power_supply/%s/%s", name, attribute); *value = read_sysfs(filename, &ok); return ok; }
void GeneralInfo::update_sysfs(const char *sysfs, int col) { char result[64]; memset(&result[0], 0, sizeof(result)); read_sysfs(sysfs, result); result[strlen(result)-1] = '\0'; text_data[col]->settext(result); }
int SensorBase::sensorBaseGetPollMax(){ char buf[64]; int size; int pollmax; size = read_sysfs(sysfs_poll_max,buf,sizeof(buf)); buf[size] = '\0'; pollmax = atoi(buf); ALOGD("%s ,%s",__FUNCTION__,buf); return pollmax; //default max is 200ms }
int SensorBase::sensorBaseGetPollMin(){ char buf[64]; int size; int pollmin; size = read_sysfs(sysfs_poll_min,buf,sizeof(buf)); buf[size] = '\0'; pollmin = atoi(buf); ALOGD("%s ,%s",__FUNCTION__,buf); return pollmin; }
void GeneralInfo::update_temp() { char result[64]; char *p; read_sysfs(SB_SYSFS_PATH_BATTERY_TEMPERATURE, result); p = &result[strlen(result)-1]; *p++ = '.'; *p++ = '0'; *p++ = '\0'; text_data[TEMP]->settext(result); }
void thinkpad_fan::end_measurement(void) { end_rate = read_sysfs("/sys/devices/platform/thinkpad_hwmon/fan1_input"); report_utilization("thinkpad-fan", utilization()); }
void thinkpad_fan::start_measurement(void) { /* read the rpms of the fan */ start_rate = read_sysfs("/sys/devices/platform/thinkpad_hwmon/fan1_input"); }
static int linuxDevPCIInit(void) { DIR* sysfsPci_dir=NULL; struct dirent* dir; int i; osdPCIDevice *osd=NULL; pciLock = epicsMutexMustCreate(); int host_is_first = 0; pagesize=sysconf(_SC_PAGESIZE); if (pagesize==-1) { perror("Failed to get pagesize"); goto fail; } sysfsPci_dir = opendir("/sys/bus/pci/devices"); if (!sysfsPci_dir){ fprintf(stderr, "Could not open /sys/bus/pci/devices!\n"); goto fail; } while ((dir=readdir(sysfsPci_dir))) { char* filename; FILE* file; int fail=0; int match; unsigned long long int start,stop,flags; char dname[80]; if (!dir->d_name || dir->d_name[0]=='.') continue; /* Skip invalid entries */ osd=calloc(1, sizeof(osdPCIDevice)); if (!osd) { errMessage(S_dev_noMemory, "Out of memory"); goto fail; } osd->fd=-1; osd->cfd = -1; for ( i=0; i<sizeof(osd->rfd)/sizeof(osd->rfd[0]); i++ ) osd->rfd[i] = -1; osd->dev.slot = DEVPCI_NO_SLOT; match = sscanf(dir->d_name,"%x:%x:%x.%x", &osd->dev.domain,&osd->dev.bus,&osd->dev.device,&osd->dev.function); if (match != 4){ fprintf(stderr, "Could not decode PCI device directory %s\n", dir->d_name); } osd->dev.id.vendor=read_sysfs(&fail, BUSBASE "vendor", osd->dev.domain, osd->dev.bus, osd->dev.device, osd->dev.function); osd->dev.id.device=read_sysfs(&fail, BUSBASE "device", osd->dev.domain, osd->dev.bus, osd->dev.device, osd->dev.function); osd->dev.id.sub_vendor=read_sysfs(&fail, BUSBASE "subsystem_vendor", osd->dev.domain, osd->dev.bus, osd->dev.device, osd->dev.function); osd->dev.id.sub_device=read_sysfs(&fail, BUSBASE "subsystem_device", osd->dev.domain, osd->dev.bus, osd->dev.device, osd->dev.function); osd->dev.id.pci_class=read_sysfs(&fail, BUSBASE "class", osd->dev.domain, osd->dev.bus, osd->dev.device, osd->dev.function); osd->dev.irq=read_sysfs(&fail, BUSBASE "irq", osd->dev.domain, osd->dev.bus, osd->dev.device, osd->dev.function); osd->dev.id.revision=0; if (fail) { fprintf(stderr, "Warning: Failed to read some attributes of PCI device %04x:%02x:%02x.%x\n" " This may cause some searches to fail\n", osd->dev.domain, osd->dev.bus, osd->dev.device, osd->dev.function); fail=0; } if(devPCIDebug>=1) { fprintf(stderr, "linuxDevPCIInit found %04x:%02x:%02x.%x\n", osd->dev.domain, osd->dev.bus, osd->dev.device, osd->dev.function); fprintf(stderr, " as pri %04x:%04x sub %04x:%04x cls %06x\n", osd->dev.id.vendor, osd->dev.id.device, osd->dev.id.sub_vendor, osd->dev.id.sub_device, osd->dev.id.pci_class); } /* Read BAR info */ /* Base address */ filename = allocPrintf(BUSBASE "resource", osd->dev.domain, osd->dev.bus, osd->dev.device, osd->dev.function); if (!filename) { errMessage(S_dev_noMemory, "Out of memory"); goto fail; } file=fopen(filename, "r"); if (!file) { fprintf(stderr, "Could not open resource file %s!\n", filename); free(filename); continue; } for (i=0; i<PCIBARCOUNT; i++) { /* read 6 BARs */ match = fscanf(file, "0x%16llx 0x%16llx 0x%16llx\n", &start, &stop, &flags); if (match != 3) { fprintf(stderr, "Could not parse line %i of %s\n", i+1, filename); continue; } osd->dev.bar[i].ioport = (flags & PCI_BASE_ADDRESS_SPACE)==PCI_BASE_ADDRESS_SPACE_IO; osd->dev.bar[i].below1M = !!(flags&PCI_BASE_ADDRESS_MEM_TYPE_1M); osd->dev.bar[i].addr64 = !!(flags&PCI_BASE_ADDRESS_MEM_TYPE_64); osd->displayBAR[i] = start; /* offset from start of page to start of BAR */ osd->offset[i] = osd->displayBAR[i]&(pagesize-1); /* region length */ osd->len[i] = (start || stop ) ? (stop - start + 1) : 0; } /* rom */ match = fscanf(file, "%llx %llx %llx\n", &start, &stop, &flags); if (match != 3) { fprintf(stderr, "Could not parse line %i of %s\n", i+1, filename); start = 0; stop = 0; } osd->displayErom = start; osd->eromlen = (start || stop ) ? (stop - start + 1) : 0; fclose(file); free(filename); /* driver name */ filename = allocPrintf(BUSBASE "driver", osd->dev.domain, osd->dev.bus, osd->dev.device, osd->dev.function); if (!filename) { errMessage(S_dev_noMemory, "Out of memory"); goto fail; } memset (dname, 0, sizeof(dname)); if (readlink(filename, dname, sizeof(dname)-1) != -1) osd->dev.driver = epicsStrDup(basename(dname)); free(filename); osd->devLock = epicsMutexMustCreate(); if (!ellCount(&devices)) { host_is_first = (osd->dev.bus == 0 && osd->dev.device == 0); } ellInsert(&devices,host_is_first?ellLast(&devices):NULL,&osd->node); osd=NULL; } if (sysfsPci_dir) closedir(sysfsPci_dir); sysfsPci_dir = opendir(linuxslotsdir); if (sysfsPci_dir){ while ((dir=readdir(sysfsPci_dir))) { unsigned dom, B, D; char *fullname; FILE *fp; if (!dir->d_name || dir->d_name[0]=='.') continue; /* Skip invalid entries */ if(devPCIDebug>4) fprintf(stderr, "examine /slots entry '%s'\n", dir->d_name); fullname = allocPrintf("%s/%s/address", linuxslotsdir, dir->d_name); if(!fullname) continue; if(devPCIDebug>3) fprintf(stderr, "found '%s'\n", fullname); if((fp=fopen(fullname, "r"))!=NULL) { if(fscanf(fp, "%x:%x:%x", &dom, &B, &D)==3) { ELLNODE *cur; if(devPCIDebug>2) fprintf(stderr, "found slot %s with %04u:%02u:%02u.*\n", dir->d_name, dom, B, D); for(cur=ellFirst(&devices); cur; cur=ellNext(cur)) { osdPCIDevice *osd = CONTAINER(cur, osdPCIDevice, node); if(osd->dev.domain!=dom || osd->dev.bus!=B || osd->dev.device!=D) continue; if(osd->dev.slot==DEVPCI_NO_SLOT) { osd->dev.slot = strdup(dir->d_name); // return NULL would mean slot remains unlabeled } else { fprintf(stderr, "Duplicate slot address for %s\n", dir->d_name); } } } fclose(fp); } free(fullname); } closedir(sysfsPci_dir); } else if(devPCIDebug>0) { fprintf(stderr, "/sys does not provide PCI slots listing\n"); } return 0; fail: if (sysfsPci_dir) closedir(sysfsPci_dir); epicsMutexDestroy(pciLock); return S_dev_badInit; }