Skip to content

soc: mt6735: Add SMP fix so more than 1 cpu works - #160

Open
Kaloyan501 wants to merge 1 commit into
ivoszbg:masterfrom
Kaloyan501:master
Open

Kaloyan501 wants to merge 1 commit into
ivoszbg:masterfrom
Kaloyan501:master

Conversation

@Kaloyan501

Copy link
Copy Markdown
Contributor

Adds a SMP fix specific to the MT6735.
Almost verbatim copy of this repo: https://gitlab.com/mt6735-mainline/mt6735-smp-fix
License and the original owner allow integrating the code into this repo.
Screenshot of permission confirmation and link to public chat message can be provided if needed.
The diffs contain things like a WARNING while compiling and a running smp fix thing, which I think are nice, but if they are not neccessary I can remove them.

@Kaloyan501

Copy link
Copy Markdown
Contributor Author
20261021_225021.mp4

@Kaloyan501

Copy link
Copy Markdown
Contributor Author

Proof it works

@Kaloyan501

Copy link
Copy Markdown
Contributor Author

CPUs also show up in htop and pass a stress test
image

Comment thread soc/mediatek/mt6735-smp-fix.c Resolved

@BotchedRPR BotchedRPR left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This stuff is huge. Give me a few days to review.

Comment thread main/main.c Resolved
@Kaloyan501
Kaloyan501 force-pushed the master branch 2 times, most recently from b9060a2 to c4e765e Compare October 23, 2026 15:49
@Kaloyan501
Kaloyan501 requested a review from BotchedRPR October 23, 2026 15:52
@Aiden-Isik

Copy link
Copy Markdown
Contributor

I might be misunderstanding the purpose of this PR, but usually it is the kernel which brings up secondary CPUs, right? Bootloaders typically only run with one enabled.

@Kaloyan501

Copy link
Copy Markdown
Contributor Author

I might be misunderstanding the purpose of this PR, but usually it is the kernel which brings up secondary CPUs, right? Bootloaders typically only run with one enabled.

Read the description on the original repo, I just ported it over to uniLoader. If it works it works.

@Kaloyan501

Copy link
Copy Markdown
Contributor Author

Quote from the original repo README: MT6735 exposes a broken PSCI implementation that expects the kernel to power up the CPU's power domain on its own after the PSCI request has been sent. Work around that by booting up the CPUs before Linux starts and passing them via a spin-table

@Kaloyan501

Copy link
Copy Markdown
Contributor Author

Basically kernel cant bring the cpus up itself cause LK is broken (who would have expected that)

@BotchedRPR

Copy link
Copy Markdown
Collaborator

Basically kernel cant bring the cpus up itself cause LK is broken (who would have expected that)

Not lk but atf

@ivoszbg

ivoszbg commented Oct 28, 2026

Copy link
Copy Markdown
Owner

Can you indent with tabs, not spaces? also surely there's a better way to get this without parsing the board dt like that, hm

@Kaloyan501

Copy link
Copy Markdown
Contributor Author

Can you indent with tabs, not spaces? also surely there's a better way to get this without parsing the board dt like that, hm

God dammit, my text editor for some reason inputs spaces instead of a tab when I press the tab key. Will fix.

@Kaloyan501

Kaloyan501 commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor Author

Also there is definitely a better way to do it, I couldn't think of one at the time, any ideas are welcome!

@Kaloyan501

Copy link
Copy Markdown
Contributor Author

The indentations using spaces should be fixed now.

@chmcax chmcax left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

this is really dirty
also, this should be done in a small shim separate from uniLoader

Comment thread soc/mediatek/mt6735-smp-fix.c Resolved
Comment thread soc/mediatek/mt6735-smp-fix.c Resolved
Comment thread soc/mediatek/mt6735-smp-fix.c Resolved
Comment thread soc/mediatek/mt6735-smp-fix.c Resolved
Comment thread soc/mediatek/mt6735-smp-fix.c Resolved
Comment thread main/main.c
#include <lib/debug.h>

extern struct board_data board_ops;
void *board_dtb;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nitpick: there has to be a better way to do this

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I mean boards being able to access the dtb from early and late init is a good thing. What do you suggest as a better way, some function that returns the dtb or something else?

Comment thread soc/mediatek/mt6735-smp-fix.c Resolved
@BotchedRPR

Copy link
Copy Markdown
Collaborator

this is really dirty also, this should be done in a small shim separate from uniLoader

I disagree
uniLoader is literally made for stuff like this (see: exynos mmc regulator)
Having a shim in a shim is a bad bad practice...

@chmcax

chmcax commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

this is really dirty also, this should be done in a small shim separate from uniLoader

I disagree uniLoader is literally made for stuff like this (see: exynos mmc regulator) Having a shim in a shim is a bad bad practice...

I mean this basically is just that but within a uniLoader "driver"
also, regulators are toggled once on bootup, this code is executed on every CPU state change

@Kaloyan501

Kaloyan501 commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor Author

this is really dirty also, this should be done in a small shim separate from uniLoader

That shim already exists but is used with zImage64, check the original repo linked in the first message of this PR. The whole idea of porting it to uniLoader is to not have a shim in a shim. Also there is currently no other way I know of to bring up the secondary cpus of the MT6735 up on a mainline kernel apart from this shim (and subsequently the code in this PR). As for any inconsistencies and weirdness, this is literally a direct copy paste job of the code from the original repo, just with modifications of how the DT is read. Will see your other comments on the code itself tomorrow.

@chmcax chmcax left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Overall better, but please add a description of the quirk to the commit message (see commit e3bfa5e).

Comment thread soc/mediatek/mt6735-smp-fix.c Resolved
Comment thread soc/mediatek/mt6735-smp-fix.c Resolved
Comment thread soc/mediatek/mt6735-smp-fix.c Resolved
Comment thread soc/mediatek/mt6735-smp-fix.c Resolved
Comment thread soc/mediatek/mt6735-smp-fix.c Resolved
@Kaloyan501
Kaloyan501 force-pushed the master branch 2 times, most recently from d015318 to 66076cb Compare October 29, 2026 20:34
Comment thread soc/mediatek/mt6735-smp-fix.c Resolved
;
}

writel(readl(ctl) | SRAM_ISOINT_B, ctl);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

We need to write to this memory address 4 times? Do the values change? If so, why is there no waiting period to allow it to change? Shouldn't the bitwise ops be done just once if no?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Same answer as the hardcoded values, original repo does it like that, no idea why or if its needed for some weird janky reason.

Comment thread soc/mediatek/mt6735-smp-fix.c Resolved
Comment thread soc/mediatek/mt6735-smp-fix.c Resolved
Comment thread soc/mediatek/mt6735-smp-fix.c Resolved
extern char cpu_entry_end[];
extern uint64_t cpu_spin_table[3];

#define SPM_BASE 0x10000000UL

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

/methinks this could be a driver.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Should I move the whole file to driver/ or is that up for debate?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

yeah, ideally move it to drivers/mediatek

@Kaloyan501

Copy link
Copy Markdown
Contributor Author

Also latest changes are untested on device, just typing this here so I wont forget to check tomorrow.

@BotchedRPR

Copy link
Copy Markdown
Collaborator

@Kaloyan501

Submitting code that you don't understand isn't really all that good.
Who's expected to maintain said code if it breaks?

This code needs a refactor and if its not you who will do it then I am not sure who will...

No ill intentions on my part here but I'm not going to accept this code as it looks right now nor could help you much with a refactor even if I personally understand it, I don't have a device to test changes.

Nothing stands in your way of understanding the code and testing the refactor though

@Kaloyan501

Copy link
Copy Markdown
Contributor Author

Ok, I will try to research the purpose of the magic values and get back to you if I find their purpose.

@Kaloyan501

Copy link
Copy Markdown
Contributor Author

Ok, I think I found the purpose of some of them, will make a refactor with explanations where needed.

@Kaloyan501

Copy link
Copy Markdown
Contributor Author

@Kaloyan501

Copy link
Copy Markdown
Contributor Author

Also should I try to rewrite the ASM in C directly?

@Kaloyan501

Copy link
Copy Markdown
Contributor Author

About writing 4 times to the same memory address: downstream does it that way too. mt_spm_mtcmos.c CPU1 power-on branch, SPM Unlock Write.

@Kaloyan501

Kaloyan501 commented Oct 31, 2026 •

Copy link
Copy Markdown
Contributor Author

Also what I linked is the ground truth of all of this from the looks of it, so now I can answer any questions about magic numbers and such when needed.

@Kaloyan501

Kaloyan501 commented Oct 31, 2026 •

Copy link
Copy Markdown
Contributor Author

Also downstream code has udelay(1) on the register writes, I did not see that in the original code this PR is based on, the payload runs fine, but there is a non-0% chance that is just luck. If needed, I can add them.

@Kaloyan501

Copy link
Copy Markdown
Contributor Author

Also you said this code needs a refactor, I do not want to guess, please tell me in bulk what exactly it needs if you can, so I can do it in one go.

Comment thread soc/mediatek/mt6735-smp-fix.c Resolved
Comment thread soc/mediatek/mt6735-smp-fix.c Resolved
}
}

node = fdt_path_offset(fdt, "/reserved-memory/spin-table@0");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

whole reserve-memory part: @BotchedRPR @ivoszbg there should be a common reserve-memory function imo, there's probably gonna be other drivers that would need this

@BotchedRPR BotchedRPR left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

You added your dirty files here
Remove them so that I can genuinely review

@Kaloyan501

Copy link
Copy Markdown
Contributor Author

My gitignore got nuked, sorry about that. Will fix.

@Kaloyan501
Kaloyan501 force-pushed the master branch 4 times, most recently from 0bec63c to 9ea7c93 Compare November 12, 2026 23:56
MT6735 exposes a broken PSCI implementation that expects the kernel to power up the CPU's power domain on its own after the PSCI request has been sent.
Work around that by booting up the CPUs before Linux starts and later passing them via a spin-table in the device's DTS.

Based on [1].

[1]: https://gitlab.com/mt6735-mainline/mt6735-smp-fix

Signed-off-by: Kaloyan Donev <donevkaloyan@gmail.com>
@Kaloyan501

Copy link
Copy Markdown
Contributor Author

There is a regression, watchdog disabling does not work.

@Kaloyan501

Kaloyan501 commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor Author

Everything is fine, issue was caused by my outdated defconfig

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.

6 participants