Skip to content

Commit a87c811

Browse files
gmarullnashif
authored andcommitted
arch: x86: use DEVICE_DT_GET_ONE
Improve code by using DEVICE_DT_GET_ONE instead of device_get_binding, since the intel_vt_d device instance can be obtained at compile time. Signed-off-by: Gerard Marull-Paretas <[email protected]>
1 parent ce0ad0e commit a87c811

File tree

2 files changed

+5
-29
lines changed

2 files changed

+5
-29
lines changed

arch/x86/core/intel64/irq.c

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -34,19 +34,7 @@ const void *x86_irq_args[NR_IRQ_VECTORS];
3434
#include <device.h>
3535
#include <drivers/interrupt_controller/intel_vtd.h>
3636

37-
static const struct device *vtd;
38-
39-
static bool get_vtd(void)
40-
{
41-
if (vtd != NULL) {
42-
return true;
43-
}
44-
#define DT_DRV_COMPAT intel_vt_d
45-
vtd = device_get_binding(DT_INST_LABEL(0));
46-
#undef DT_DRV_COMPAT
47-
48-
return vtd == NULL ? false : true;
49-
}
37+
static const struct device *vtd = DEVICE_DT_GET_ONE(intel_vt_d);
5038

5139
#endif /* CONFIG_INTEL_VTD_ICTL */
5240

@@ -131,7 +119,7 @@ int arch_irq_connect_dynamic(unsigned int irq, unsigned int priority,
131119
vector = z_x86_allocate_vector(priority, -1);
132120
if (vector >= 0) {
133121
#if defined(CONFIG_INTEL_VTD_ICTL)
134-
if (get_vtd()) {
122+
if (device_is_ready(vtd)) {
135123
int irte = vtd_allocate_entries(vtd, 1);
136124

137125
__ASSERT(irte >= 0, "IRTE allocation must succeed");

arch/x86/core/pcie.c

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -164,19 +164,7 @@ void pcie_conf_write(pcie_bdf_t bdf, unsigned int reg, uint32_t data)
164164
#include <drivers/interrupt_controller/intel_vtd.h>
165165
#include <arch/x86/acpi.h>
166166

167-
static const struct device *vtd;
168-
169-
static bool get_vtd(void)
170-
{
171-
if (vtd != NULL) {
172-
return true;
173-
}
174-
#define DT_DRV_COMPAT intel_vt_d
175-
vtd = device_get_binding(DT_INST_LABEL(0));
176-
#undef DT_DRV_COMPAT
177-
178-
return vtd == NULL ? false : true;
179-
}
167+
static const struct device *vtd = DEVICE_DT_GET_ONE(intel_vt_d);
180168

181169
#endif /* CONFIG_INTEL_VTD_ICTL */
182170

@@ -244,7 +232,7 @@ uint8_t arch_pcie_msi_vectors_allocate(unsigned int priority,
244232
{
245233
int irte;
246234

247-
if (!get_vtd()) {
235+
if (!device_is_ready(vtd)) {
248236
return 0;
249237
}
250238

@@ -306,7 +294,7 @@ bool arch_pcie_msi_vector_connect(msi_vector_t *vector,
306294
if (vector->arch.remap) {
307295
union acpi_dmar_id id;
308296

309-
if (!get_vtd()) {
297+
if (!device_is_ready(vtd)) {
310298
return false;
311299
}
312300

0 commit comments

Comments
 (0)