Skip to content

Conversation

@ceolin
Copy link

@ceolin ceolin commented Aug 15, 2022

Some macros defined in SoF are also being defined in Zephyr.
Just avoiding redefinition un-defining these macros.

Signed-off-by: Flavio Ceolin flavio.ceolin@intel.com

@sofci
Copy link
Collaborator

sofci commented Aug 15, 2022

Can one of the admins verify this patch?

reply test this please to run this test once

@gkbldcig
Copy link
Collaborator

Can one of the admins verify this patch?

Copy link
Contributor

Choose a reason for hiding this comment

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

Found this via zephyrproject-rtos/zephyr#48963

This looks mildly dangerous to me. That resulting SOF code is going to get either the Zephyr or the SOF versions of these macros essentially arbitrarily, depending on header inclusion order.

Better to find the SOF definitions and put them under an #ifndef __ZEPHYR__, adding a #include <zephyr/sys/util.h> (or wherever these macros are) to the same file.

Copy link
Author

Choose a reason for hiding this comment

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

The problem is that this would require Zephyr to have all these macros defined there and if we change some name it will break SoF. To make it deterministic I can include zephyr header in this file, and keep this conditionals, this way we ensure that the inclusion order doesn't matter.

Copy link
Member

Choose a reason for hiding this comment

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

My preference here is to go full native (i.e. use the Zephyr macros directly), and only redefine locally when building for xtos (and this should be in a separate area).

Copy link
Author

Choose a reason for hiding this comment

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

we don't have all these macros on Zephyr and will not have. For example Zephyr has a different implementation for MASK. It means that we will need a slightly bigger change in SoF. Let me look it.

@ceolin
Copy link
Author

ceolin commented Aug 16, 2022

v2:
- Include Zephyr's header where macros are defined. It ensures that Zephyr will not redefine SoF macros.

@ceolin
Copy link
Author

ceolin commented Aug 16, 2022

v3:
- Changed to only define some macros when not building for Zephyr

Some macros defined in SoF are also being defined in Zephyr.
Just avoiding redefinition including Zephyr's header when building
with Zephyr.

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
@ceolin
Copy link
Author

ceolin commented Aug 16, 2022

v4:
- GET_BITS is not going to be exported by Zephyr at moment.zephyrproject-rtos/zephyr#48963 (comment)

@dbaluta
Copy link
Collaborator

dbaluta commented Aug 17, 2022

@ceolin I really like the way you add history of updates with v1, v2, ... v4. @lgirdwood we should keep in mind and use that for SOF more often.

#define SET_BITS(b_hi, b_lo, x) \
(((x) & ((1ULL << ((b_hi) - (b_lo) + 1ULL)) - 1ULL)) << (b_lo))
#define GET_BIT(b, x) \
(((x) & (1ULL << (b))) >> (b))
Copy link
Collaborator

Choose a reason for hiding this comment

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

not for this PR - I see GET_BIT() and SET_BITS() defined in Zephyr in DMIC and DAI driver headers with the latter being defined in two headers, maybe they could be moved to a common shared header

@lgirdwood
Copy link
Member

The long term direction for SOF on Zephyr platforms is that IP drivers will migrate to Zephyr i.e. the need for bit setting macros will be reduced. We will still need an aligned bit setting macro for xtos users though.

@lgirdwood
Copy link
Member

@ceolin can you check CI, looks like some build failures.

@ceolin
Copy link
Author

ceolin commented Aug 17, 2022

The long term direction for SOF on Zephyr platforms is that IP drivers will migrate to Zephyr i.e. the need for bit setting macros will be reduced. We will still need an aligned bit setting macro for xtos users though.

I have avoided to duplicate these macros on Zephyr in every driver but I hit a road blocker. These macros need a proper namespace, moving them a common place started to conflict with other subsystems / hals.

Regarding CI failing, that is the thing, this change requires the changes on Zephyr as well, it is the chicken and egg problem, Zephyr is also failing because SoF. One thing we can do to avoid break the code base is come back with that initial version that un-define the macros (to avoid re-definition), merge Zephyr changes, then we it again to this latest commit.

@lgirdwood
Copy link
Member

lgirdwood commented Aug 22, 2022

@ceolin fwiw - I'm looking at a more strict partitioning of RTOS headers and logic. See #6161
The intent is to make sure we have no contamination in the future between xtos code and zephyr code. Today this is quite tricky to rule out.

@kv2019i kv2019i marked this pull request as draft December 16, 2022 11:54
@kv2019i
Copy link
Collaborator

kv2019i commented Dec 16, 2022

No activity in a long time, converting as draft.

@ceolin ceolin closed this May 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants