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

Add mt8195 platform specific changes #4725

Merged
merged 3 commits into from
Sep 10, 2021

Conversation

kuanhsuncheng
Copy link
Contributor

Hi sirs,

This is Allen Cheng from MediaTek.

There are some commits I don't put in the previous pull request.

Most of them will modify the common code in sof.

Some are hw restriction (compile error) and feature(mpu) when we develop mt8195 in chromebook.

If there is any comments, please let me know.

Thanks.

Copy link
Member

@lgirdwood lgirdwood left a comment

Choose a reason for hiding this comment

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

I think we just need the Kconfig selection of exclusive as this looks like its showing lots of red in CI (probably because it's not cache coherent like S32CLI on Intel DSPs).

src/arch/xtensa/include/arch/atomic.h Show resolved Hide resolved
src/arch/xtensa/include/arch/atomic.h Outdated Show resolved Hide resolved
Copy link
Contributor Author

@kuanhsuncheng kuanhsuncheng left a comment

Choose a reason for hiding this comment

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

Hi I add CONFIG_XTENSA_EXCLUSIVE in kconfig,

let me know if there is anything needs to be changed, thanks.

src/arch/xtensa/include/arch/atomic.h Show resolved Hide resolved
*a += value;
return *a;
#else
#error No atomic methods available.
Copy link
Contributor Author

@kuanhsuncheng kuanhsuncheng Sep 8, 2021

Choose a reason for hiding this comment

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

Hi @lgirdwood ,

Do I need to add XCHAL_HAVE_S32C1I?

if we use gcc to compile, it seems compiler will go to "#error No atomic methods available".

Copy link
Member

Choose a reason for hiding this comment

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

Yes. we need

#if CONFIG_LOCK_EXCLUSIVE && __XCC__ && XCHAL_EXCLUSIVE
 /* do this */
#elif XCHAL_S32C1I
/* do that */
#elif CONFIG_NUM_CORES == 1
/* do something else */
#else 
#error No atomic support for multicore system
#endif

Copy link
Member

Choose a reason for hiding this comment

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

See the CI build

warning: the int symbol CORE_COUNT (defined at src/platform/Kconfig:272) has a non-int default MP_NUM_CPUS (undefined)
-- MEU_OFFSET=1344
-- Configuring done
-- Generating done
-- Build files have been written to: /srv/home/jenkins/workspace/sof_generic_build/build_tgl_xcc
[  0%] Built target genconfig
--
                 from /srv/home/jenkins/workspace/sof_generic_build/src/include/sof/lib/dma.h:20,
                 from /srv/home/jenkins/workspace/sof_generic_build/src/platform/intel/cavs/include/cavs/drivers/dw-dma.h:14,
                 from /srv/home/jenkins/workspace/sof_generic_build/src/platform/tigerlake/include/platform/drivers/dw-dma.h:13,
                 from /srv/home/jenkins/workspace/sof_generic_build/src/include/sof/drivers/dw-dma.h:12,
                 from /srv/home/jenkins/workspace/sof_generic_build/src/platform/intel/cavs/lib/dma.c:11:
/srv/home/jenkins/workspace/sof_generic_build/src/arch/xtensa/include/arch/atomic.h:69:3: error: #error No atomic methods available.
/srv/home/jenkins/workspace/sof_generic_build/src/arch/xtensa/include/arch/atomic.h:106:3: error: #error No atomic methods available.
[ 45%] Building C object CMakeFiles/sof.dir/src/platform/intel/cavs/lib/mem_window.c.o
[ 45%] Building C object CMakeFiles/sof.dir/src/platform/intel/cavs/platform.c.o
make[3]: *** [CMakeFiles/sof.dir/build.make:118: CMakeFiles/sof.dir/src/platform/intel/cavs/lib/dma.c.o] Error 2

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi Liam,

For gcc-build, there is no XCHAL_HAVE_EXCLUSIVE and XCHAL_HAVE_S32C1I used,

I wonder how it handles those cases before.

Copy link
Member

@lgirdwood lgirdwood Sep 9, 2021

Choose a reason for hiding this comment

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

That's a good point - then I think its best if we have for atomic.h and spinlock.h a set of functions for EXCLUSIVE and the existing set of functions for S32C11I and a set of functions for UP and non atomic ISA. e.g.

#if XCHAL_HAVE_EXCLUSIVE && CONFIG_XTENSA_EXCLUSIVE && __XCC__

/* All EXCLUSIVE methods here */

static inline int32_t arch_atomic_add(atomic_t *a, int32_t value)
{
	/*reference xtos : xipc_misc.h*/
	int32_t result = 0;
	int32_t current;

	while (!result) {
		current = XT_L32EX((int32_t *)a);
		result = current + value;
		XT_S32EX(result, (int32_t *)a);
		XT_GETEX(result);
	}
	return current;
}

#elif XCHAL_S32C1I

/* all S32C1I methods here */

static inline int32_t arch_atomic_add(atomic_t *a, int32_t value)
{
	int32_t result, current;

	__asm__ __volatile__(
		"1:     l32i    %1, %2, 0\n"
		"       wsr     %1, scompare1\n"
		"       add     %0, %1, %3\n"
		"       s32c1i  %0, %2, 0\n"
		"       bne     %0, %1, 1b\n"
		: "=&a" (result), "=&a" (current)
		: "a" (&a->value), "a" (value)
		: "memory");

	return current;
}

#else 

/* The xtensa config has no atomic method ISA support - we can use normal integer arithmetic iff UP */
#if CONFIG_NUM_CORES > 1
#error No atomic ISA for SMP configuration
#endif

/* integer arithmetic methods here */
static inline int32_t arch_atomic_add(atomic_t *a, int32_t value)
{
  *a += value;
}
#endif

This is simple do to in both files and wont break anything.

@kuanhsuncheng kuanhsuncheng force-pushed the mt8195-dev branch 5 times, most recently from d64e1c7 to 7d1cac9 Compare September 9, 2021 08:30
@lgirdwood
Copy link
Member

@andyross fyi - for Zephyr support of xtensa EXCLUSIVE locking and MPU.

Copy link
Contributor Author

@kuanhsuncheng kuanhsuncheng left a comment

Choose a reason for hiding this comment

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

HI I found there is no CONFIG_NUM_CORES macro define.

so I use CONFIG_CORE_COUNT to check the current dsp core number.

And I am not sure the gcc case is ok or not.

let me know if there is anything needs to be changed, thanks.

*a += value;
return *a;
#else
#error No atomic methods available.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi Liam,

For gcc-build, there is no XCHAL_HAVE_EXCLUSIVE and XCHAL_HAVE_S32C1I used,

I wonder how it handles those cases before.

src/arch/xtensa/exc-dump.S Show resolved Hide resolved
src/arch/xtensa/xtos/reset-vector.S Show resolved Hide resolved
scripts/xtensa-build-all.sh Outdated Show resolved Hide resolved
src/drivers/mediatek/mt8195/CMakeLists.txt Outdated Show resolved Hide resolved
Copy link
Contributor Author

@kuanhsuncheng kuanhsuncheng left a comment

Choose a reason for hiding this comment

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

Update the new changes,

If there is any comments, please let me know.

Thanks.

@dbaluta
Copy link
Collaborator

dbaluta commented Sep 9, 2021

We can immediately merge the following patches:

  • drivers: mtk: remove superfluous variable for mt8195
  • build: remove unused files from build system
  • Kconfig: add mt8195 to Kconfig
  • scripts: Add mt8195 to build script

if you move them to another PR and leave time for others to review the rest of the patches which look to be a little bit more delicate :)

Copy link
Member

@lgirdwood lgirdwood left a comment

Choose a reason for hiding this comment

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

@kuanhsuncheng these are all good to merge except the atomic one as it needs an update.

@@ -65,6 +105,39 @@ static inline int32_t arch_atomic_sub(atomic_t *a, int32_t value)
return current;
}

#else

#if CONFIG_CORE_COUNT > 1 && __XCC__
Copy link
Member

Choose a reason for hiding this comment

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

We dont need the __XCC__ here as we are saying that the ISA has no multicore instructions and SMP has been selected. This is not compiler related.

@@ -28,6 +28,18 @@ static inline void arch_spin_lock(spinlock_t *lock)
{
uint32_t result;

#if XCHAL_HAVE_EXCLUSIVE && CONFIG_XTENSA_EXCLUSIVE
Copy link
Member

Choose a reason for hiding this comment

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

I think it's cleaner if we do the same as atomic.h here i.e.

#if XCHAL_HAVE_EXCLUSIVE && CONFIG_XTENSA_EXCLUSIVE && __XCC__
/* all the EXCLUSIVE functions here */
#elif XCHAL_S321CI
/* all the S32 funcs here */
#else
/* error check for multicore */ 
/* all the integer functions here */
#endif

#error No atomic ISA for SMP configuration

#endif

Copy link
Member

Choose a reason for hiding this comment

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

Need to put a comment here (and a similar one in spinlock.h) that says
The ISA has no atomic operations so use integer arithmetic on uniprocessor systems. This helps support GCC and qemu emulation of certain targets.

current = arch_atomic_read(a);
result = current - value;
arch_atomic_set(a, value);
return result;
Copy link
Member

Choose a reason for hiding this comment

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

This should return current value, this way the caller know the value at the addition and the result (in a*).

current = arch_atomic_read(a);
result = current - value;
arch_atomic_set(a, value);
return result;
Copy link
Member

Choose a reason for hiding this comment

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

Should return current.

@kuanhsuncheng
Copy link
Contributor Author

kuanhsuncheng commented Sep 10, 2021

We can immediately merge the following patches:

  • drivers: mtk: remove superfluous variable for mt8195
  • build: remove unused files from build system
  • Kconfig: add mt8195 to Kconfig
  • scripts: Add mt8195 to build script

if you move them to another PR and leave time for others to review the rest of the patches which look to be a little bit more delicate :)

hi Daniel,

I agree that, it will be more clear for PR.

I create another PR for MT8196 build of sof.

#4741

For 4725, I leave some specific patches for mt8192.

Thanks for your comment.

This results in a compiler error
when xtensa configuration has no IRQ level 5.
Make it use core-isa.h.

Error:
invalid register 'EPC5' for 'rsr' instruction
Error:
invalid register 'EPS5' for 'rsr' instruction

For mt8195, we don't support those instrucations

Signed-off-by: YC Hung <[email protected]>
Signed-off-by: Allen-KH Cheng <[email protected]>
Override the default MPU setup.
This table matches the mt8195 memory map

Add xtensa/mpuasm.h, for mpu_write_map opcode

Signed-off-by: YC Hung <[email protected]>
Signed-off-by: Allen-KH Cheng <[email protected]>
In mp_asm.S, if XCHAL_HAVE_EXCLUSIVE is defined,
it will use exclusive instructions,
else it will use s32c1i instructions.

It supports S32C1I and exclusive instruction in xthal_compare_and_set() API.
Refer to xtos-simc-mutex.c, xtos_mutex_p structure is similar to spinlock_t.

For dsp design, we cannot use s32c1i intrcutions in mt8195.

In order to not affect other platform, add CONFIG_XTENSA_EXCLUSIVE and __XCC__
compile options.

Signed-off-by: YC Hung <[email protected]>
Signed-off-by: Allen-KH Cheng <[email protected]>
Copy link
Contributor Author

@kuanhsuncheng kuanhsuncheng left a comment

Choose a reason for hiding this comment

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

Hi

I update the new version.

Add spin lock simple implement for for UP

Also move build script patch to other PR.

let me know if there is anything needs to be changed, thanks.

@lgirdwood
Copy link
Member

CI showing unrelated timeouts on alsabat and suspend unrelated to this PR.

@lgirdwood lgirdwood merged commit 83093da into thesofproject:main Sep 10, 2021
@kuanhsuncheng kuanhsuncheng deleted the mt8195-dev branch September 13, 2021 09:09
uint32_t result;

lock->lock = 0;
result = 1;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Unused result variable, removal submitted in #9351

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.

4 participants