1d722e3fbSopenharmony_ci/*
2d722e3fbSopenharmony_ci * Copyright (C) 2018 Intel Corporation
3d722e3fbSopenharmony_ci *
4d722e3fbSopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a
5d722e3fbSopenharmony_ci * copy of this software and associated documentation files (the "Software"),
6d722e3fbSopenharmony_ci * to deal in the Software without restriction, including without limitation
7d722e3fbSopenharmony_ci * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8d722e3fbSopenharmony_ci * and/or sell copies of the Software, and to permit persons to whom the
9d722e3fbSopenharmony_ci * Software is furnished to do so, subject to the following conditions:
10d722e3fbSopenharmony_ci *
11d722e3fbSopenharmony_ci * The above copyright notice and this permission notice (including the next
12d722e3fbSopenharmony_ci * paragraph) shall be included in all copies or substantial portions of the
13d722e3fbSopenharmony_ci * Software.
14d722e3fbSopenharmony_ci *
15d722e3fbSopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16d722e3fbSopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17d722e3fbSopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
18d722e3fbSopenharmony_ci * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19d722e3fbSopenharmony_ci * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20d722e3fbSopenharmony_ci * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21d722e3fbSopenharmony_ci * IN THE SOFTWARE.
22d722e3fbSopenharmony_ci */
23d722e3fbSopenharmony_ci#include "intel_chipset.h"
24d722e3fbSopenharmony_ci
25d722e3fbSopenharmony_ci#include <inttypes.h>
26d722e3fbSopenharmony_ci#include <stdbool.h>
27d722e3fbSopenharmony_ci
28d722e3fbSopenharmony_ci#include "i915_pciids.h"
29d722e3fbSopenharmony_ci
30d722e3fbSopenharmony_ci#undef INTEL_VGA_DEVICE
31d722e3fbSopenharmony_ci#define INTEL_VGA_DEVICE(id, gen) { id, gen }
32d722e3fbSopenharmony_ci
33d722e3fbSopenharmony_cistatic const struct pci_device {
34d722e3fbSopenharmony_ci	uint16_t device;
35d722e3fbSopenharmony_ci	uint16_t gen;
36d722e3fbSopenharmony_ci} pciids[] = {
37d722e3fbSopenharmony_ci	/* Keep ids sorted by gen; latest gen first */
38d722e3fbSopenharmony_ci	INTEL_ADLN_IDS(12),
39d722e3fbSopenharmony_ci	INTEL_RPLP_IDS(12),
40d722e3fbSopenharmony_ci	INTEL_ADLP_IDS(12),
41d722e3fbSopenharmony_ci	INTEL_RPLS_IDS(12),
42d722e3fbSopenharmony_ci	INTEL_ADLS_IDS(12),
43d722e3fbSopenharmony_ci	INTEL_RKL_IDS(12),
44d722e3fbSopenharmony_ci	INTEL_DG1_IDS(12),
45d722e3fbSopenharmony_ci	INTEL_TGL_12_IDS(12),
46d722e3fbSopenharmony_ci	INTEL_JSL_IDS(11),
47d722e3fbSopenharmony_ci	INTEL_EHL_IDS(11),
48d722e3fbSopenharmony_ci	INTEL_ICL_11_IDS(11),
49d722e3fbSopenharmony_ci	INTEL_CNL_IDS(10),
50d722e3fbSopenharmony_ci	INTEL_CFL_IDS(9),
51d722e3fbSopenharmony_ci	INTEL_GLK_IDS(9),
52d722e3fbSopenharmony_ci	INTEL_KBL_IDS(9),
53d722e3fbSopenharmony_ci	INTEL_BXT_IDS(9),
54d722e3fbSopenharmony_ci	INTEL_SKL_IDS(9),
55d722e3fbSopenharmony_ci};
56d722e3fbSopenharmony_ci
57d722e3fbSopenharmony_cidrm_private bool intel_is_genx(unsigned int devid, int gen)
58d722e3fbSopenharmony_ci{
59d722e3fbSopenharmony_ci	const struct pci_device *p,
60d722e3fbSopenharmony_ci		  *pend = pciids + sizeof(pciids) / sizeof(pciids[0]);
61d722e3fbSopenharmony_ci
62d722e3fbSopenharmony_ci	for (p = pciids; p < pend; p++) {
63d722e3fbSopenharmony_ci		/* PCI IDs are sorted */
64d722e3fbSopenharmony_ci		if (p->gen < gen)
65d722e3fbSopenharmony_ci			break;
66d722e3fbSopenharmony_ci
67d722e3fbSopenharmony_ci		if (p->device != devid)
68d722e3fbSopenharmony_ci			continue;
69d722e3fbSopenharmony_ci
70d722e3fbSopenharmony_ci		if (gen == p->gen)
71d722e3fbSopenharmony_ci			return true;
72d722e3fbSopenharmony_ci
73d722e3fbSopenharmony_ci		break;
74d722e3fbSopenharmony_ci	}
75d722e3fbSopenharmony_ci
76d722e3fbSopenharmony_ci	return false;
77d722e3fbSopenharmony_ci}
78d722e3fbSopenharmony_ci
79d722e3fbSopenharmony_cidrm_private bool intel_get_genx(unsigned int devid, int *gen)
80d722e3fbSopenharmony_ci{
81d722e3fbSopenharmony_ci	const struct pci_device *p,
82d722e3fbSopenharmony_ci		  *pend = pciids + sizeof(pciids) / sizeof(pciids[0]);
83d722e3fbSopenharmony_ci
84d722e3fbSopenharmony_ci	for (p = pciids; p < pend; p++) {
85d722e3fbSopenharmony_ci		if (p->device != devid)
86d722e3fbSopenharmony_ci			continue;
87d722e3fbSopenharmony_ci
88d722e3fbSopenharmony_ci		if (gen)
89d722e3fbSopenharmony_ci			*gen = p->gen;
90d722e3fbSopenharmony_ci
91d722e3fbSopenharmony_ci		return true;
92d722e3fbSopenharmony_ci	}
93d722e3fbSopenharmony_ci
94d722e3fbSopenharmony_ci	return false;
95d722e3fbSopenharmony_ci}
96