libvirt/src/util/virpcivpd.h
Dmitrii Shcherbakov 59c1bc3a0e Add a PCI/PCIe device VPD Parser
Add support for deserializing the binary PCI/PCIe VPD format and storing
results in memory.

The VPD format is specified in "I.3. VPD Definitions" in PCI specs
(2.2+) and "6.28.1 VPD Format" PCIe 4.0. As section 6.28 in PCIe 4.0
notes, the PCI Local Bus and PCIe VPD formats are binary compatible
and PCIe 4.0 merely started incorporating what was already present in
PCI specs.

Linux kernel exposes a binary blob in the VPD format via sysfs since
v2.6.26 (commit 94e6108803469a37ee1e3c92dafdd1d59298602f) which requires
a parser to interpret.

Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Signed-off-by: Dmitrii Shcherbakov <dmitrii.shcherbakov@canonical.com>
2021-10-21 17:34:04 +01:00

77 lines
2.3 KiB
C

/*
* virpcivpd.h: helper APIs for working with the PCI/PCIe VPD capability
*
* Copyright (C) 2021 Canonical Ltd.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see
* <http://www.gnu.org/licenses/>.
*/
#pragma once
#include "internal.h"
typedef struct virPCIVPDResourceCustom virPCIVPDResourceCustom;
struct virPCIVPDResourceCustom {
char idx;
char *value;
};
typedef struct virPCIVPDResourceRO virPCIVPDResourceRO;
struct virPCIVPDResourceRO {
char *part_number;
char *change_level;
char *manufacture_id;
char *serial_number;
GPtrArray *vendor_specific;
};
typedef struct virPCIVPDResourceRW virPCIVPDResourceRW;
struct virPCIVPDResourceRW {
char *asset_tag;
GPtrArray *vendor_specific;
GPtrArray *system_specific;
};
typedef struct virPCIVPDResource virPCIVPDResource;
struct virPCIVPDResource {
char *name;
virPCIVPDResourceRO *ro;
virPCIVPDResourceRW *rw;
};
virPCIVPDResource *virPCIVPDParse(int vpdFileFd);
void virPCIVPDResourceFree(virPCIVPDResource *res);
G_DEFINE_AUTOPTR_CLEANUP_FUNC(virPCIVPDResource, virPCIVPDResourceFree);
virPCIVPDResourceRO *virPCIVPDResourceRONew(void);
void virPCIVPDResourceROFree(virPCIVPDResourceRO *ro);
G_DEFINE_AUTOPTR_CLEANUP_FUNC(virPCIVPDResourceRO, virPCIVPDResourceROFree);
virPCIVPDResourceRW *virPCIVPDResourceRWNew(void);
void virPCIVPDResourceRWFree(virPCIVPDResourceRW *rw);
G_DEFINE_AUTOPTR_CLEANUP_FUNC(virPCIVPDResourceRW, virPCIVPDResourceRWFree);
bool
virPCIVPDResourceUpdateKeyword(virPCIVPDResource *res, const bool readOnly,
const char *const keyword, const char *const value);
void virPCIVPDResourceCustomFree(virPCIVPDResourceCustom *custom);
G_DEFINE_AUTOPTR_CLEANUP_FUNC(virPCIVPDResourceCustom, virPCIVPDResourceCustomFree);