Subversion Repositories Kolibri OS

Rev

Rev 4358 | Blame | Compare with Previous | Last modification | View Log | RSS feed

  1. /*
  2.  * Copyright © 2011 Intel Corporation
  3.  *
  4.  * Permission is hereby granted, free of charge, to any person obtaining a
  5.  * copy of this software and associated documentation files (the "Software"),
  6.  * to deal in the Software without restriction, including without limitation
  7.  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  8.  * and/or sell copies of the Software, and to permit persons to whom the
  9.  * Software is furnished to do so, subject to the following conditions:
  10.  *
  11.  * The above copyright notice and this permission notice (including the next
  12.  * paragraph) shall be included in all copies or substantial portions of the
  13.  * Software.
  14.  *
  15.  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  16.  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  17.  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  18.  * NONINFRINGEMENT.  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  19.  * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
  20.  * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  21.  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  22.  * DEALINGS IN THE SOFTWARE.
  23.  *
  24.  * Authors:
  25.  *    Kristian Høgsberg <krh@bitplanet.net>
  26.  *    Benjamin Franzke <benjaminfranzke@googlemail.com>
  27.  */
  28.  
  29. #include <stdio.h>
  30. #include <string.h>
  31. #include <pciaccess.h>
  32. #include <kos32sys.h>
  33.  
  34. #include "gbm_driint.h"
  35. #define DRIVER_MAP_DRI2_ONLY
  36. #include "pci_ids/pci_id_driver_map.h"
  37.  
  38. char *
  39. dri_fd_get_driver_name(int fd)
  40. {
  41.     ioctl_t   io;
  42.     struct pci_device device;
  43.    char *driver = NULL;
  44.     int i, j;
  45.  
  46.     io.handle   = fd;
  47.     io.io_code  = SRV_GET_PCI_INFO;
  48.     io.input    = &device;
  49.     io.inp_size = sizeof(device);
  50.     io.output   = NULL;
  51.     io.out_size = 0;
  52.  
  53.     if (call_service(&io)!=0)
  54.       return NULL;
  55.  
  56.     for (i = 0; driver_map[i].driver; i++)
  57.     {
  58.         if (device.vendor_id != driver_map[i].vendor_id)
  59.          continue;
  60.         if (driver_map[i].num_chips_ids == -1)
  61.         {
  62.          driver = strdup(driver_map[i].driver);
  63.             printf("pci id for %d: %04x:%04x, driver %s\n",
  64.                   fd, device.vendor_id, device.device_id, driver);
  65.          goto out;
  66.       }
  67.  
  68.       for (j = 0; j < driver_map[i].num_chips_ids; j++)
  69.             if (driver_map[i].chip_ids[j] == device.device_id)
  70.             {
  71.             driver = strdup(driver_map[i].driver);
  72.                 printf("pci id for %d: %04x:%04x, driver %s\n",
  73.                      fd, device.vendor_id, device.device_id, driver);
  74.             goto out;
  75.          }
  76.    }
  77.  
  78. out:
  79.  
  80.    return driver;
  81. }
  82.