OSDN Git Service

Update abixml for newer libabigail
[android-x86/external-efivar.git] / src / dp-hw.c
1 /*
2  * libefivar - library for the manipulation of EFI variables
3  * Copyright 2012-2015 Red Hat, Inc.
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public License as
7  * published by the Free Software Foundation; either version 2.1 of the
8  * License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, see
17  * <http://www.gnu.org/licenses/>.
18  *
19  */
20
21 #include "fix_coverity.h"
22
23 #include <errno.h>
24 #include <inttypes.h>
25
26 #include "efivar.h"
27
28 ssize_t
29 format_edd10_guid(char *buf, size_t size, const char *dp_type, const_efidp dp)
30 {
31         ssize_t off = 0;
32         efidp_edd10 const *edd_dp = (efidp_edd10 *)dp;
33         format(buf, size, off, dp_type, "EDD10(0x%"PRIx32")",
34                     edd_dp->hardware_device);
35         return off;
36 }
37
38 ssize_t
39 _format_hw_dn(char *buf, size_t size, const_efidp dp)
40 {
41         efi_guid_t edd10_guid = EDD10_HARDWARE_VENDOR_PATH_GUID;
42         ssize_t off = 0;
43         switch (dp->subtype) {
44         case EFIDP_HW_PCI:
45                 format(buf, size, off, "Pci", "Pci(0x%"PRIx32",0x%"PRIx32")",
46                        dp->pci.device, dp->pci.function);
47                 break;
48         case EFIDP_HW_PCCARD:
49                 format(buf, size, off, "PcCard", "PcCard(0x%"PRIx32")",
50                        dp->pccard.function);
51                 break;
52         case EFIDP_HW_MMIO:
53                 format(buf, size, off, "MemoryMapped",
54                        "MemoryMapped(%"PRIu32",0x%"PRIx64",0x%"PRIx64")",
55                        dp->mmio.memory_type, dp->mmio.starting_address,
56                        dp->mmio.ending_address);
57                 break;
58         case EFIDP_HW_VENDOR:
59                 if (!efi_guid_cmp(&dp->hw_vendor.vendor_guid, &edd10_guid)) {
60                         format_helper(format_edd10_guid, buf, size, off,
61                                       "EDD 1.0", dp);
62                 } else {
63                         format_vendor(buf, size, off, "VenHw", dp);
64                 }
65                 break;
66         case EFIDP_HW_CONTROLLER:
67                 format(buf, size, off, "Ctrl", "Ctrl(0x%"PRIx32")",
68                        dp->controller.controller);
69                 break;
70         case EFIDP_HW_BMC:
71                 format(buf, size, off, "BMC", "BMC(%d,0x%"PRIx64")",
72                        dp->bmc.interface_type, dp->bmc.base_addr);
73                 break;
74         default:
75                 format(buf, size, off, "Hardware",
76                        "HardwarePath(%d,", dp->subtype);
77                 format_hex(buf, size, off, "Hardware", (uint8_t *)dp+4,
78                            efidp_node_size(dp)-4);
79                 format(buf, size, off, "Hardware", ")");
80                 break;
81         }
82         return off;
83 }
84
85 ssize_t PUBLIC
86 efidp_make_pci(uint8_t *buf, ssize_t size, uint8_t device, uint8_t function)
87 {
88         efidp_pci *pci = (efidp_pci *)buf;
89         ssize_t sz;
90         ssize_t req = sizeof (*pci);
91         sz = efidp_make_generic(buf, size, EFIDP_HARDWARE_TYPE, EFIDP_HW_PCI,
92                                 req);
93         if (size && sz == req) {
94                 pci->device = device;
95                 pci->function = function;
96         }
97
98         if (sz < 0)
99                 efi_error("efidp_make_generic failed");
100
101         return sz;
102 }
103
104 ssize_t PUBLIC
105 efidp_make_edd10(uint8_t *buf, ssize_t size, uint32_t hardware_device)
106 {
107         efi_guid_t edd10_guid = EDD10_HARDWARE_VENDOR_PATH_GUID;
108         efidp_edd10 *edd_dp = (efidp_edd10 *)buf;
109         ssize_t sz;
110         ssize_t req = sizeof (*edd_dp);
111         sz = efidp_make_generic(buf, size, EFIDP_HARDWARE_TYPE, EFIDP_HW_VENDOR,
112                                 req);
113         if (size && sz == req) {
114                 memcpy(&edd_dp->vendor_guid, &edd10_guid, sizeof (edd10_guid));
115                 edd_dp->hardware_device = hardware_device;
116         }
117
118         if (sz < 0)
119                 efi_error("efidp_make_generic failed");
120
121         return sz;
122 }