New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
drivers: fpga: Added altera FPGA bridge support #71360
drivers: fpga: Added altera FPGA bridge support #71360
Conversation
As discussed in the Architecture group meeting moved fpga bridges from subsystem to driver. Kindly review this PR |
drivers/fpga/fpga_altera.c
Outdated
|
||
static int altera_fpga_on(const struct device *dev) | ||
{ | ||
int32_t ret = 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Incorrect indentation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
drivers/fpga/fpga_altera.c
Outdated
|
||
static int altera_fpga_init(const struct device *dev) | ||
{ | ||
if (!dev) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
Looks nice in general, please fix the compliance checks first (note you can also run them locally, so you don't have to wait for the CI run to be approved with each iteration) |
drivers/fpga/fpga_altera.c
Outdated
static const struct fpga_driver_api altera_fpga_api = { | ||
.on = altera_fpga_on, | ||
.off = altera_fpga_off | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately the subsystem currently requires the remaining callbacks to be defined, so that cannot go in like this.
At the very least we'd need to modify the common layer to allow NULLs for the rest and return -ENOTSUP. Otherwise you might see random issues when sb tries to use your driver
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
b657eaa
to
4462789
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we want to allow having only selected capabilities, we need to expand the common layer imo, e.g, add checks for NULL here:
zephyr/include/zephyr/drivers/fpga.h
Lines 128 to 131 in 9b17a95
const struct fpga_driver_api *api = | |
(const struct fpga_driver_api *)dev->api; | |
return api->get_info(dev); |
And return -ENOSUP there (in the common layer).
In addition we need to make sure the returned value is used wherever the driver is used (e.g. in the fpga shell implementation).
Otherwise I think it will too fragile.
drivers/fpga/fpga_altera.c
Outdated
static const char *altera_fpga_get_info(const struct device *dev) | ||
{ | ||
ARG_UNUSED(dev); | ||
return NULL; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am afraid it still won't work, the FPGA layer is too limited at this point.
You'll get a NULL here:
zephyr/include/zephyr/drivers/fpga.h
Lines 126 to 132 in 9b17a95
static inline const char *fpga_get_info(const struct device *dev) | |
{ | |
const struct fpga_driver_api *api = | |
(const struct fpga_driver_api *)dev->api; | |
return api->get_info(dev); | |
} |
and it will propagate here:
zephyr/drivers/fpga/fpga_shell.c
Line 127 in 9b17a95
shell_print(sh, "%s", fpga_get_info(dev)); |
It is similar for other functions as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tgorochowik Agree, NULL will be propagated to fpga_shell but we can't return -ENOSUP from the common layer i.e. fpga.h as the return type for the fpga_get_info function is of type "char *" or you are suggestion is to return "-ENOSUP" as string.
Either way, we have to return NULL or "-ENOSUP" either from the driver or from the common layer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a significant reason to return NULL
or "-ENOTSUP"
here?
For lack of a better option, you could return e.g. the crc of the bitstream if it is loaded, otherwise, an empty string.
zephyr/drivers/fpga/fpga_ice40.c
Line 495 in e3ff993
static const char *fpga_ice40_get_info(const struct device *dev) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @cfriedt for you valuable comment I agree with you we can return the empty string in this case
drivers/fpga/fpga_altera.c
Outdated
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
#define DT_DRV_COMPAT intel_fpga |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not a lawyer or anything, but as of 2024 Altera is again a separate corporate entity (still a subsidiary of Intel).
Would it make sense to maybe use altera_fpga
here? If so, please ensure it's in dts/bindings/vendor-prefixes.txt
Also, given that this is an SoC FPGA (i.e. has hard-cores) and that there are many other FPGAs in the product line, I would suggest using a more differentiating DT compatible such as altera,agilex-socfpga-bridge
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your suggestion @cfriedt I made the required changes
drivers/fpga/fpga_altera.c
Outdated
} | ||
|
||
/* Will send the SMC command to check the status of the FPGA */ | ||
static int32_t is_fpga_config_not_ready(void) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might be better to rename this so that it provides non-inverted logical operation (adjust return value as necessary).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
drivers/fpga/fpga_altera.c
Outdated
} | ||
|
||
/* Check FPGA status before bridge enable/disable */ | ||
ret = is_fpga_config_not_ready(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would suggest using a name that implies non-inverted logic
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
drivers/fpga/fpga_altera.c
Outdated
static const char *altera_fpga_get_info(const struct device *dev) | ||
{ | ||
ARG_UNUSED(dev); | ||
return NULL; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a significant reason to return NULL
or "-ENOTSUP"
here?
For lack of a better option, you could return e.g. the crc of the bitstream if it is loaded, otherwise, an empty string.
zephyr/drivers/fpga/fpga_ice40.c
Line 495 in e3ff993
static const char *fpga_ice40_get_info(const struct device *dev) |
4462789
to
053b4e0
Compare
drivers/fpga/fpga_altera.h
Outdated
* is useful for matching responses to commands along with the ID | ||
*/ | ||
uint32_t client_id : 4; | ||
} header_t; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is not a typedef so it probably makes sense to remove the _t
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
drivers/fpga/fpga_altera.h
Outdated
#include <zephyr/sip_svc/sip_svc.h> | ||
#include <zephyr/drivers/sip_svc/sip_svc_agilex_smc.h> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are these two headers required by anything in this file? If not, please include them where they are needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
@@ -99,6 +99,10 @@ | |||
reg = <0x10000000 0x200000>; | |||
}; | |||
|
|||
fpga0: bridges { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't there be an address associated with this device inside of the fpga SoC?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actaully we are not directly interacting with any hardware we are calling sip_svc subsystem which further request the ATF to read and write in the bridge register so this bridge dont have any address
@@ -97,6 +97,10 @@ | |||
reg = <0x80100000 DT_SIZE_M(8)>; | |||
}; | |||
|
|||
fpga0: bridges { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't there be an address associated with this device inside of the fpga SoC?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same for here
drivers/fpga/fpga_altera.h
Outdated
}; | ||
|
||
/* SIP SVC response private data */ | ||
struct private_data_t { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not typedef'ed so please remove the _t
struct private_data_t { | |
struct private_data { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
drivers/fpga/Kconfig.altera
Outdated
# Copyright (c) 2024, Intel Corporation. All rights reserved. | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
config ALTERA_FPGA |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this is only one type of interface (agilex bridge) it might be best to rename this option, because. Otherwise, it might be mistaken as support for all altera fpgas
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
drivers/fpga/fpga_altera.c
Outdated
@@ -0,0 +1,463 @@ | |||
/* |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
File name should have agilex bridge appended
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
053b4e0
to
264c764
Compare
static uint32_t mailbox_client_token; | ||
static struct sip_svc_controller *mailbox_smc_dev; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are duplicates definitions and should be removed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
static uint32_t mailbox_client_token; | ||
static struct sip_svc_controller *mailbox_smc_dev; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The devicetree bindings for this driver should include a phandle property that refers to the sip_svc_controller.
That phandle / address should be stored as compile-time const data in a struct <driver>_config
.
Similarly, the mailbox client token should be part of a struct <driver>_data
assuming it is mutable and only runtime discoverable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cfriedt As discussed in the architecture review meeting, we have made a dummy node in the device tree for this driver as it doesn't need the information about the SiP SVC controller. As the SiP SVC device node will be
returned by "sip_svc_get_controller" function declared in "zephyr/sip_svc/sip_svc.h" file and it is a subsystem, not a driver.
Yes, for the other comment regarding keeping the information in the struct _data, we agree it should be kept the way you mentioned.
.off = altera_fpga_off, | ||
}; | ||
|
||
DEVICE_DT_DEFINE(DT_NODELABEL(fpga0), &altera_fpga_init, NULL, NULL, NULL, POST_KERNEL, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be preferable to instantiate this with a macro - DT_INST_FOREACH_STATUS_OKAY()
.
With that, we need an instance to be added to some devicetree in a build_all testsuite
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
c4eb8da
to
3466386
Compare
3466386
to
7f7de85
Compare
7f7de85
to
eca7369
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks OK for me, with the caveat that the Arch WG approved of having no DT entry. It would be nice to have eventually, but it's not a blocking issue.
@hardeepsharma95 - I might have approved prematurely. We still need a "build_all" test that incorporates this driver into CI so that we know it's healthy. |
Added altera FPGA bridge support Signed-off-by: Hardeep Sharma <hardeep.sharma@intel.com>
eca7369
to
31dc1e8
Compare
done |
CONFIG_ALTERA_AGILEX_BRIDGE_FPGA=y | ||
CONFIG_ARM_SIP_SVC_DRIVER=y | ||
CONFIG_ARM_SIP_SVC_SUBSYS=y | ||
CONFIG_ARM_SIP_SVC_SUBSYS_SINGLY_OPEN=y | ||
CONFIG_HEAP_MEM_POOL_SIZE=16384 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These should be added to prj.conf
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
@@ -0,0 +1,9 @@ | |||
# Copyright (c) 2024, Intel Corporation. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file can probably be removed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
&sip_smc { | ||
status = "okay"; | ||
zephyr,num-clients = <2>; | ||
}; | ||
|
||
&fpga0 { | ||
status = "okay"; | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These nodes do not exist in native_posix
or native_sim
so they cannot be extended this way.
Please add the nodes directly in the devicetree.
Also, be sure to test with
twister -i -T tests/drivers/build_all/fpga
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
Altera FPGA driver should be built on a regular basis to ensure that there are no regressions Signed-off-by: Hardeep Sharma <hardeep.sharma@intel.com>
31dc1e8
to
1a553c0
Compare
Kindly review and approve this PR |
1 similar comment
Kindly review and approve this PR |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM - thanks for your patience 🙏
Hello All , |
Hi @hardeepsharma95! To celebrate this milestone and showcase your contribution, we'd love to award you the Zephyr Technical Contributor badge. If you're interested, please claim your badge by filling out this form: Claim Your Zephyr Badge. Thank you for your valuable input, and we look forward to seeing more of your contributions in the future! 🪁 |
Added FPGA Bridge Enable/Disable functionality :
Adding support for Agilex & Agilex5