Ejemplo n.º 1
0
int
ipmi_locate_pci_get_device_info (ipmi_locate_ctx_t ctx,
                                 ipmi_interface_type_t type,
                                 struct ipmi_locate_info *info)
{
  if (!ctx || ctx->magic != IPMI_LOCATE_CTX_MAGIC)
    {
      ERR_TRACE (ipmi_locate_ctx_errormsg (ctx), ipmi_locate_ctx_errnum (ctx));
      return (-1);
    }

  if (!IPMI_INTERFACE_TYPE_VALID (type) || !info)
    {
      LOCATE_SET_ERRNUM (ctx, IPMI_LOCATE_ERR_PARAMETERS);
      return (-1);
    }

  LOCATE_SET_ERRNUM (ctx, IPMI_LOCATE_ERR_SYSTEM_ERROR);
  return (-1);
}
Ejemplo n.º 2
0
static void
defaults_display (ipmi_locate_ctx_t ctx)
{
  struct ipmi_locate_info info;

  assert (ctx);

  printf ("KCS device default values: ");
  if (!ipmi_locate_defaults_get_device_info (ctx,
                                             IPMI_INTERFACE_KCS,
                                             &info))
    {
      printf ("\n");
      display_ipmi_locate_info (&info);
    }
  else
    {
      if (ipmi_locate_ctx_errnum (ctx) == IPMI_LOCATE_ERR_SYSTEM_ERROR)
        printf ("FAILED\n");
      else
        printf ("ERROR: %s\n", ipmi_locate_ctx_errormsg (ctx));
    }
  printf ("\n");

  printf ("SMIC device default values: ");
  if (!ipmi_locate_defaults_get_device_info (ctx,
                                             IPMI_INTERFACE_SMIC,
                                             &info))
    {
      printf ("\n");
      display_ipmi_locate_info (&info);
    }
  else
    {
      if (ipmi_locate_ctx_errnum (ctx) == IPMI_LOCATE_ERR_SYSTEM_ERROR)
        printf ("FAILED\n");
      else
        printf ("ERROR: %s\n", ipmi_locate_ctx_errormsg (ctx));
    }
  printf ("\n");

#if 0

  /* Default values of BT not known, this will always fail */

  printf ("BT device default values: ");
  if (!ipmi_locate_defaults_get_device_info (ctx,
                                             IPMI_INTERFACE_BT,
                                             &info))
    {
      printf ("\n");
      display_ipmi_locate_info (&info);
    }
  else
    {
      if (ipmi_locate_ctx_errnum (ctx) == IPMI_LOCATE_ERR_SYSTEM_ERROR)
        printf ("FAILED\n");
      else
        printf ("ERROR: %s\n", ipmi_locate_ctx_errormsg (ctx));
    }
  printf ("\n");
#else /* !0 */

  printf ("BT device default values: ");
  printf ("\n");

#endif  /* !0 */

  printf ("SSIF device default values: ");
  if (!ipmi_locate_defaults_get_device_info (ctx,
                                             IPMI_INTERFACE_SSIF,
                                             &info))
    {
      printf ("\n");
      display_ipmi_locate_info (&info);
    }
  else
    {
      if (ipmi_locate_ctx_errnum (ctx) == IPMI_LOCATE_ERR_SYSTEM_ERROR)
        printf ("FAILED\n");
      else
        printf ("ERROR: %s\n", ipmi_locate_ctx_errormsg (ctx));
    }
  printf ("\n");
  return;
}
Ejemplo n.º 3
0
int
ipmi_locate_pci_get_device_info (ipmi_locate_ctx_t ctx,
                                 ipmi_interface_type_t type,
                                 struct ipmi_locate_info *info)
{
  unsigned dfn;
  unsigned vendor;
  unsigned bus;
  unsigned dev;
  unsigned func;
  unsigned irq;
  uint64_t base_address[6];
  char buf[512];
  FILE* fp_devices;
  int items;
  unsigned int i;
  struct ipmi_locate_info linfo;
  int rv = -1;

  if (!ctx || ctx->magic != IPMI_LOCATE_CTX_MAGIC)
    {
      ERR_TRACE (ipmi_locate_ctx_errormsg (ctx), ipmi_locate_ctx_errnum (ctx));
      return (-1);
    }

  if (!IPMI_INTERFACE_TYPE_VALID (type) || !info)
    {
      LOCATE_SET_ERRNUM (ctx, IPMI_LOCATE_ERR_PARAMETERS);
      return (-1);
    }

  memset (&linfo, '\0', sizeof (struct ipmi_locate_info));
  linfo.interface_type = type;
  if (type == IPMI_INTERFACE_SSIF)
    {
      strncpy (linfo.driver_device, IPMI_DEFAULT_I2C_DEVICE, IPMI_LOCATE_PATH_MAX);
      linfo.driver_device[IPMI_LOCATE_PATH_MAX - 1] = '\0';
    }

  if (!(fp_devices = fopen ("/proc/bus/pci/devices", "r")))
    {
      LOCATE_ERRNO_TO_LOCATE_ERRNUM (ctx, errno);
      goto cleanup;
    }

  while (fgets (buf, sizeof (buf), fp_devices) != NULL)
    {
      pci_class_regs_t regs;
      
      items = sscanf (buf, "%x %x %x " FORMAT_X64 " " FORMAT_X64 " " FORMAT_X64 " " FORMAT_X64 " " FORMAT_X64 " " FORMAT_X64,
                      &dfn, &vendor, &irq,
                      &base_address[0], &base_address[1], &base_address[2], &base_address[3], &base_address[4], &base_address[5]);
      linfo.intr_num = (uint16_t)irq;
      
      if (items != 9)
        {
          LOCATE_SET_ERRNUM (ctx, IPMI_LOCATE_ERR_SYSTEM_ERROR);
          goto cleanup;
        }
      bus = dfn >> 8U;
      dev = PCI_SLOT (dfn & 0xff);
      func = PCI_FUNC (dfn & 0xff);
      
      if (_pci_get_regs (ctx, bus, dev, func, &regs) < 0)
        goto cleanup;
      
      if (regs.pci_class != IPMI_CLASS ||
          regs.pci_subclass != IPMI_SUBCLASS ||
          regs.pci_prog_interface + 1 != type)
        continue;
      
      for (i = 0; i < 6; i++)
        {
          if (base_address[i] == 0 || base_address[i] == ~0)
            continue;
          
          switch (base_address[i] & PCI_BASE_ADDRESS_SPACE)
            {
            case past_io:
              linfo.address_space_id = IPMI_ADDRESS_SPACE_ID_SYSTEM_MEMORY;
              linfo.driver_address = base_address[i] & ~PCI_BASE_ADDRESS_IO_MASK;
              memcpy (info, &linfo, sizeof (struct ipmi_locate_info));
              rv = 0;
              goto cleanup;
              
            case past_memory:
              linfo.address_space_id = IPMI_ADDRESS_SPACE_ID_SYSTEM_IO;
              linfo.driver_address = base_address[i] & ~PCI_BASE_ADDRESS_MEM_MASK;
              memcpy (info, &linfo, sizeof (struct ipmi_locate_info));
              rv = 0;
              goto cleanup;
            }
      }
  }

 cleanup:
  if (fp_devices)
    fclose (fp_devices);
  return (rv);
}
Ejemplo n.º 4
0
static void
pci_probe_display (ipmi_locate_ctx_t ctx)
{
  struct ipmi_locate_info info;

  assert (ctx);

  printf ("Probing KCS device using PCI... ");
  if (!ipmi_locate_pci_get_device_info (ctx,
                                        IPMI_INTERFACE_KCS,
                                        &info))
    {
      printf ("done\n");
      display_ipmi_locate_info (&info);
    }
  else
    {
      if (ipmi_locate_ctx_errnum (ctx) == IPMI_LOCATE_ERR_SYSTEM_ERROR)
        printf ("FAILED\n");
      else
        printf ("ERROR: %s\n", ipmi_locate_ctx_errormsg (ctx));
    }
  printf ("\n");

  printf ("Probing SMIC device using PCI... ");
  if (!ipmi_locate_pci_get_device_info (ctx,
                                        IPMI_INTERFACE_SMIC,
                                        &info))
    {
      printf ("done\n");
      display_ipmi_locate_info (&info);
    }
  else
    {
      if (ipmi_locate_ctx_errnum (ctx) == IPMI_LOCATE_ERR_SYSTEM_ERROR)
        printf ("FAILED\n");
      else
        printf ("ERROR: %s\n", ipmi_locate_ctx_errormsg (ctx));
    }
  printf ("\n");

  printf ("Probing BT device using PCI... ");
  if (!ipmi_locate_pci_get_device_info (ctx,
                                        IPMI_INTERFACE_BT,
                                        &info))
    {
      printf ("done\n");
      display_ipmi_locate_info (&info);
    }
  else
    {
      if (ipmi_locate_ctx_errnum (ctx) == IPMI_LOCATE_ERR_SYSTEM_ERROR)
        printf ("FAILED\n");
      else
        printf ("ERROR: %s\n", ipmi_locate_ctx_errormsg (ctx));
    }
  printf ("\n");

  printf ("Probing SSIF device using PCI... ");
  if (!ipmi_locate_pci_get_device_info (ctx,
                                        IPMI_INTERFACE_SSIF,
                                        &info))
    {
      printf ("done\n");
      display_ipmi_locate_info (&info);
    }
  else
    {
      if (ipmi_locate_ctx_errnum (ctx) == IPMI_LOCATE_ERR_SYSTEM_ERROR)
        printf ("FAILED\n");
      else
        printf ("ERROR: %s\n", ipmi_locate_ctx_errormsg (ctx));
    }
  printf ("\n");

  return;
}