LCOV - code coverage report
Current view: top level - dev/acpi - acpihve.c (source / functions) Hit Total Coverage
Test: 6.4 Lines: 0 22 0.0 %
Date: 2018-10-19 03:25:38 Functions: 0 2 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       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           0 : acpihve_match(struct device *parent, void *match, void *aux)
      51             : {
      52           0 :         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           0 :         if (acpihve_attached || aaa->aaa_table == NULL)
      59           0 :                 return (0);
      60             : 
      61           0 :         hdr = (struct acpi_table_header *)aaa->aaa_table;
      62           0 :         if (memcmp(hdr->signature, "OEM0", 4) != 0 ||
      63           0 :             memcmp(hdr->oemid, "VRTUAL", 6) != 0 ||
      64           0 :             memcmp(hdr->oemtableid, "MICROSFT", 8) != 0)
      65           0 :                 return (0);
      66             : 
      67           0 :         return (1);
      68           0 : }
      69             : 
      70             : void
      71           0 : acpihve_attach(struct device *parent, struct device *self, void *aux)
      72             : {
      73           0 :         struct acpi_attach_args *aaa = aux;
      74           0 :         struct acpi_oem0 *oem0 = (struct acpi_oem0 *)aaa->aaa_table;
      75             :         int i;
      76             : 
      77           0 :         acpihve_attached++;
      78             : 
      79           0 :         if (oem0->hdr.length != sizeof(*oem0)) {
      80           0 :                 printf(": unexpected table length %u\n", oem0->hdr.length);
      81           0 :                 return;
      82             :         }
      83             : 
      84             :         /* 64 bytes of entropy from OEM0 table */
      85           0 :         for (i = 0; i < nitems(oem0->entropy); i++)
      86           0 :                 enqueue_randomness(oem0->entropy[i]);
      87             : 
      88           0 :         printf("\n");
      89           0 : }

Generated by: LCOV version 1.13