a9da3307db733eb1739ba859952610bba3d894abnp/***************************************************************************
a9da3307db733eb1739ba859952610bba3d894abnp * devinfo_cpu : cpu devices
a9da3307db733eb1739ba859952610bba3d894abnp * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
a9da3307db733eb1739ba859952610bba3d894abnp * Use is subject to license terms.
a9da3307db733eb1739ba859952610bba3d894abnp * Licensed under the Academic Free License version 2.1
a9da3307db733eb1739ba859952610bba3d894abnp **************************************************************************/
a9da3307db733eb1739ba859952610bba3d894abnp#pragma ident "%Z%%M% %I% %E% SMI"
a9da3307db733eb1739ba859952610bba3d894abnp#include "../osspec.h"
a9da3307db733eb1739ba859952610bba3d894abnp#include "../logger.h"
a9da3307db733eb1739ba859952610bba3d894abnp#include "../hald.h"
a9da3307db733eb1739ba859952610bba3d894abnp#include "../hald_dbus.h"
a9da3307db733eb1739ba859952610bba3d894abnp#include "../device_info.h"
a9da3307db733eb1739ba859952610bba3d894abnp#include "../util.h"
a9da3307db733eb1739ba859952610bba3d894abnpstatic HalDevice *devinfo_cpu_add(HalDevice *, di_node_t, char *, char *);
a9da3307db733eb1739ba859952610bba3d894abnpdevinfo_cpu_add(HalDevice *parent, di_node_t node, char *devfs_path, char *device_type)
a9da3307db733eb1739ba859952610bba3d894abnp * If it is x86, the software device tree node will have the
a9da3307db733eb1739ba859952610bba3d894abnp * device_type information which is the one passed above. If it is
a9da3307db733eb1739ba859952610bba3d894abnp * NULL, check if the node has a PROM entry, and check the device_type
a9da3307db733eb1739ba859952610bba3d894abnp * in case of sparc. Else return NULL
a9da3307db733eb1739ba859952610bba3d894abnp * Check the device type if it has a PROM entry. Because
a9da3307db733eb1739ba859952610bba3d894abnp * in sparc, the device_type entry will in the PROM node
a9da3307db733eb1739ba859952610bba3d894abnp "handle to find cpu device: %s",
a9da3307db733eb1739ba859952610bba3d894abnp * Get cpuid if available
a9da3307db733eb1739ba859952610bba3d894abnp * There is no cpuid entry in this arch.Just
a9da3307db733eb1739ba859952610bba3d894abnp * increment the cpuid which will be the
a9da3307db733eb1739ba859952610bba3d894abnp * current instance
a9da3307db733eb1739ba859952610bba3d894abnp * This is a x86 arch, because software device tree node
a9da3307db733eb1739ba859952610bba3d894abnp * has the device_type entry for cpu. The "reg" property
a9da3307db733eb1739ba859952610bba3d894abnp * will have the cpuid. If not just increment the cpuid
a9da3307db733eb1739ba859952610bba3d894abnp * which will be the current cpu instance in the kstat
a9da3307db733eb1739ba859952610bba3d894abnp * There is no cpuid entry in this arch. Just
a9da3307db733eb1739ba859952610bba3d894abnp * increment the cpuid which will be the
a9da3307db733eb1739ba859952610bba3d894abnp * current instance
a9da3307db733eb1739ba859952610bba3d894abnp * devinfo_set_default_properties () uses di_instance() as part of
a9da3307db733eb1739ba859952610bba3d894abnp * the udi. For some solaris devices like cpu di_instance() is not
a9da3307db733eb1739ba859952610bba3d894abnp * present and it returns -1. For the udi to be unique can use the
a9da3307db733eb1739ba859952610bba3d894abnp * If cpu driver is not installed, then devfs_path returned by
a9da3307db733eb1739ba859952610bba3d894abnp * libdevinfo will be same for all cpu's.
a9da3307db733eb1739ba859952610bba3d894abnp * Since HAL stores the devices in its tree based on the devfs_path,
a9da3307db733eb1739ba859952610bba3d894abnp * To make it unique, will be concatenating devfs_path with cpu_id
a9da3307db733eb1739ba859952610bba3d894abnp snprintf (cpu_devfs_path, HAL_PATH_MAX, "%s", devfs_path);
a9da3307db733eb1739ba859952610bba3d894abnp HAL_DEBUG(("DevfsPath=> %s, CPUID=> %d", cpu_devfs_path, cpu_id));
a9da3307db733eb1739ba859952610bba3d894abnp hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi),
a9da3307db733eb1739ba859952610bba3d894abnp "/org/freedesktop/Hal/devices%s_%d", cpu_devfs_path, cpu_id);
a9da3307db733eb1739ba859952610bba3d894abnp if (di_prop_lookup_strings (DDI_DEV_T_ANY, node, "model", &s) > 0) {
a9da3307db733eb1739ba859952610bba3d894abnp hal_device_property_set_string (d, "info.solaris.driver",
a9da3307db733eb1739ba859952610bba3d894abnp hal_device_property_set_int (d, "processor.number", cpu_id);
a9da3307db733eb1739ba859952610bba3d894abnp * Get the cpu related info from the kstat
a9da3307db733eb1739ba859952610bba3d894abnp HAL_ERROR (("Could not lookup kstat to get cpu info: %s",
a9da3307db733eb1739ba859952610bba3d894abnp ksdata = (kstat_named_t *)kstat_data_lookup (ksp, "clock_MHz");
a9da3307db733eb1739ba859952610bba3d894abnp HAL_ERROR (("Could not get kstat clock_MHz data for cpu: %s",
a9da3307db733eb1739ba859952610bba3d894abnp if (hal_device_property_set_uint64 (d, "processor.maximum_speed",
a9da3307db733eb1739ba859952610bba3d894abnp HAL_INFO (("Could not set the processor speed device prop"));
a9da3307db733eb1739ba859952610bba3d894abnp "supported_frequencies_Hz");
a9da3307db733eb1739ba859952610bba3d894abnp HAL_INFO (("Could not get kstat supported_frequencies_Hz data"
a9da3307db733eb1739ba859952610bba3d894abnp * If more than one freq is supported, then they are seperated
a9da3307db733eb1739ba859952610bba3d894abnp * by a ":"
a9da3307db733eb1739ba859952610bba3d894abnp if (hal_device_property_set_bool (d, "processor.can_throttle",
a9da3307db733eb1739ba859952610bba3d894abnp " device prop"));
a9da3307db733eb1739ba859952610bba3d894abnp devinfo_add_enqueue (d, cpu_devfs_path, &devinfo_cpu_handler);
a9da3307db733eb1739ba859952610bba3d894abnp return (d);