From 80e4976e1bed5aa4fd35f8ac5d709da769467b0a Mon Sep 17 00:00:00 2001 From: Marcelo Politzer <251334+mpolitzer@users.noreply.github.com> Date: Fri, 27 Oct 2023 13:57:04 -0300 Subject: [PATCH] fixup! feat: convert yield to use the driver library --- linux/libdriver/base/yield-driver-api.h | 7 +++---- linux/libdriver/examples/yield.c | 16 +++++++++------- linux/libdriver/ioctl/yield.c | 4 ++-- linux/libdriver/mock/yield.c | 4 ++-- 4 files changed, 16 insertions(+), 15 deletions(-) diff --git a/linux/libdriver/base/yield-driver-api.h b/linux/libdriver/base/yield-driver-api.h index 6106ca71..f0d87fba 100644 --- a/linux/libdriver/base/yield-driver-api.h +++ b/linux/libdriver/base/yield-driver-api.h @@ -10,6 +10,7 @@ * @{ */ #ifndef YIELD_DRIVER_API_H #define YIELD_DRIVER_API_H +#include /** contents of @ref rollup_driver_t are implementation specific. * Define it in @p */ @@ -25,9 +26,7 @@ int yield_driver_init(struct yield_driver *me); /** Report the application progress to the emulator. * - * @param [in] me A sucessfuly initialized state by @ref yield_driver_init - * - * @note usage of @p me after this call is a BUG and will cause undefined behaviour */ -int yield_driver_progress(struct yield_driver *me, float progress); + * @param [in] me A sucessfuly initialized state by @ref yield_driver_init */ +int yield_driver_progress(struct yield_driver *me, uint32_t progress); #endif /* YIELD_DRIVER_API_H */ diff --git a/linux/libdriver/examples/yield.c b/linux/libdriver/examples/yield.c index 01718c3d..7a3cc5de 100644 --- a/linux/libdriver/examples/yield.c +++ b/linux/libdriver/examples/yield.c @@ -10,12 +10,14 @@ int main(int argc, char *argv[]) float progress = 0.0; yield_driver_t Y[1]; - if (yield_driver_init(Y)) - return EXIT_FAILURE; - if (argc > 1) - progress = strtof(argv[1], NULL); - if (yield_driver_progress(Y, progress)) - return EXIT_FAILURE; - + if ((argc > 1) && (sscanf(argv[1], "--progress=%f\n", &progress) == 1)) { + if (yield_driver_init(Y)) + return EXIT_FAILURE; + if (yield_driver_progress(Y, progress * 10)) + return EXIT_FAILURE; + } else { + fprintf(stderr, "usage: %s --progress=\n", argv[0]); + exit(EXIT_FAILURE); + } return EXIT_SUCCESS; } diff --git a/linux/libdriver/ioctl/yield.c b/linux/libdriver/ioctl/yield.c index 34db2314..cdf3ccd7 100644 --- a/linux/libdriver/ioctl/yield.c +++ b/linux/libdriver/ioctl/yield.c @@ -15,13 +15,13 @@ int yield_driver_init(struct yield_driver *me) return 0; } -int yield_driver_progress(struct yield_driver *me, float progress) +int yield_driver_progress(struct yield_driver *me, uint32_t progress) { struct yield_request req = { .dev = (uint64_t)HTIF_DEVICE_YIELD, .cmd = (uint64_t)HTIF_YIELD_AUTOMATIC, .reason = (uint64_t)HTIF_YIELD_REASON_PROGRESS, - .data = progress * 10, + .data = progress, }; return ioctl(me->fd, IOCTL_YIELD, (unsigned long)&req); } diff --git a/linux/libdriver/mock/yield.c b/linux/libdriver/mock/yield.c index e66e423b..d6551dd9 100644 --- a/linux/libdriver/mock/yield.c +++ b/linux/libdriver/mock/yield.c @@ -8,9 +8,9 @@ int yield_driver_init(struct yield_driver *me) return 0; } -int yield_driver_progress(struct yield_driver *me, float progress) +int yield_driver_progress(struct yield_driver *me, uint32_t progress) { assert(me); - fprintf(stderr, "Progress: %6.2f\n", progress); + fprintf(stderr, "Progress: %u.%02u\n", progress / 10, progress % 10 * 10); return 0; }