- adl_main_control_create = (ADL_MAIN_CONTROL_CREATE)
- getprocaddress(hdll, "ADL_Main_Control_Create");
- adl_main_control_destroy = (ADL_MAIN_CONTROL_DESTROY)
- getprocaddress(hdll, "ADL_Main_Control_Destroy");
- adl_adapter_numberofadapters_get = (ADL_ADAPTER_NUMBEROFADAPTERS_GET)
- getprocaddress(hdll, "ADL_Adapter_NumberOfAdapters_Get");
- adl_adapter_adapterinfo_get = (ADL_ADAPTER_ADAPTERINFO_GET)
- getprocaddress(hdll, "ADL_Adapter_AdapterInfo_Get");
- adl_adapter_active_get = (ADL_ADAPTER_ACTIVE_GET)
- getprocaddress(hdll, "ADL_Adapter_Active_Get");
- adl_overdrive5_temperature_get = (ADL_OVERDRIVE5_TEMPERATURE_GET)
- getprocaddress(hdll, "ADL_Overdrive5_Temperature_Get");
- adl_overdrive5_fanspeed_get = (ADL_OVERDRIVE5_FANSPEED_GET)
- getprocaddress(hdll, "ADL_Overdrive5_FanSpeed_Get");
- if (!adl_main_control_create ||
- !adl_main_control_destroy ||
- !adl_adapter_numberofadapters_get ||
- !adl_adapter_adapterinfo_get ||
- !adl_overdrive5_temperature_get ||
- !adl_overdrive5_fanspeed_get) {
- fprintf(stderr,
- _("ERROR: ADL's API is missing!\n"));
- return 0;
- }
-
- /* Initialize ADL. The second parameter is 1, which means:
- retrieve adapter information only for adapters that
- are physically present and enabled in the system */
- if (ADL_OK != adl_main_control_create(adl_main_memory_alloc, 1)) {
- fprintf(stderr,
- _("ERROR: ADL Initialization Error!\n"));
- return 0;
- }
- adl_main_control_done = 1;
-
- /* Obtain the number of adapters for the system */
- if (ADL_OK != adl_adapter_numberofadapters_get(&inumberadapters)) {
- fprintf(stderr,
- _("ERROR: Cannot get the number of adapters!\n"));
- return 0;
- }
-
- if (!inumberadapters)
- return 0;
-
- lpadapterinfo = malloc(sizeof(AdapterInfo) * inumberadapters);
- memset(lpadapterinfo, '\0', sizeof(AdapterInfo) * inumberadapters);
-
- /* Get the AdapterInfo structure for all adapters in the system */
- adl_adapter_adapterinfo_get(lpadapterinfo,
- sizeof(AdapterInfo) * inumberadapters);
-
- /* Repeat for all available adapters in the system */
- for (i = 0; i < inumberadapters; i++) {
- iadapterindex = lpadapterinfo[i].iAdapterIndex;
- if (ADL_OK != adl_adapter_active_get(iadapterindex, &lpstatus))
- continue;
- if (lpstatus != ADL_TRUE)
- /* count only if the adapter is active */
- continue;
-
- if (!active_amd_adapters) {
- active_amd_adapters = (int *) malloc(sizeof(int));
- inumberadaptersactive = 1;
- } else {
- ++inumberadaptersactive;
- active_amd_adapters =
- (int *) realloc(active_amd_adapters,
- sizeof(int)*inumberadaptersactive);
- }
- active_amd_adapters[inumberadaptersactive-1] = iadapterindex;
- }
-
- adl_main_memory_free((void **) &lpadapterinfo);
-
- /* Each Adapter has one GPU temperature
- sensor and one fan control sensor */
- return 2*inumberadaptersactive;
-}
-
-void amd_psensor_list_update(struct psensor **sensors)
-{
- struct psensor **ss, *s;
-
- ss = sensors;
- while (*ss) {
- s = *ss;
-
- if (s->type == SENSOR_TYPE_AMD_TEMP)
- psensor_set_current_value(s, get_temp(s));
- else if (s->type == SENSOR_TYPE_AMD_FAN)
- psensor_set_current_value(s, get_fanspeed(s));
-
- ss++;
- }
-}
-
-struct psensor * *
-amd_psensor_list_add(struct psensor **sensors, int values_len)
-{
- int i, n;
- struct psensor **tmp, **ss, *s;
-
- n = init();
-
- ss = sensors;
- for (i = 0; i < n; i++) {
- s = create_sensor(i, values_len);
-
- tmp = psensor_list_add(ss, s);
-
- if (ss != tmp)
- free(ss);
-
- ss = tmp;
- }
-
- if (active_amd_adapters) {
- free(active_amd_adapters);
- active_amd_adapters = NULL;
- }
-
- return ss;
-}
-
-void amd_cleanup()
-{
- if (hdll) {
- if (adl_main_control_done)
- adl_main_control_destroy();
- dlclose(hdll);
- }
- if (active_amd_adapters) {
- free(active_amd_adapters);
- active_amd_adapters = NULL;
- }
-}