Skip to content
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

Merged

Conversation

hardeepsharma95
Copy link
Contributor

Added FPGA Bridge Enable/Disable functionality :

Adding support for Agilex & Agilex5

@zephyrbot zephyrbot added area: ARM64 ARM (64-bit) Architecture area: FPGA Field-Programmable Gate Array (FPGA) platform: Intel SoC FPGA Agilex Intel Corporation, SoC FPGA Agilex labels Apr 10, 2024
@hardeepsharma95
Copy link
Contributor Author

As discussed in the Architecture group meeting moved fpga bridges from subsystem to driver.
Old PR :: #65753

Kindly review this PR


static int altera_fpga_on(const struct device *dev)
{
int32_t ret = 0;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Incorrect indentation

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done


static int altera_fpga_init(const struct device *dev)
{
if (!dev) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@tgorochowik
Copy link
Member

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)

Comment on lines 423 to 460
static const struct fpga_driver_api altera_fpga_api = {
.on = altera_fpga_on,
.off = altera_fpga_off
};
Copy link
Member

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@hardeepsharma95 hardeepsharma95 force-pushed the hps_bridges_latest branch 2 times, most recently from b657eaa to 4462789 Compare April 11, 2024 08:51
Copy link
Member

@tgorochowik tgorochowik left a 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:

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.

static const char *altera_fpga_get_info(const struct device *dev)
{
ARG_UNUSED(dev);
return NULL;
Copy link
Member

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:

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:

shell_print(sh, "%s", fpga_get_info(dev));

It is similar for other functions as well.

Copy link
Contributor

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.

Copy link
Member

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.

static const char *fpga_ice40_get_info(const struct device *dev)

Copy link
Contributor Author

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

* SPDX-License-Identifier: Apache-2.0
*/

#define DT_DRV_COMPAT intel_fpga
Copy link
Member

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.

Copy link
Contributor Author

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

}

/* Will send the SMC command to check the status of the FPGA */
static int32_t is_fpga_config_not_ready(void)
Copy link
Member

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).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

}

/* Check FPGA status before bridge enable/disable */
ret = is_fpga_config_not_ready();
Copy link
Member

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

static const char *altera_fpga_get_info(const struct device *dev)
{
ARG_UNUSED(dev);
return NULL;
Copy link
Member

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.

static const char *fpga_ice40_get_info(const struct device *dev)

* is useful for matching responses to commands along with the ID
*/
uint32_t client_id : 4;
} header_t;
Copy link
Member

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Comment on lines 11 to 12
#include <zephyr/sip_svc/sip_svc.h>
#include <zephyr/drivers/sip_svc/sip_svc_agilex_smc.h>
Copy link
Member

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.

Copy link
Contributor Author

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 {
Copy link
Member

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?

Copy link
Contributor Author

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 {
Copy link
Member

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same for here

};

/* SIP SVC response private data */
struct private_data_t {
Copy link
Member

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

Suggested change
struct private_data_t {
struct private_data {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

# Copyright (c) 2024, Intel Corporation. All rights reserved.
# SPDX-License-Identifier: Apache-2.0

config ALTERA_FPGA
Copy link
Member

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@@ -0,0 +1,463 @@
/*
Copy link
Member

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Comment on lines 19 to 20
static uint32_t mailbox_client_token;
static struct sip_svc_controller *mailbox_smc_dev;
Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Comment on lines 24 to 25
static uint32_t mailbox_client_token;
static struct sip_svc_controller *mailbox_smc_dev;
Copy link
Member

@cfriedt cfriedt Apr 19, 2024

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.

Copy link
Contributor

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,
Copy link
Member

@cfriedt cfriedt Apr 19, 2024

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

cfriedt
cfriedt previously approved these changes Apr 22, 2024
Copy link
Member

@cfriedt cfriedt left a 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.

@cfriedt
Copy link
Member

cfriedt commented Apr 22, 2024

@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>
@hardeepsharma95
Copy link
Contributor Author

@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.

done

Comment on lines 5 to 9
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
Copy link
Member

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

Copy link
Contributor Author

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.
Copy link
Member

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Comment on lines 48 to 53
&sip_smc {
status = "okay";
zephyr,num-clients = <2>;
};

&fpga0 {
status = "okay";
};
Copy link
Member

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

Copy link
Contributor Author

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>
@hardeepsharma95
Copy link
Contributor Author

Hi @tgorochowik @cfriedt

Kindly review and approve this PR

1 similar comment
@hardeepsharma95
Copy link
Contributor Author

Hi @tgorochowik @cfriedt

Kindly review and approve this PR

Copy link
Member

@cfriedt cfriedt left a 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 🙏

@hardeepsharma95
Copy link
Contributor Author

Hello All ,
Kindly review and approve this PR

@carlescufi carlescufi merged commit 792fd57 into zephyrproject-rtos:main Apr 26, 2024
21 checks passed
Copy link

Hi @hardeepsharma95!
Congratulations on getting your very first Zephyr pull request merged 🎉🥳. This is a fantastic achievement, and we're thrilled to have you as part of our community!

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! 🪁

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: ARM64 ARM (64-bit) Architecture area: FPGA Field-Programmable Gate Array (FPGA) area: Samples Samples area: Shell Shell subsystem platform: Intel SoC FPGA Agilex Intel Corporation, SoC FPGA Agilex
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants