Skip to content

Commit 0dc7adf

Browse files
Tomas Winklerwenlingz
authored andcommitted
dm: mei: add sysfs read functions
mei requires reading of u8, u32 and uuid sysfs files. Tracked-On: #1536 Signed-off-by: Tomas Winkler <tomas.winkler@intel.com> Signed-off-by: Vitaly Lubart <vitaly.lubart@intel.com> Acked-by: Wang, Yu1 <yu1.wang@intel.com>
1 parent b8d53d1 commit 0dc7adf

File tree

1 file changed

+75
-0
lines changed

1 file changed

+75
-0
lines changed

devicemodel/hw/pci/virtio/virtio_mei.c

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@
4141

4242
#include "mei.h"
4343

44+
#ifndef BIT
45+
#define BIT(x) (1 << (x))
46+
#endif
47+
48+
#define DEV_NAME_SIZE sizeof(((struct dirent *)0)->d_name)
49+
4450
#ifndef UUID_STR_LEN
4551
#define UUID_STR_LEN 37
4652
#endif
@@ -146,3 +152,72 @@ refcnt_put(const struct refcnt *ref)
146152
if (__sync_sub_and_fetch((int *)&ref->count, 1) == 0)
147153
ref->destroy(ref);
148154
}
155+
156+
static int mei_sysfs_read_property_file(const char *fname, char *buf, size_t sz)
157+
{
158+
int fd;
159+
int rc;
160+
161+
if (!buf)
162+
return -EINVAL;
163+
164+
if (!sz)
165+
return 0;
166+
167+
fd = open(fname, O_RDONLY);
168+
if (fd < 0) {
169+
DPRINTF("open failed %s %d\n", fname, errno);
170+
return -1;
171+
}
172+
173+
rc = read(fd, buf, sz);
174+
175+
close(fd);
176+
177+
return rc;
178+
}
179+
180+
static int mei_sysfs_read_property_u8(const char *fname, uint8_t *u8_property)
181+
{
182+
char buf[4] = {0};
183+
unsigned long int res;
184+
185+
if (mei_sysfs_read_property_file(fname, buf, sizeof(buf) - 1) < 0)
186+
return -1;
187+
188+
res = strtoul(buf, NULL, 10);
189+
if (res >= 256)
190+
return -1;
191+
192+
*u8_property = (uint8_t)res;
193+
194+
return 0;
195+
}
196+
197+
static int mei_sysfs_read_property_u32(const char *fname,
198+
uint32_t *u32_property)
199+
{
200+
char buf[32] = {0};
201+
unsigned long int res;
202+
203+
if (mei_sysfs_read_property_file(fname, buf, sizeof(buf) - 1) < 0)
204+
return -1;
205+
206+
res = strtoul(buf, NULL, 10);
207+
if (res == ULONG_MAX)
208+
return -1;
209+
210+
*u32_property = res;
211+
212+
return 0;
213+
}
214+
215+
static int mei_sysfs_read_property_uuid(char *fname, guid_t *uuid)
216+
{
217+
char buf[UUID_STR_LEN] = {0};
218+
219+
if (mei_sysfs_read_property_file(fname, buf, sizeof(buf) - 1) < 0)
220+
return -1;
221+
222+
return guid_parse(buf, sizeof(buf), uuid);
223+
}

0 commit comments

Comments
 (0)