summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTomas Smetana <tsmetana@redhat.com>2013-01-15 09:51:45 +0100
committerTomas Smetana <tsmetana@redhat.com>2013-01-15 09:51:45 +0100
commit28e0f4e9c2dc3611a177adee36ac9a82ca461369 (patch)
tree1df7b04ab97c7575b0e0b63a908344d76709fecc
parente2f7cec35373782817e161ec988922a577dd2da6 (diff)
parent93d359d202c0f930afa6544f81441cc05080bd12 (diff)
downloadopenlmi-providers-28e0f4e9c2dc3611a177adee36ac9a82ca461369.tar.gz
openlmi-providers-28e0f4e9c2dc3611a177adee36ac9a82ca461369.tar.xz
openlmi-providers-28e0f4e9c2dc3611a177adee36ac9a82ca461369.zip
New provider: hardware
-rw-r--r--CMakeLists.txt1
-rw-r--r--mof/LMI_Hardware.mof35
-rw-r--r--src/CMakeLists.txt4
-rw-r--r--src/hardware/CMakeLists.txt31
-rw-r--r--src/hardware/LMI_PCIDeviceProvider.c371
5 files changed, 442 insertions, 0 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index e44fd76..bf94319 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -16,6 +16,7 @@ option(WITH-FAN "Build fan provider" ON)
option(WITH-POWER "Build power provider" ON)
option(WITH-SERVICE "Build service provider" ON)
option(WITH-ACCOUNT "Build account provider" ON)
+option(WITH-HARDWARE "Build hardware provider" ON)
# Set path to custom cmake modules
set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules ${CMAKE_MODULE_PATH})
diff --git a/mof/LMI_Hardware.mof b/mof/LMI_Hardware.mof
new file mode 100644
index 0000000..87d5741
--- /dev/null
+++ b/mof/LMI_Hardware.mof
@@ -0,0 +1,35 @@
+/*
+ * Copyright (C) 2013 Red Hat, Inc. All rights reserved.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * Authors: Tomas Smetana <tsmetana@redhat.com>
+ */
+
+[ Provider("cmpi:cmpiLMI_PCIDevice") ]
+class LMI_PCIDevice: CIM_PCIDevice
+{
+ [ Description("Name of the subsystem") ]
+ string SubsystemName;
+
+ [ Description("Name of the subsystem vendor") ]
+ string SubsystemVendorName;
+
+ [ Description("Name of the device") ]
+ string PCIDeviceName;
+
+ [ Description("Name of the vendor") ]
+ string VendorName;
+};
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index ff3bf58..6d41f49 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -24,3 +24,7 @@ endif (WITH-SERVICE)
if (WITH-ACCOUNT)
add_subdirectory(account)
endif (WITH-ACCOUNT)
+
+if (WITH-HARDWARE)
+ add_subdirectory(hardware)
+endif (WITH-HARDWARE)
diff --git a/src/hardware/CMakeLists.txt b/src/hardware/CMakeLists.txt
new file mode 100644
index 0000000..073b076
--- /dev/null
+++ b/src/hardware/CMakeLists.txt
@@ -0,0 +1,31 @@
+
+set(PROVIDER_NAME Hardware)
+set(LIBRARY_NAME cmpiLMI_${PROVIDER_NAME})
+set(MOF LMI_Hardware.mof)
+
+#set(provider_SRCS
+# util/serviceutil.c
+#)
+
+konkretcmpi_generate(${MOF}
+ CIM_PROVIDERS
+ CIM_HEADERS
+)
+
+add_library(${LIBRARY_NAME} SHARED
+ ${provider_SRCS}
+ ${CIM_PROVIDERS}
+ ${CIM_HEADERS}
+)
+
+pkg_check_modules(LIBPCI REQUIRED libpci)
+
+include_directories(${CMAKE_CURRENT_BINARY_DIR} ${CMPI_INCLUDE_DIR} ${LIBPCI_INCLUDE_DIR})
+target_link_libraries(${LIBRARY_NAME} openlmicommon ${KONKRETCMPI_LIBRARIES} ${LIBPCI_LIBRARIES})
+
+# Create registration file
+cim_registration(${PROVIDER_NAME} ${LIBRARY_NAME} ${MOF} share/openlmi-providers)
+
+install(PROGRAMS util/servicedisc.sh util/serviceutil.sh DESTINATION libexec)
+
+install(TARGETS ${LIBRARY_NAME} DESTINATION lib${LIB_SUFFIX}/cmpi)
diff --git a/src/hardware/LMI_PCIDeviceProvider.c b/src/hardware/LMI_PCIDeviceProvider.c
new file mode 100644
index 0000000..e879484
--- /dev/null
+++ b/src/hardware/LMI_PCIDeviceProvider.c
@@ -0,0 +1,371 @@
+/*
+ * Copyright (C) 2013 Red Hat, Inc. All rights reserved.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * Authors: Tomas Smetana <tsmetana@redhat.com>
+ *
+ */
+#include <konkret/konkret.h>
+#include <pci/pci.h>
+
+#include "globals.h"
+#include "LMI_PCIDevice.h"
+
+static const CMPIBroker* _cb = NULL;
+
+static void get_subid(struct pci_dev *d, u16 *subvp, u16 *subdp)
+{
+ u8 htype = pci_read_byte(d, PCI_HEADER_TYPE) & 0x7f;
+
+ if (htype == PCI_HEADER_TYPE_NORMAL) {
+ *subvp = pci_read_word(d, PCI_SUBSYSTEM_VENDOR_ID);
+ *subdp = pci_read_word(d, PCI_SUBSYSTEM_ID);
+ } else if (htype == PCI_HEADER_TYPE_CARDBUS) {
+ *subvp = pci_read_word(d, PCI_CB_SUBSYSTEM_VENDOR_ID);
+ *subdp = pci_read_word(d, PCI_CB_SUBSYSTEM_ID);
+ } else
+ *subvp = *subdp = 0xffff;
+}
+
+static void LMI_PCIDeviceInitialize()
+{
+}
+
+static CMPIStatus LMI_PCIDeviceCleanup(
+ CMPIInstanceMI* mi,
+ const CMPIContext* cc,
+ CMPIBoolean term)
+{
+ CMReturn(CMPI_RC_OK);
+}
+
+static CMPIStatus LMI_PCIDeviceEnumInstanceNames(
+ CMPIInstanceMI* mi,
+ const CMPIContext* cc,
+ const CMPIResult* cr,
+ const CMPIObjectPath* cop)
+{
+ return KDefaultEnumerateInstanceNames(_cb, mi, cc, cr, cop);
+}
+
+#define NAME_BUF_SIZE 128
+#define PCI_DEVID_STR_SIZE 9
+static CMPIStatus LMI_PCIDeviceEnumInstances(
+ CMPIInstanceMI* mi,
+ const CMPIContext* cc,
+ const CMPIResult* cr,
+ const CMPIObjectPath* cop,
+ const char** properties)
+{
+ struct pci_access *acc;
+ struct pci_dev *dev;
+ struct pci_cap *cap;
+ int i;
+ u16 subid, svid;
+ char vendor_buf[NAME_BUF_SIZE], *vendor_name;
+ char device_buf[NAME_BUF_SIZE], *device_name;
+ char subsys_buf[NAME_BUF_SIZE], *subsys_name;
+ char svendor_buf[NAME_BUF_SIZE], *svendor_name;
+ char device_id_str[PCI_DEVID_STR_SIZE];
+ LMI_PCIDevice lmi_dev;
+ const char *ns = KNameSpace(cop);
+
+ if (!(acc = pci_alloc()))
+ KReturn2(_cb, ERR_FAILED, "Error accessing the PCI bus");
+ pci_init(acc);
+ pci_scan_bus(acc);
+
+ for (dev = acc->devices; dev; dev = dev->next) {
+ pci_fill_info(dev,
+ PCI_FILL_IDENT
+ | PCI_FILL_IRQ
+ | PCI_FILL_BASES
+ | PCI_FILL_ROM_BASE
+ | PCI_FILL_CLASS
+ | PCI_FILL_CAPS);
+
+ vendor_name = pci_lookup_name(acc, vendor_buf, NAME_BUF_SIZE,
+ PCI_LOOKUP_VENDOR, dev->vendor_id);
+ device_name = pci_lookup_name(acc, device_buf, NAME_BUF_SIZE,
+ PCI_LOOKUP_DEVICE, dev->vendor_id, dev->device_id);
+ get_subid(dev, &svid, &subid);
+ subsys_name = pci_lookup_name(acc, subsys_buf, NAME_BUF_SIZE,
+ PCI_LOOKUP_DEVICE | PCI_LOOKUP_SUBSYSTEM,
+ dev->vendor_id, dev->device_id, svid, subid);
+ svendor_name = pci_lookup_name(acc, svendor_buf, NAME_BUF_SIZE,
+ PCI_LOOKUP_VENDOR | PCI_LOOKUP_SUBSYSTEM, svid);
+
+ LMI_PCIDevice_Init(&lmi_dev, _cb, ns);
+ LMI_PCIDevice_Set_CreationClassName(&lmi_dev, "LMI_PCIDevice");
+ LMI_PCIDevice_Set_SystemCreationClassName(&lmi_dev,
+ get_system_creation_class_name());
+ LMI_PCIDevice_Set_SystemName(&lmi_dev, get_system_name());
+ snprintf((char *)&device_id_str, PCI_DEVID_STR_SIZE, "%d:%d.%d",
+ dev->bus, dev->dev, dev->func);
+ LMI_PCIDevice_Set_DeviceID(&lmi_dev, device_id_str);
+ LMI_PCIDevice_Set_BusNumber(&lmi_dev, dev->bus);
+ LMI_PCIDevice_Set_DeviceNumber(&lmi_dev, dev->dev);
+ LMI_PCIDevice_Set_FunctionNumber(&lmi_dev, dev->func);
+ LMI_PCIDevice_Set_VendorID(&lmi_dev, dev->vendor_id);
+ LMI_PCIDevice_Set_PCIDeviceID(&lmi_dev, dev->device_id);
+ LMI_PCIDevice_Set_PCIDeviceName(&lmi_dev, device_name);
+ LMI_PCIDevice_Set_SubsystemID(&lmi_dev, subid);
+ LMI_PCIDevice_Set_SubsystemVendorID(&lmi_dev, svid);
+ /* Throw away the lower 8 bits denoting the subclass */
+ LMI_PCIDevice_Set_ClassCode(&lmi_dev, ((dev->device_class) >> 8));
+ if (dev->rom_base_addr)
+ LMI_PCIDevice_Set_ExpansionROMBaseAddress(&lmi_dev,
+ dev->rom_base_addr);
+ if (vendor_name)
+ LMI_PCIDevice_Set_VendorName(&lmi_dev, vendor_name);
+ if (subsys_name)
+ LMI_PCIDevice_Set_SubsystemName(&lmi_dev, subsys_name);
+ if (svendor_name)
+ LMI_PCIDevice_Set_SubsystemVendorName(&lmi_dev, svendor_name);
+ for (i = 0; i < 6; i++)
+ if (dev->base_addr[i]) {
+#ifdef PCI_HAVE_64BIT_ADDRESS
+ LMI_PCIDevice_Set_BaseAddress64(&lmi_dev, i, dev->base_addr[i]);
+#else
+ LMI_PCIDevice_Set_BaseAddress(&lmi_dev, i, dev->base_addr[i]);
+#endif
+ }
+ for (cap = dev->first_cap, i = 0; cap; cap = cap->next, i++) {
+ LMI_PCIDevice_Set_Capabilities(&lmi_dev, i, cap->type);
+ }
+ KReturnInstance(cr, lmi_dev);
+ }
+
+ pci_cleanup(acc);
+
+ CMReturn(CMPI_RC_OK);
+}
+
+static CMPIStatus LMI_PCIDeviceGetInstance(
+ CMPIInstanceMI* mi,
+ const CMPIContext* cc,
+ const CMPIResult* cr,
+ const CMPIObjectPath* cop,
+ const char** properties)
+{
+ return KDefaultGetInstance(
+ _cb, mi, cc, cr, cop, properties);
+}
+
+static CMPIStatus LMI_PCIDeviceCreateInstance(
+ CMPIInstanceMI* mi,
+ const CMPIContext* cc,
+ const CMPIResult* cr,
+ const CMPIObjectPath* cop,
+ const CMPIInstance* ci)
+{
+ CMReturn(CMPI_RC_ERR_NOT_SUPPORTED);
+}
+
+static CMPIStatus LMI_PCIDeviceModifyInstance(
+ CMPIInstanceMI* mi,
+ const CMPIContext* cc,
+ const CMPIResult* cr,
+ const CMPIObjectPath* cop,
+ const CMPIInstance* ci,
+ const char** properties)
+{
+ CMReturn(CMPI_RC_ERR_NOT_SUPPORTED);
+}
+
+static CMPIStatus LMI_PCIDeviceDeleteInstance(
+ CMPIInstanceMI* mi,
+ const CMPIContext* cc,
+ const CMPIResult* cr,
+ const CMPIObjectPath* cop)
+{
+ CMReturn(CMPI_RC_ERR_NOT_SUPPORTED);
+}
+
+static CMPIStatus LMI_PCIDeviceExecQuery(
+ CMPIInstanceMI* mi,
+ const CMPIContext* cc,
+ const CMPIResult* cr,
+ const CMPIObjectPath* cop,
+ const char* lang,
+ const char* query)
+{
+ CMReturn(CMPI_RC_ERR_NOT_SUPPORTED);
+}
+
+CMInstanceMIStub(
+ LMI_PCIDevice,
+ LMI_PCIDevice,
+ _cb,
+ LMI_PCIDeviceInitialize())
+
+static CMPIStatus LMI_PCIDeviceMethodCleanup(
+ CMPIMethodMI* mi,
+ const CMPIContext* cc,
+ CMPIBoolean term)
+{
+ CMReturn(CMPI_RC_OK);
+}
+
+static CMPIStatus LMI_PCIDeviceInvokeMethod(
+ CMPIMethodMI* mi,
+ const CMPIContext* cc,
+ const CMPIResult* cr,
+ const CMPIObjectPath* cop,
+ const char* meth,
+ const CMPIArgs* in,
+ CMPIArgs* out)
+{
+ return LMI_PCIDevice_DispatchMethod(
+ _cb, mi, cc, cr, cop, meth, in, out);
+}
+
+CMMethodMIStub(
+ LMI_PCIDevice,
+ LMI_PCIDevice,
+ _cb,
+ LMI_PCIDeviceInitialize())
+
+KUint32 LMI_PCIDevice_RequestStateChange(
+ const CMPIBroker* cb,
+ CMPIMethodMI* mi,
+ const CMPIContext* context,
+ const LMI_PCIDeviceRef* self,
+ const KUint16* RequestedState,
+ KRef* Job,
+ const KDateTime* TimeoutPeriod,
+ CMPIStatus* status)
+{
+ KUint32 result = KUINT32_INIT;
+
+ KSetStatus(status, ERR_NOT_SUPPORTED);
+ return result;
+}
+
+KUint32 LMI_PCIDevice_SetPowerState(
+ const CMPIBroker* cb,
+ CMPIMethodMI* mi,
+ const CMPIContext* context,
+ const LMI_PCIDeviceRef* self,
+ const KUint16* PowerState,
+ const KDateTime* Time,
+ CMPIStatus* status)
+{
+ KUint32 result = KUINT32_INIT;
+
+ KSetStatus(status, ERR_NOT_SUPPORTED);
+ return result;
+}
+
+KUint32 LMI_PCIDevice_Reset(
+ const CMPIBroker* cb,
+ CMPIMethodMI* mi,
+ const CMPIContext* context,
+ const LMI_PCIDeviceRef* self,
+ CMPIStatus* status)
+{
+ KUint32 result = KUINT32_INIT;
+
+ KSetStatus(status, ERR_NOT_SUPPORTED);
+ return result;
+}
+
+KUint32 LMI_PCIDevice_EnableDevice(
+ const CMPIBroker* cb,
+ CMPIMethodMI* mi,
+ const CMPIContext* context,
+ const LMI_PCIDeviceRef* self,
+ const KBoolean* Enabled,
+ CMPIStatus* status)
+{
+ KUint32 result = KUINT32_INIT;
+
+ KSetStatus(status, ERR_NOT_SUPPORTED);
+ return result;
+}
+
+KUint32 LMI_PCIDevice_OnlineDevice(
+ const CMPIBroker* cb,
+ CMPIMethodMI* mi,
+ const CMPIContext* context,
+ const LMI_PCIDeviceRef* self,
+ const KBoolean* Online,
+ CMPIStatus* status)
+{
+ KUint32 result = KUINT32_INIT;
+
+ KSetStatus(status, ERR_NOT_SUPPORTED);
+ return result;
+}
+
+KUint32 LMI_PCIDevice_QuiesceDevice(
+ const CMPIBroker* cb,
+ CMPIMethodMI* mi,
+ const CMPIContext* context,
+ const LMI_PCIDeviceRef* self,
+ const KBoolean* Quiesce,
+ CMPIStatus* status)
+{
+ KUint32 result = KUINT32_INIT;
+
+ KSetStatus(status, ERR_NOT_SUPPORTED);
+ return result;
+}
+
+KUint32 LMI_PCIDevice_SaveProperties(
+ const CMPIBroker* cb,
+ CMPIMethodMI* mi,
+ const CMPIContext* context,
+ const LMI_PCIDeviceRef* self,
+ CMPIStatus* status)
+{
+ KUint32 result = KUINT32_INIT;
+
+ KSetStatus(status, ERR_NOT_SUPPORTED);
+ return result;
+}
+
+KUint32 LMI_PCIDevice_RestoreProperties(
+ const CMPIBroker* cb,
+ CMPIMethodMI* mi,
+ const CMPIContext* context,
+ const LMI_PCIDeviceRef* self,
+ CMPIStatus* status)
+{
+ KUint32 result = KUINT32_INIT;
+
+ KSetStatus(status, ERR_NOT_SUPPORTED);
+ return result;
+}
+
+KUint8 LMI_PCIDevice_BISTExecution(
+ const CMPIBroker* cb,
+ CMPIMethodMI* mi,
+ const CMPIContext* context,
+ const LMI_PCIDeviceRef* self,
+ CMPIStatus* status)
+{
+ KUint8 result = KUINT8_INIT;
+
+ KSetStatus(status, ERR_NOT_SUPPORTED);
+ return result;
+}
+
+KONKRET_REGISTRATION(
+ "root/cimv2",
+ "LMI_PCIDevice",
+ "LMI_PCIDevice",
+ "instance method")