Chris Wilson | 9537422 | 2010-04-08 11:56:57 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright © 2008 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, EXPRESS OR |
| 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 18 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 20 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
| 21 | * DEALINGS IN THE SOFTWARE. |
| 22 | * |
| 23 | * Authors: |
| 24 | * Eric Anholt <eric@anholt.net> |
| 25 | * |
| 26 | */ |
| 27 | |
| 28 | #include <unistd.h> |
| 29 | #include <stdlib.h> |
| 30 | #include <stdio.h> |
| 31 | #include <string.h> |
| 32 | #include <errno.h> |
| 33 | #include <err.h> |
| 34 | #include <assert.h> |
| 35 | #include <sys/ioctl.h> |
Sateesh Kavuri | b39a74b | 2012-02-06 15:37:04 +0530 | [diff] [blame] | 36 | #include <fcntl.h> |
Chris Wilson | 9537422 | 2010-04-08 11:56:57 +0100 | [diff] [blame] | 37 | #include <sys/stat.h> |
| 38 | #include <sys/mman.h> |
Daniel Vetter | aed95c3 | 2014-03-22 14:54:28 +0100 | [diff] [blame] | 39 | #include "i915_drm.h" |
Chris Wilson | 9537422 | 2010-04-08 11:56:57 +0100 | [diff] [blame] | 40 | |
Tomeu Vizoso | 644f364 | 2016-02-18 14:23:25 +0100 | [diff] [blame] | 41 | #include "drmtest.h" |
Daniel Vetter | aed95c3 | 2014-03-22 14:54:28 +0100 | [diff] [blame] | 42 | #include "intel_chipset.h" |
Daniel Vetter | 71ac5de | 2014-08-26 15:13:06 +0200 | [diff] [blame] | 43 | #include "igt_core.h" |
Chris Wilson | 9537422 | 2010-04-08 11:56:57 +0100 | [diff] [blame] | 44 | |
Daniel Vetter | a8e8654 | 2014-03-22 15:12:57 +0100 | [diff] [blame] | 45 | /** |
| 46 | * SECTION:intel_chipset |
| 47 | * @short_description: Feature macros and chipset helpers |
Damien Lespiau | 6ebd8c2 | 2015-06-26 14:28:41 +0100 | [diff] [blame] | 48 | * @title: Chipset |
Thomas Wood | f0381d1 | 2015-09-07 09:26:01 +0100 | [diff] [blame] | 49 | * @include: igt.h |
Daniel Vetter | cd6d5a6 | 2014-03-22 19:35:40 +0100 | [diff] [blame] | 50 | * |
Daniel Vetter | a8e8654 | 2014-03-22 15:12:57 +0100 | [diff] [blame] | 51 | * This library mostly provides feature macros which use raw pci device ids. It |
| 52 | * also provides a few more helper functions to handle pci devices, chipset |
| 53 | * detection and related issues. |
| 54 | */ |
| 55 | |
| 56 | /** |
| 57 | * intel_pch: |
| 58 | * |
| 59 | * Global variable to keep track of the pch type. Can either be set manually or |
| 60 | * detected at runtime with intel_check_pch(). |
| 61 | */ |
Daniel Vetter | 266b26b | 2014-03-22 14:59:58 +0100 | [diff] [blame] | 62 | enum pch_type intel_pch; |
Zhenyu Wang | 2b40fc8 | 2010-04-15 22:57:02 +0800 | [diff] [blame] | 63 | |
Daniel Vetter | a8e8654 | 2014-03-22 15:12:57 +0100 | [diff] [blame] | 64 | /** |
| 65 | * intel_get_pci_device: |
| 66 | * |
| 67 | * Looks up the main graphics pci device using libpciaccess. |
| 68 | * |
| 69 | * Returns: |
| 70 | * The pci_device, exits the program on any failures. |
| 71 | */ |
Chris Wilson | 9537422 | 2010-04-08 11:56:57 +0100 | [diff] [blame] | 72 | struct pci_device * |
| 73 | intel_get_pci_device(void) |
| 74 | { |
| 75 | struct pci_device *pci_dev; |
Daniel Vetter | 1be3fd7 | 2012-01-09 23:42:19 +0100 | [diff] [blame] | 76 | int error; |
Chris Wilson | 9537422 | 2010-04-08 11:56:57 +0100 | [diff] [blame] | 77 | |
Daniel Vetter | 1be3fd7 | 2012-01-09 23:42:19 +0100 | [diff] [blame] | 78 | error = pci_system_init(); |
Daniel Vetter | 71ac5de | 2014-08-26 15:13:06 +0200 | [diff] [blame] | 79 | igt_fail_on_f(error != 0, |
| 80 | "Couldn't initialize PCI system\n"); |
Chris Wilson | 9537422 | 2010-04-08 11:56:57 +0100 | [diff] [blame] | 81 | |
Chris Wilson | 50fdf32 | 2012-12-06 12:16:12 +0000 | [diff] [blame] | 82 | /* Grab the graphics card. Try the canonical slot first, then |
| 83 | * walk the entire PCI bus for a matching device. */ |
Chris Wilson | 9537422 | 2010-04-08 11:56:57 +0100 | [diff] [blame] | 84 | pci_dev = pci_device_find_by_slot(0, 0, 2, 0); |
Chris Wilson | 50fdf32 | 2012-12-06 12:16:12 +0000 | [diff] [blame] | 85 | if (pci_dev == NULL || pci_dev->vendor_id != 0x8086) { |
| 86 | struct pci_device_iterator *iter; |
| 87 | struct pci_id_match match; |
| 88 | |
| 89 | match.vendor_id = 0x8086; /* Intel */ |
| 90 | match.device_id = PCI_MATCH_ANY; |
| 91 | match.subvendor_id = PCI_MATCH_ANY; |
| 92 | match.subdevice_id = PCI_MATCH_ANY; |
| 93 | |
| 94 | match.device_class = 0x3 << 16; |
| 95 | match.device_class_mask = 0xff << 16; |
| 96 | |
| 97 | match.match_data = 0; |
| 98 | |
| 99 | iter = pci_id_match_iterator_create(&match); |
| 100 | pci_dev = pci_device_next(iter); |
| 101 | pci_iterator_destroy(iter); |
| 102 | } |
Daniel Vetter | dcab159 | 2016-10-11 11:31:38 +0200 | [diff] [blame] | 103 | igt_require_f(pci_dev, "Couldn't find Intel graphics card\n"); |
Chris Wilson | 9537422 | 2010-04-08 11:56:57 +0100 | [diff] [blame] | 104 | |
Daniel Vetter | 1be3fd7 | 2012-01-09 23:42:19 +0100 | [diff] [blame] | 105 | error = pci_device_probe(pci_dev); |
Daniel Vetter | 71ac5de | 2014-08-26 15:13:06 +0200 | [diff] [blame] | 106 | igt_fail_on_f(error != 0, |
| 107 | "Couldn't probe graphics card\n"); |
Chris Wilson | 9537422 | 2010-04-08 11:56:57 +0100 | [diff] [blame] | 108 | |
| 109 | if (pci_dev->vendor_id != 0x8086) |
| 110 | errx(1, "Graphics card is non-intel"); |
| 111 | |
| 112 | return pci_dev; |
| 113 | } |
Zhenyu Wang | 2b40fc8 | 2010-04-15 22:57:02 +0800 | [diff] [blame] | 114 | |
Chris Wilson | eaa7e61 | 2015-02-18 15:58:06 +0000 | [diff] [blame] | 115 | extern uint16_t __drm_device_id; |
| 116 | |
Daniel Vetter | a8e8654 | 2014-03-22 15:12:57 +0100 | [diff] [blame] | 117 | /** |
| 118 | * intel_get_drm_devid: |
| 119 | * @fd: open i915 drm file descriptor |
| 120 | * |
| 121 | * Queries the kernel for the pci device id corresponding to the drm file |
| 122 | * descriptor. |
| 123 | * |
| 124 | * Returns: |
| 125 | * The devid, exits the program on any failures. |
| 126 | */ |
Daniel Vetter | aed95c3 | 2014-03-22 14:54:28 +0100 | [diff] [blame] | 127 | uint32_t |
| 128 | intel_get_drm_devid(int fd) |
| 129 | { |
Chris Wilson | acca724 | 2014-07-21 07:57:25 +0100 | [diff] [blame] | 130 | const char *override; |
Daniel Vetter | aed95c3 | 2014-03-22 14:54:28 +0100 | [diff] [blame] | 131 | |
Tomeu Vizoso | 644f364 | 2016-02-18 14:23:25 +0100 | [diff] [blame] | 132 | igt_assert(is_i915_device(fd)); |
Chris Wilson | eaa7e61 | 2015-02-18 15:58:06 +0000 | [diff] [blame] | 133 | igt_assert(__drm_device_id); |
| 134 | |
Daniel Vetter | aed95c3 | 2014-03-22 14:54:28 +0100 | [diff] [blame] | 135 | override = getenv("INTEL_DEVID_OVERRIDE"); |
Chris Wilson | eaa7e61 | 2015-02-18 15:58:06 +0000 | [diff] [blame] | 136 | if (override) |
Chris Wilson | 5b93daf | 2015-02-18 16:06:15 +0000 | [diff] [blame] | 137 | return strtol(override, NULL, 0); |
Chris Wilson | eaa7e61 | 2015-02-18 15:58:06 +0000 | [diff] [blame] | 138 | else |
| 139 | return __drm_device_id; |
Daniel Vetter | aed95c3 | 2014-03-22 14:54:28 +0100 | [diff] [blame] | 140 | } |
| 141 | |
Daniel Vetter | a8e8654 | 2014-03-22 15:12:57 +0100 | [diff] [blame] | 142 | /** |
Daniel Vetter | a8e8654 | 2014-03-22 15:12:57 +0100 | [diff] [blame] | 143 | * intel_check_pch: |
| 144 | * |
| 145 | * Detects the PCH chipset type of the running systems and fills in the results |
Thomas Wood | d01ebbd | 2015-06-29 16:47:14 +0100 | [diff] [blame] | 146 | * into the global #intel_pch variable. |
Daniel Vetter | a8e8654 | 2014-03-22 15:12:57 +0100 | [diff] [blame] | 147 | */ |
Zhenyu Wang | 2b40fc8 | 2010-04-15 22:57:02 +0800 | [diff] [blame] | 148 | void |
| 149 | intel_check_pch(void) |
| 150 | { |
| 151 | struct pci_device *pch_dev; |
| 152 | |
| 153 | pch_dev = pci_device_find_by_slot(0, 0, 31, 0); |
| 154 | if (pch_dev == NULL) |
| 155 | return; |
| 156 | |
Paulo Zanoni | 29abdb9 | 2013-03-01 13:30:46 -0300 | [diff] [blame] | 157 | if (pch_dev->vendor_id != 0x8086) |
| 158 | return; |
| 159 | |
| 160 | switch (pch_dev->device_id & 0xff00) { |
| 161 | case 0x3b00: |
Daniel Vetter | 266b26b | 2014-03-22 14:59:58 +0100 | [diff] [blame] | 162 | intel_pch = PCH_IBX; |
Paulo Zanoni | 29abdb9 | 2013-03-01 13:30:46 -0300 | [diff] [blame] | 163 | break; |
| 164 | case 0x1c00: |
| 165 | case 0x1e00: |
Daniel Vetter | 266b26b | 2014-03-22 14:59:58 +0100 | [diff] [blame] | 166 | intel_pch = PCH_CPT; |
Paulo Zanoni | 29abdb9 | 2013-03-01 13:30:46 -0300 | [diff] [blame] | 167 | break; |
| 168 | case 0x8c00: |
| 169 | case 0x9c00: |
Daniel Vetter | 266b26b | 2014-03-22 14:59:58 +0100 | [diff] [blame] | 170 | intel_pch = PCH_LPT; |
Paulo Zanoni | 29abdb9 | 2013-03-01 13:30:46 -0300 | [diff] [blame] | 171 | break; |
| 172 | default: |
Daniel Vetter | 266b26b | 2014-03-22 14:59:58 +0100 | [diff] [blame] | 173 | intel_pch = PCH_NONE; |
Paulo Zanoni | 29abdb9 | 2013-03-01 13:30:46 -0300 | [diff] [blame] | 174 | return; |
| 175 | } |
Zhenyu Wang | 2b40fc8 | 2010-04-15 22:57:02 +0800 | [diff] [blame] | 176 | } |