1 /* $OpenBSD: acpihve.c,v 1.2 2018/04/28 15:44:59 jasper Exp $ */ 2 3 /* 4 * Copyright (c) 2017 Jonathan Gray <jsg@openbsd.org> 5 * 6 * Permission to use, copy, modify, and distribute this software for any 7 * purpose with or without fee is hereby granted, provided that the above 8 * copyright notice and this permission notice appear in all copies. 9 * 10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 */ 18 19 #include <sys/param.h> 20 #include <sys/systm.h> 21 #include <sys/device.h> 22 23 #include <dev/acpi/acpireg.h> 24 #include <dev/acpi/acpivar.h> 25 #include <dev/rndvar.h> 26 27 int acpihve_match(struct device *, void *, void *); 28 void acpihve_attach(struct device *, struct device *, void *); 29 30 struct acpi_oem0 { 31 struct acpi_table_header hdr; 32 uint32_t entropy[16]; 33 } __packed; 34 35 struct acpihve_softc { 36 struct device sc_dev; 37 }; 38 39 struct cfattach acpihve_ca = { 40 sizeof(struct acpihve_softc), acpihve_match, acpihve_attach 41 }; 42 43 struct cfdriver acpihve_cd = { 44 NULL, "acpihve", DV_DULL 45 }; 46 47 int acpihve_attached; 48 49 int 50 acpihve_match(struct device *parent, void *match, void *aux) 51 { 52 struct acpi_attach_args *aaa = aux; 53 struct acpi_table_header *hdr; 54 55 /* 56 * If we do not have a table, it is not us; attach only once 57 */ 58 if (acpihve_attached || aaa->aaa_table == NULL) 59 return (0); 60 61 hdr = (struct acpi_table_header *)aaa->aaa_table; 62 if (memcmp(hdr->signature, "OEM0", 4) != 0 || 63 memcmp(hdr->oemid, "VRTUAL", 6) != 0 || 64 memcmp(hdr->oemtableid, "MICROSFT", 8) != 0) 65 return (0); 66 67 return (1); 68 } 69 70 void 71 acpihve_attach(struct device *parent, struct device *self, void *aux) 72 { 73 struct acpi_attach_args *aaa = aux; 74 struct acpi_oem0 *oem0 = (struct acpi_oem0 *)aaa->aaa_table; 75 int i; 76 77 acpihve_attached++; 78 79 if (oem0->hdr.length != sizeof(*oem0)) { 80 printf(": unexpected table length %u\n", oem0->hdr.length); 81 return; 82 } 83 84 /* 64 bytes of entropy from OEM0 table */ 85 for (i = 0; i < nitems(oem0->entropy); i++) 86 enqueue_randomness(oem0->entropy[i]); 87 88 printf("\n"); 89 } 90