MCPcopy Create free account
hub / github.com/F-Stack/f-stack / vtd_init

Function vtd_init

freebsd/amd64/vmm/intel/vtd.c:306–397  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

304}
305
306static int
307vtd_init(void)
308{
309 int i, units, remaining, tmp;
310 struct vtdmap *vtdmap;
311 vm_paddr_t ctx_paddr;
312 char *end, envname[32];
313 unsigned long mapaddr;
314 ACPI_STATUS status;
315 ACPI_TABLE_DMAR *dmar;
316 ACPI_DMAR_HEADER *hdr;
317 ACPI_DMAR_HARDWARE_UNIT *drhd;
318
319 /*
320 * Allow the user to override the ACPI DMAR table by specifying the
321 * physical address of each remapping unit.
322 *
323 * The following example specifies two remapping units at
324 * physical addresses 0xfed90000 and 0xfeda0000 respectively.
325 * set vtd.regmap.0.addr=0xfed90000
326 * set vtd.regmap.1.addr=0xfeda0000
327 */
328 for (units = 0; units < DRHD_MAX_UNITS; units++) {
329 snprintf(envname, sizeof(envname), "vtd.regmap.%d.addr", units);
330 if (getenv_ulong(envname, &mapaddr) == 0)
331 break;
332 vtdmaps[units] = (struct vtdmap *)PHYS_TO_DMAP(mapaddr);
333 }
334
335 if (units > 0)
336 goto skip_dmar;
337
338 /* Search for DMAR table. */
339 status = AcpiGetTable(ACPI_SIG_DMAR, 0, (ACPI_TABLE_HEADER **)&dmar);
340 if (ACPI_FAILURE(status))
341 return (ENXIO);
342
343 end = (char *)dmar + dmar->Header.Length;
344 remaining = dmar->Header.Length - sizeof(ACPI_TABLE_DMAR);
345 while (remaining > sizeof(ACPI_DMAR_HEADER)) {
346 hdr = (ACPI_DMAR_HEADER *)(end - remaining);
347 if (hdr->Length > remaining)
348 break;
349 /*
350 * From Intel VT-d arch spec, version 1.3:
351 * BIOS implementations must report mapping structures
352 * in numerical order, i.e. All remapping structures of
353 * type 0 (DRHD) enumerated before remapping structures of
354 * type 1 (RMRR) and so forth.
355 */
356 if (hdr->Type != ACPI_DMAR_TYPE_HARDWARE_UNIT)
357 break;
358
359 drhd = (ACPI_DMAR_HARDWARE_UNIT *)hdr;
360 drhds[units] = drhd;
361 vtdmaps[units] = (struct vtdmap *)PHYS_TO_DMAP(drhd->Address);
362 if (++units >= DRHD_MAX_UNITS)
363 break;

Callers

nothing calls this directly

Calls 5

snprintfFunction · 0.85
AcpiGetTableFunction · 0.85
vtd_max_domainsFunction · 0.85
getenv_ulongFunction · 0.50
panicFunction · 0.50

Tested by

no test coverage detected