[PATCH v5] event: Add fpga load event

From: Christian Taedcke christian.taedcke@weidmueller.com
This enables implementing custom logic after a bitstream was loaded into the fpga.
Signed-off-by: Christian Taedcke christian.taedcke@weidmueller.com Reviewed-by: Simon Glass sjg@chromium.org ---
Changes in v5: - remove changes from kmcent2 board file - add missing include to event.h
Changes in v4: - add include common.h to kmcent2 board file
Changes in v3: - replace #if with if - remove previously added printf - return notification error from fpga_load() - fix static_assert checking event name list
Changes in v2: - replace __weak function with a new event
common/event.c | 3 +++ drivers/fpga/fpga.c | 20 ++++++++++++++++++++ include/event.h | 17 +++++++++++++++++ 3 files changed, 40 insertions(+)
diff --git a/common/event.c b/common/event.c index 164c95f8f5..20720c5283 100644 --- a/common/event.c +++ b/common/event.c @@ -36,6 +36,9 @@ const char *const type_name[] = { /* init hooks */ "misc_init_f",
+ /* Fpga load hook */ + "fpga_load", + /* fdt hooks */ "ft_fixup",
diff --git a/drivers/fpga/fpga.c b/drivers/fpga/fpga.c index 7f6b6bc73a..81e6d8ffc0 100644 --- a/drivers/fpga/fpga.c +++ b/drivers/fpga/fpga.c @@ -244,6 +244,21 @@ int fpga_loads(int devnum, const void *buf, size_t size, } #endif
+static int fpga_load_event_notify(const void *buf, size_t bsize, int result) +{ + if (CONFIG_IS_ENABLED(EVENT)) { + struct event_fpga_load load = { + .buf = buf, + .bsize = bsize, + .result = result + }; + + return event_notify(EVT_FPGA_LOAD, &load, sizeof(load)); + } + + return 0; +} + /* * Generic multiplexing code */ @@ -251,6 +266,7 @@ int fpga_load(int devnum, const void *buf, size_t bsize, bitstream_type bstype, int flags) { int ret_val = FPGA_FAIL; /* assume failure */ + int ret_notify; const fpga_desc *desc = fpga_validate(devnum, buf, bsize, (char *)__func__);
@@ -284,6 +300,10 @@ int fpga_load(int devnum, const void *buf, size_t bsize, bitstream_type bstype, } }
+ ret_notify = fpga_load_event_notify(buf, bsize, ret_val); + if (ret_notify) + return ret_notify; + return ret_val; }
diff --git a/include/event.h b/include/event.h index fe41080fa6..daf44bf8a8 100644 --- a/include/event.h +++ b/include/event.h @@ -11,6 +11,7 @@ #define __event_h
#include <dm/ofnode_decl.h> +#include <linux/types.h>
/** * enum event_t - Types of events supported by U-Boot @@ -31,6 +32,9 @@ enum event_t { /* Init hooks */ EVT_MISC_INIT_F,
+ /* Fpga load hook */ + EVT_FPGA_LOAD, + /* Device tree fixups before booting */ EVT_FT_FIXUP,
@@ -59,6 +63,19 @@ union event_data { struct udevice *dev; } dm;
+ /** + * struct event_fpga_load - fpga load event + * + * @buf: The buffer that was loaded into the fpga + * @bsize: The size of the buffer that was loaded into the fpga + * @result: Result of the load operation + */ + struct event_fpga_load { + const void *buf; + size_t bsize; + int result; + } fpga_load; + /** * struct event_ft_fixup - FDT fixup before booting *

On Thu, Jul 20, 2023 at 09:27:24AM +0200, christian.taedcke-oss@weidmueller.com wrote:
From: Christian Taedcke christian.taedcke@weidmueller.com
This enables implementing custom logic after a bitstream was loaded into the fpga.
Signed-off-by: Christian Taedcke christian.taedcke@weidmueller.com Reviewed-by: Simon Glass sjg@chromium.org
Reviewed-by: Tom Rini trini@konsulko.com

On 7/20/23 09:27, christian.taedcke-oss@weidmueller.com wrote:
From: Christian Taedcke christian.taedcke@weidmueller.com
This enables implementing custom logic after a bitstream was loaded into the fpga.
Signed-off-by: Christian Taedcke christian.taedcke@weidmueller.com Reviewed-by: Simon Glass sjg@chromium.org
Changes in v5:
- remove changes from kmcent2 board file
- add missing include to event.h
Changes in v4:
- add include common.h to kmcent2 board file
Changes in v3:
- replace #if with if
- remove previously added printf
- return notification error from fpga_load()
- fix static_assert checking event name list
Changes in v2:
replace __weak function with a new event
common/event.c | 3 +++ drivers/fpga/fpga.c | 20 ++++++++++++++++++++ include/event.h | 17 +++++++++++++++++ 3 files changed, 40 insertions(+)
diff --git a/common/event.c b/common/event.c index 164c95f8f5..20720c5283 100644 --- a/common/event.c +++ b/common/event.c @@ -36,6 +36,9 @@ const char *const type_name[] = { /* init hooks */ "misc_init_f",
- /* Fpga load hook */
- "fpga_load",
- /* fdt hooks */ "ft_fixup",
diff --git a/drivers/fpga/fpga.c b/drivers/fpga/fpga.c index 7f6b6bc73a..81e6d8ffc0 100644 --- a/drivers/fpga/fpga.c +++ b/drivers/fpga/fpga.c @@ -244,6 +244,21 @@ int fpga_loads(int devnum, const void *buf, size_t size, } #endif
+static int fpga_load_event_notify(const void *buf, size_t bsize, int result) +{
- if (CONFIG_IS_ENABLED(EVENT)) {
struct event_fpga_load load = {
.buf = buf,
.bsize = bsize,
.result = result
};
return event_notify(EVT_FPGA_LOAD, &load, sizeof(load));
- }
- return 0;
+}
- /*
*/
- Generic multiplexing code
@@ -251,6 +266,7 @@ int fpga_load(int devnum, const void *buf, size_t bsize, bitstream_type bstype, int flags) { int ret_val = FPGA_FAIL; /* assume failure */
- int ret_notify; const fpga_desc *desc = fpga_validate(devnum, buf, bsize, (char *)__func__);
@@ -284,6 +300,10 @@ int fpga_load(int devnum, const void *buf, size_t bsize, bitstream_type bstype, } }
- ret_notify = fpga_load_event_notify(buf, bsize, ret_val);
- if (ret_notify)
return ret_notify;
- return ret_val; }
diff --git a/include/event.h b/include/event.h index fe41080fa6..daf44bf8a8 100644 --- a/include/event.h +++ b/include/event.h @@ -11,6 +11,7 @@ #define __event_h
#include <dm/ofnode_decl.h> +#include <linux/types.h>
/**
- enum event_t - Types of events supported by U-Boot
@@ -31,6 +32,9 @@ enum event_t { /* Init hooks */ EVT_MISC_INIT_F,
- /* Fpga load hook */
- EVT_FPGA_LOAD,
- /* Device tree fixups before booting */ EVT_FT_FIXUP,
@@ -59,6 +63,19 @@ union event_data { struct udevice *dev; } dm;
- /**
* struct event_fpga_load - fpga load event
*
* @buf: The buffer that was loaded into the fpga
* @bsize: The size of the buffer that was loaded into the fpga
* @result: Result of the load operation
*/
- struct event_fpga_load {
const void *buf;
size_t bsize;
int result;
- } fpga_load;
- /**
- struct event_ft_fixup - FDT fixup before booting
I forget to reply that I applied this patch. Already merged to main repo as a1190b4d6a9bf3a45038e3eba4a11de4be2b1cca.
Thanks, Michal
participants (3)
-
christian.taedcke-oss@weidmueller.com
-
Michal Simek
-
Tom Rini