MediaTek MT8192 APU
Subsystems (6)
cover MediaTek MT8192 APU
Add Support for MediaTek MT8192 APU.
The MediaTek AI Processing Unit (APU) is a proprietary hardware in the SoC to support AI functions.
The patches support the MT8192 APU running on internal microprocess. Software packages contins power control, tinysys controller and middleware.
This series is based on drivers implemented in
MT8192 apu power domain[1] and IOMMU[2] patches.
[1] https://patchwork.kernel.org/project/linux-mediatek/list/?series=568927
[2] https://patchwork.kernel.org/project/linux-mediatek/list/?series=551641
The device tree depends on [3][4][5] which haven't yet been accepted.
[3] https://patchwork.kernel.org/project/linux-mediatek/list/?series=521655
[4] https://patchwork.kernel.org/patch/12134935
[5] https://patchwork.kernel.org/patch/12140237
Flora Fu (12):
dt-bindings: soc: mediatek: apusys: add mt8192 apu iommu bindings
dt-bindings: soc: mediatek: apusys: Add new document for APU power
dt-bindings: soc: mediatek: apusys: Add new document for APU tinysys iommu/mediatek: Add APU iommu support
soc: mediatek: Add command for APU SMC call
soc: mediatek: apu: Add apu core driver
soc: mediatek: apu: Add apu power driver
soc: mediatek: apu: Add apusys rv driver
soc: mediatek: apu: Add middleware driver
arm64: dts: mt8192: Add apu power nodes
arm64: dts: mt8192: Add apu tinysys
arm64: dts: mt8192: Add regulator for APU
Yong Wu (1):
arm64: dts: mt8192: Add APU-IOMMU nodes
.../bindings/iommu/mediatek,iommu.yaml | 2 + .../soc/mediatek/mediatek,apu-pwr.yaml | 88 ++ .../soc/mediatek/mediatek,apu-rv.yaml | 140 +++ arch/arm64/boot/dts/mediatek/mt8192-evb.dts | 5 + arch/arm64/boot/dts/mediatek/mt8192.dtsi | 107 ++ drivers/iommu/mtk_iommu.c | 57 ++ drivers/soc/mediatek/Kconfig | 18 + drivers/soc/mediatek/apusys/Makefile | 22 + drivers/soc/mediatek/apusys/apu-config.h | 100 ++ drivers/soc/mediatek/apusys/apu-core.c | 97 ++ drivers/soc/mediatek/apusys/apu-core.h | 18 + drivers/soc/mediatek/apusys/apu-device.h | 39 + drivers/soc/mediatek/apusys/apu-ipi.c | 486 +++++++++ drivers/soc/mediatek/apusys/apu-mbox.c | 83 ++ drivers/soc/mediatek/apusys/apu-mbox.h | 27 + drivers/soc/mediatek/apusys/apu-pwr-dbg.c | 167 ++++ drivers/soc/mediatek/apusys/apu-pwr-ipi.c | 377 +++++++ drivers/soc/mediatek/apusys/apu-pwr.c | 599 +++++++++++ drivers/soc/mediatek/apusys/apu-pwr.h | 260 +++++ drivers/soc/mediatek/apusys/apu-rproc.c | 806 +++++++++++++++ drivers/soc/mediatek/apusys/apu-sw-logger.c | 429 ++++++++ drivers/soc/mediatek/apusys/apu.h | 256 +++++ drivers/soc/mediatek/apusys/mdw-cmd.c | 618 ++++++++++++ drivers/soc/mediatek/apusys/mdw-drv.c | 211 ++++ drivers/soc/mediatek/apusys/mdw-ioctl.c | 331 ++++++ drivers/soc/mediatek/apusys/mdw-ioctl.h | 256 +++++ drivers/soc/mediatek/apusys/mdw-mem.c | 938 ++++++++++++++++++ drivers/soc/mediatek/apusys/mdw-mem.h | 23 + drivers/soc/mediatek/apusys/mdw-rv-cmd.c | 158 +++ drivers/soc/mediatek/apusys/mdw-rv-dev.c | 386 +++++++ drivers/soc/mediatek/apusys/mdw-rv-msg.h | 90 ++ drivers/soc/mediatek/apusys/mdw-rv.c | 131 +++ drivers/soc/mediatek/apusys/mdw-rv.h | 98 ++ drivers/soc/mediatek/apusys/mdw-sysfs.c | 200 ++++ drivers/soc/mediatek/apusys/mdw.h | 208 ++++ drivers/soc/mediatek/apusys/mt81xx-plat.c | 320 ++++++ include/dt-bindings/memory/mt8192-larb-port.h | 4 + include/linux/soc/mediatek/mtk_sip_svc.h | 2 + 38 files changed, 8157 insertions(+) create mode 100644 Documentation/devicetree/bindings/soc/mediatek/mediatek,apu-pwr.yaml create mode 100644 Documentation/devicetree/bindings/soc/mediatek/mediatek,apu-rv.yaml create mode 100644 drivers/soc/mediatek/apusys/apu-config.h create mode 100644 drivers/soc/mediatek/apusys/apu-core.c create mode 100644 drivers/soc/mediatek/apusys/apu-core.h create mode 100644 drivers/soc/mediatek/apusys/apu-device.h create mode 100644 drivers/soc/mediatek/apusys/apu-ipi.c create mode 100644 drivers/soc/mediatek/apusys/apu-mbox.c create mode 100644 drivers/soc/mediatek/apusys/apu-mbox.h create mode 100644 drivers/soc/mediatek/apusys/apu-pwr-dbg.c create mode 100644 drivers/soc/mediatek/apusys/apu-pwr-ipi.c create mode 100644 drivers/soc/mediatek/apusys/apu-pwr.c create mode 100644 drivers/soc/mediatek/apusys/apu-pwr.h create mode 100644 drivers/soc/mediatek/apusys/apu-rproc.c create mode 100644 drivers/soc/mediatek/apusys/apu-sw-logger.c create mode 100644 drivers/soc/mediatek/apusys/apu.h create mode 100644 drivers/soc/mediatek/apusys/mdw-cmd.c create mode 100644 drivers/soc/mediatek/apusys/mdw-drv.c create mode 100644 drivers/soc/mediatek/apusys/mdw-ioctl.c create mode 100644 drivers/soc/mediatek/apusys/mdw-ioctl.h create mode 100644 drivers/soc/mediatek/apusys/mdw-mem.c create mode 100644 drivers/soc/mediatek/apusys/mdw-mem.h create mode 100644 drivers/soc/mediatek/apusys/mdw-rv-cmd.c create mode 100644 drivers/soc/mediatek/apusys/mdw-rv-dev.c create mode 100644 drivers/soc/mediatek/apusys/mdw-rv-msg.h create mode 100644 drivers/soc/mediatek/apusys/mdw-rv.c create mode 100644 drivers/soc/mediatek/apusys/mdw-rv.h create mode 100644 drivers/soc/mediatek/apusys/mdw-sysfs.c create mode 100644 drivers/soc/mediatek/apusys/mdw.h create mode 100644 drivers/soc/mediatek/apusys/mt81xx-plat.c
Signature · 1 line
2.18.0
RFC 1/13 dt-bindings: soc: mediatek: apusys: add mt8192 apu iommu bindings
Add mt8192 apu iommu bindings.
--- Documentation/devicetree/bindings/iommu/mediatek,iommu.yaml | 2 ++ 1 file changed, 2 insertions(+)
Documentation/devicetree/bindings/iommu/mediatek,iommu.yaml +2 -0
@@ -77,6 +77,7 @@ properties: - mediatek,mt8173-m4u # generation two - mediatek,mt8183-m4u # generation two - mediatek,mt8192-m4u # generation two + - mediatek,mt8192-iommu-apu # generation two - mediatek,mt8195-iommu-vdo # generation two - mediatek,mt8195-iommu-vpp # generation two - mediatek,mt8195-iommu-infra # generation two
@@ -154,6 +155,7 @@ allOf: compatible: enum: - mediatek,mt8192-m4u + - mediatek,mt8192-iommu-apu - mediatek,mt8195-iommu-vdo - mediatek,mt8195-iommu-vpp
Signature · 1 line
2.18.0
RFC 2/13 dt-bindings: soc: mediatek: apusys: Add new document for APU power
In reply to Flora FuAdd new document for APU power controller.
--- .../soc/mediatek/mediatek,apu-pwr.yaml | 88 +++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 Documentation/devicetree/bindings/soc/mediatek/mediatek,apu-pwr.yaml
Documentation/devicetree/bindings/soc/mediatek/mediatek,apu-pwr.yaml new file +88 -0
@@ -0,0 +1,88 @@ +# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) +# # Copyright 2021 MediaTek Inc. +%YAML 1.2 +--- +$id: "http://devicetree.org/schemas/soc/mediatek/mediatek,apu-pwr.yaml#" +$schema: "http://devicetree.org/meta-schemas/core.yaml#" + +title: Mediatek APU Power + +description: | + Mediatek AI Process Unit (APU) power driver support for subsys clock and + regulator controller. It will has device link to iommu-apu and apusys-rv + tinysys driver to ensure the power state is ready for hardware + in sub modules. + +maintainers: + - Flora Fu <[email protected]> + +properties: + compatible: + oneOf: + - const: mediatek,apusys-power + - items: + - const: mediatek,apusys-power + - const: mediatek,mt8192-apu-power + + reg: + minItems: 1 + + reg-names: + minItems: 1 + + power-domains: + maxItems: 1 + + vvpu-supply: + description: apu vpu regulator supply. + + vmdla-supply: + description: apu mdla regulator supply. + + clocks: + description: Contains module clock source and clock names + + clock-names: + description: Names of the clocks list in clocks property + +required: + - compatible + - reg + - reg-names + - clocks + - clock-names + - vvpu-supply + - vmdla-supply + +additionalProperties: false + +examples: + - | + #include <dt-bindings/clock/mt8192-clk.h> + apusys_power: apusys_power@190f1000 { + compatible = "mediatek,apusys-power", + "mediatek,mt8192-apu-power"; + reg = <0x190f1000 0x1000>; + reg-names = "apu_pcu"; + power-domains = <&apuspm 0>; + vvpu-supply = <&mt6359_vproc1_buck_reg>; + vmdla-supply = <&mt6359_vproc2_buck_reg>; + clocks = <&topckgen CLK_TOP_DSP_SEL>, + <&topckgen CLK_TOP_DSP1_SEL>, + <&topckgen CLK_TOP_DSP1_NPUPLL_SEL>, + <&topckgen CLK_TOP_DSP2_SEL>, + <&topckgen CLK_TOP_DSP2_NPUPLL_SEL>, + <&topckgen CLK_TOP_DSP5_SEL>, + <&topckgen CLK_TOP_DSP5_APUPLL_SEL>, + <&topckgen CLK_TOP_IPU_IF_SEL>, + <&clk26m>; + clock-names = "clk_top_dsp_sel", + "clk_top_dsp1_sel", + "clk_top_dsp1_npupll_sel", + "clk_top_dsp2_sel", + "clk_top_dsp2_npupll_sel", + "clk_top_dsp5_sel", + "clk_top_dsp5_apupll_sel", + "clk_top_ipu_if_sel", + "clk_top_clk26m"; + };
Signature · 1 line
2.18.0
RFC 3/13 dt-bindings: soc: mediatek: apusys: Add new document for APU tinysys
In reply to Flora FuAdd new document for APU tinysys.
--- .../soc/mediatek/mediatek,apu-rv.yaml | 140 ++++++++++++++++++ 1 file changed, 140 insertions(+) create mode 100644 Documentation/devicetree/bindings/soc/mediatek/mediatek,apu-rv.yaml
Documentation/devicetree/bindings/soc/mediatek/mediatek,apu-rv.yaml new file +140 -0
@@ -0,0 +1,140 @@ +# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) +# # Copyright 2021 MediaTek Inc. +%YAML 1.2 +--- +$id: "http://devicetree.org/schemas/soc/mediatek/mediatek,apu-rv.yaml#" +$schema: "http://devicetree.org/meta-schemas/core.yaml#" + +title: Mediatek APU Power + +description: | + APU integrated subsystem having MD32RV33 (MD32) that runs tinysys + The tinsys is running on a micro processor in APU. + Its firmware is load and boot from Kernel side. Kernel and tinysys use + IPI to tx/rx messages. + +maintainers: + - Flora Fu <[email protected]> + +properties: + compatible: + enum: + - mediatek,mt8192-apusys-rv + + reg: + minItems: 1 + + reg-names: + minItems: 1 + + power-domains: + maxItems: 1 + + iommus: + maxItems: 1 + + interrupts: + description: List of interrupts. + + interrupt-names: + description: Name list of interrupts. + + mediatek,apusys-power: + $ref: /schemas/types.yaml#/definitions/phandle + description: | + phandle to the device containing the apusys-power handle. + + apu_ctrl: + description: handle the ipi state, time sync and deep idle message. + type: object + + properties: + compatible: + const: "mediatek,apu-ctrl-rpmsg" + + required: + - compatible + + additionalProperties: false + + apu_pwr_tx: + description: handle the message trigger from AP side to tinysys. + type: object + + properties: + compatible: + const: "mediatek,apupwr-tx-rpmsg" + + required: + - compatible + + additionalProperties: false + + apu_pwr_rx: + description: handle the message trigger from tinysys to AP side. + type: object + + properties: + compatible: + const: "mediatek,apupwr-rx-rpmsg" + + required: + - compatible + + additionalProperties: false + + apu_mdw_rpmsg: + description: handle the middleware messages. + type: object + + properties: + compatible: + const: "mediatek,apu-mdw-rpmsg" + + required: + - compatible + + additionalProperties: false + +required: + - compatible + - reg + - power-domains + - interrupts + - mediatek,apusys-power + +additionalProperties: false + +examples: + - | + #include <dt-bindings/clock/mt8192-clk.h> + #include <dt-bindings/interrupt-controller/arm-gic.h> + #include <dt-bindings/interrupt-controller/irq.h> + #include <dt-bindings/memory/mt8192-larb-port.h> + + apusys_rv@19001000 { + compatible = "mediatek,mt8192-apusys-rv"; + reg = <0x19000000 0x1000>, + <0x19001000 0x1000>; + reg-names = "apu_mbox", + "md32_sysctrl"; + mediatek,apusys-power = <&apusys_power>; + power-domains = <&apuspm 0>; + iommus = <&iommu_apu IOMMU_PORT_APU_DATA>; + interrupts = <GIC_SPI 393 IRQ_TYPE_LEVEL_HIGH 0>, + <GIC_SPI 404 IRQ_TYPE_LEVEL_HIGH 0>; + interrupt-names = "apu_wdt", + "mbox0_irq"; + apu_ctrl { + compatible = "mediatek,apu-ctrl-rpmsg"; + }; + apu_pwr_tx { + compatible = "mediatek,apupwr-tx-rpmsg"; + }; + apu_pwr_rx { + compatible = "mediatek,apupwr-rx-rpmsg"; + }; + apu_mdw_rpmsg { + compatible = "mediatek,apu-mdw-rpmsg"; + }; + };
Signature · 1 line
2.18.0
RFC 4/13 iommu/mediatek: Add APU iommu support
In reply to Flora FuAPU IOMMU is a new iommu HW. it use a new pagetable. Add support for mt8192 apu iommu.
--- drivers/iommu/mtk_iommu.c | 57 +++++++++++++++++++ include/dt-bindings/memory/mt8192-larb-port.h | 4 ++ 2 files changed, 61 insertions(+)
drivers/iommu/mtk_iommu.c +57 -0
@@ -133,6 +133,7 @@/* 2 bits: iommu type */ #define MTK_IOMMU_TYPE_MM (0x0 << 13)#define MTK_IOMMU_TYPE_INFRA (0x1 << 13) +#define MTK_IOMMU_TYPE_APU (0x2 << 13)#define MTK_IOMMU_TYPE_MASK (0x3 << 13)#define IFA_IOMMU_PCIe_SUPPORT BIT(15)
@@ -185,6 +186,7 @@ static int mtk_iommu_hw_init(const struct mtk_iommu_data *data, unsigned int ban#define MTK_IOMMU_4GB_MODE_REMAP_BASE 0x140000000ULstatic LIST_HEAD (m4ulist);/* List all the M4U HWs */ +static LIST_HEAD (apulist);/* List the apu iommu HWs */ #define for_each_m4u (data, head) list_for_each_entry(data, head, list)
@@ -209,6 +211,13 @@ static const struct mtk_iommu_iova_region mt8192_multi_dom[] = {#endif }; +static const struct mtk_iommu_iova_region mt8192_multi_dom_apu[] = { + { .iova_base =0x0 , .size =SZ_4G },/* APU DATA */ + { .iova_base =0x4000000ULL , .size =0x4000000 },/* APU VLM */ + { .iova_base =0x10000000ULL , .size =0x10000000 },/* APU VPU */ + { .iova_base =0x70000000ULL , .size =0x12600000 },/* APU REG */ +}; +/* If 2 M4U share a domain(use the same hwlist), Put the corresponding info in first data.*/ static struct mtk_iommu_data *mtk_iommu_get_frst_data (struct list_head *hwlist) {
@@ -923,6 +932,37 @@ static int mtk_iommu_mm_dts_parse(struct device *dev,return 0 ; } +static int mtk_iommu_apu_prepare (struct device *dev) +{ +struct device_node *apupower_node; +struct platform_device *apudev; +struct device_link *link; + + apupower_node =of_find_compatible_node (NULL ,NULL ,"mediatek,apusys-power" ); +if (!apupower_node) { +dev_warn (dev,"Can't find apu power node!\n" ); +return -EINVAL ; + } + +if (!of_device_is_available (apupower_node)) { +of_node_put (apupower_node); +return -EPERM ; + } + + apudev =of_find_device_by_node (apupower_node); +if (!apudev) { +of_node_put (apupower_node); +return -EPROBE_DEFER ; + } + + link =device_link_add (&apudev->dev, dev,DL_FLAG_PM_RUNTIME ); +if (!link) +dev_err (dev,"Unable link %s.\n" , apudev->name); + +of_node_put (apupower_node); +return 0 ; +} +static int mtk_iommu_probe (struct platform_device *pdev) {struct mtk_iommu_data *data;
@@ -1021,6 +1061,10 @@ static int mtk_iommu_probe(struct platform_device *pdev) } data->pericfg = infracfg; + }else if (MTK_IOMMU_IS_TYPE (data->plat_data,MTK_IOMMU_TYPE_APU )) { + ret =mtk_iommu_apu_prepare (dev); +if (ret) + goto out_runtime_disable; }platform_set_drvdata (pdev, data);
@@ -1268,6 +1312,18 @@ static const struct mtk_iommu_plat_data mt8192_data = { {0, 14, 16}, {0, 13, 18, 17}}, }; +static const struct mtk_iommu_plat_data mt8192_data_apu = { + .m4u_plat =M4U_MT8192 , + .flags =WR_THROT_EN |DCM_DISABLE |MTK_IOMMU_TYPE_APU | +SHARE_PGTABLE , + .inv_sel_reg =REG_MMU_INV_SEL_GEN2 , + .hw_list = &apulist, + .bank_nr =1 , + .bank_enable = {true}, + .iova_region = mt8192_multi_dom_apu, + .iova_region_nr =ARRAY_SIZE (mt8192_multi_dom_apu), +}; +static const struct mtk_iommu_plat_data mt8195_data_infra = { .m4u_plat =M4U_MT8195 , .flags = WR_THROT_EN | DCM_DISABLE |
@@ -1323,6 +1379,7 @@ static const struct of_device_id mtk_iommu_of_ids[] = { { .compatible = "mediatek,mt8173-m4u", .data = &mt8173_data}, { .compatible = "mediatek,mt8183-m4u", .data = &mt8183_data}, { .compatible = "mediatek,mt8192-m4u", .data = &mt8192_data}, + { .compatible = "mediatek,mt8192-iommu-apu", .data = &mt8192_data_apu}, { .compatible = "mediatek,mt8195-iommu-infra", .data = &mt8195_data_infra}, { .compatible = "mediatek,mt8195-iommu-vdo", .data = &mt8195_data_vdo}, { .compatible = "mediatek,mt8195-iommu-vpp", .data = &mt8195_data_vpp},
include/dt-bindings/memory/mt8192-larb-port.h +4 -0
@@ -240,4 +240,8 @@#define M4U_PORT_L20_IPE_RSC_RDMA0 MTK_M4U_ID(20, 4)#define M4U_PORT_L20_IPE_RSC_WDMA MTK_M4U_ID(20, 5) +#define IOMMU_PORT_APU_DATA MTK_M4U_ID(0, 0) +#define IOMMU_PORT_APU_VLM MTK_M4U_ID(0, 1) +#define IOMMU_PORT_APU_VPU MTK_M4U_ID(0, 2) +#endif
Signature · 1 line
2.18.0
AngeloGioacchino Del Regno
maintainerRe: [RFC 04/13] iommu/mediatek: Add APU iommu support
Il 23/10/21 13:14, Flora Fu ha scritto:
Quoted 45 lines
APU IOMMU is a new iommu HW. it use a new pagetable. Add support for mt8192 apu iommu.
Signed-off-by Yong Wu <[email protected]>Signed-off-by Flora Fu <[email protected]>--- drivers/iommu/mtk_iommu.c | 57 +++++++++++++++++++ include/dt-bindings/memory/mt8192-larb-port.h | 4 ++ 2 files changed, 61 insertions(+)drivers/iommu/mtk_iommu.c +9
-0@@ -133,6 +133,7 @@/* 2 bits: iommu type */ #define MTK_IOMMU_TYPE_MM (0x0 << 13)#define MTK_IOMMU_TYPE_INFRA (0x1 << 13) +#define MTK_IOMMU_TYPE_APU (0x2 << 13)#define MTK_IOMMU_TYPE_MASK (0x3 << 13)#define IFA_IOMMU_PCIe_SUPPORT BIT(15)@@ -185,6 +186,7 @@ static int mtk_iommu_hw_init(const struct mtk_iommu_data *data, unsigned int ban#define MTK_IOMMU_4GB_MODE_REMAP_BASE 0x140000000ULstatic LIST_HEAD (m4ulist);/* List all the M4U HWs */ +static LIST_HEAD (apulist);/* List the apu iommu HWs */ #define for_each_m4u (data, head) list_for_each_entry(data, head, list)@@ -209,6 +211,13 @@ static const struct mtk_iommu_iova_region mt8192_multi_dom[] = {#endif }; +static const struct mtk_iommu_iova_region mt8192_multi_dom_apu[] = { + { .iova_base =0x0 , .size =SZ_4G },/* APU DATA */ + { .iova_base =0x4000000ULL , .size =0x4000000 },/* APU VLM */ + { .iova_base =0x10000000ULL , .size =0x10000000 },/* APU VPU */ + { .iova_base =0x70000000ULL , .size =0x12600000 },/* APU REG */ +}; +/* If 2 M4U share a domain(use the same hwlist), Put the corresponding info in first data.*/ static struct mtk_iommu_data *mtk_iommu_get_frst_data (struct list_head *hwlist) {
drivers/iommu/mtk_iommu.c static int mtk_iommu_mm_dts_parse(struct device *dev, · line 941
Quoted 10 lines
drivers/iommu/mtk_iommu.c +7
-0@@ -923,6 +932,37 @@ static int mtk_iommu_mm_dts_parse(struct device *dev,return 0 ; } +static int mtk_iommu_apu_prepare (struct device *dev) +{ +struct device_node *apupower_node; +struct platform_device *apudev; +struct device_link *link; + + apupower_node =of_find_compatible_node (NULL ,NULL ,"mediatek,apusys-power" );
Is it expected to have PM ops in the apusys-power driver? Currently, I can't see any, but maybe it's because of how complex is this entire implementation.
In any case, the name suggests that this controls power for the entire APU... so it would be more appropriate if apusys-power would expose a power domain (since it also has some sort of OPP, from what I can see), in which case you wouldn't be retrieving it here like you're doing right now... but simply as a power domain, simplifying the entire handling of that in here.
Quoted 79 lines
drivers/iommu/mtk_iommu.c +41
-0+if (!apupower_node) { +dev_warn (dev,"Can't find apu power node!\n" ); +return -EINVAL ; + } + +if (!of_device_is_available (apupower_node)) { +of_node_put (apupower_node); +return -EPERM ; + } + + apudev =of_find_device_by_node (apupower_node); +if (!apudev) { +of_node_put (apupower_node); +return -EPROBE_DEFER ; + } + + link =device_link_add (&apudev->dev, dev,DL_FLAG_PM_RUNTIME ); +if (!link) +dev_err (dev,"Unable link %s.\n" , apudev->name); + +of_node_put (apupower_node); +return 0 ; +} +static int mtk_iommu_probe (struct platform_device *pdev) {struct mtk_iommu_data *data;@@ -1021,6 +1061,10 @@ static int mtk_iommu_probe(struct platform_device *pdev) } data->pericfg = infracfg; + }else if (MTK_IOMMU_IS_TYPE (data->plat_data,MTK_IOMMU_TYPE_APU )) { + ret =mtk_iommu_apu_prepare (dev); +if (ret) + goto out_runtime_disable; }platform_set_drvdata (pdev, data);@@ -1268,6 +1312,18 @@ static const struct mtk_iommu_plat_data mt8192_data = { {0, 14, 16}, {0, 13, 18, 17}}, }; +static const struct mtk_iommu_plat_data mt8192_data_apu = { + .m4u_plat =M4U_MT8192 , + .flags =WR_THROT_EN |DCM_DISABLE |MTK_IOMMU_TYPE_APU | +SHARE_PGTABLE , + .inv_sel_reg =REG_MMU_INV_SEL_GEN2 , + .hw_list = &apulist, + .bank_nr =1 , + .bank_enable = {true}, + .iova_region = mt8192_multi_dom_apu, + .iova_region_nr =ARRAY_SIZE (mt8192_multi_dom_apu), +}; +static const struct mtk_iommu_plat_data mt8195_data_infra = { .m4u_plat =M4U_MT8195 , .flags = WR_THROT_EN | DCM_DISABLE |@@ -1323,6 +1379,7 @@ static const struct of_device_id mtk_iommu_of_ids[] = { { .compatible = "mediatek,mt8173-m4u", .data = &mt8173_data}, { .compatible = "mediatek,mt8183-m4u", .data = &mt8183_data}, { .compatible = "mediatek,mt8192-m4u", .data = &mt8192_data}, + { .compatible = "mediatek,mt8192-iommu-apu", .data = &mt8192_data_apu}, { .compatible = "mediatek,mt8195-iommu-infra", .data = &mt8195_data_infra}, { .compatible = "mediatek,mt8195-iommu-vdo", .data = &mt8195_data_vdo}, { .compatible = "mediatek,mt8195-iommu-vpp", .data = &mt8195_data_vpp},include/dt-bindings/memory/mt8192-larb-port.h +4
-0@@ -240,4 +240,8 @@#define M4U_PORT_L20_IPE_RSC_RDMA0 MTK_M4U_ID(20, 4)#define M4U_PORT_L20_IPE_RSC_WDMA MTK_M4U_ID(20, 5) +#define IOMMU_PORT_APU_DATA MTK_M4U_ID(0, 0) +#define IOMMU_PORT_APU_VLM MTK_M4U_ID(0, 1) +#define IOMMU_PORT_APU_VPU MTK_M4U_ID(0, 2) +#endif
Re: [RFC 04/13] iommu/mediatek: Add APU iommu support
Quoted 74 lines · AngeloGioacchino Del Regno
Il 23/10/21 13:14, Flora Fu ha scritto:
Quoted 57 lines
APU IOMMU is a new iommu HW. it use a new pagetable. Add support for mt8192 apu iommu.
Signed-off-by Yong Wu <[email protected]>Signed-off-by Flora Fu <[email protected]>--- drivers/iommu/mtk_iommu.c | 57 +++++++++++++++++++ include/dt-bindings/memory/mt8192-larb-port.h | 4 ++ 2 files changed, 61 insertions(+)drivers/iommu/mtk_iommu.c +1
-0@@ -133,6 +133,7 @@/* 2 bits: iommu type */ #define MTK_IOMMU_TYPE_MM (0x0 << 13)#define MTK_IOMMU_TYPE_INFRA (0x1 << 13) +#define MTK_IOMMU_TYPE_APU (0x2 << 13)#define MTK_IOMMU_TYPE_MASK (0x3 << 13)#define IFA_IOMMU_PCIe_SUPPORT BIT(15)@@ -185,6 +186,7 @@ static int mtk_iommu_hw_init(const struct
mtk_iommu_data*data, unsigned int ban
#defineMTK_IOMMU_4GB_MODE_REMAP_BASE0x140000000ULstatic
LIST_HEAD(m4ulist); /* List all the M4U HWs */
+staticLIST_HEAD(apulist); /* List the apu iommu HWs */#define
for_each_m4u(data, head)list_for_each_entry(data, head,
list)drivers/iommu/mtk_iommu.c +3
-0@@ -209,6 +211,13 @@ static const struct mtk_iommu_iova_region mt8192_multi_dom[] = { #endif }; +static const struct mtk_iommu_iova_region mt8192_multi_dom_apu[] = { + { .iova_base = 0x0, .size = SZ_4G}, /* APU DATA */ + { .iova_base = 0x4000000ULL, .size = 0x4000000}, /* APUVLM */
drivers/iommu/mtk_iommu.c +1
-0+ { .iova_base = 0x10000000ULL, .size = 0x10000000}, /* APUVPU */
drivers/iommu/mtk_iommu.c +1
-0+ { .iova_base = 0x70000000ULL, .size = 0x12600000}, /* APUREG */
drivers/iommu/mtk_iommu.c +2
-0+}; +/* If 2 M4U share a domain(use the same hwlist), Put the corresponding info in first data.*/
static structmtk_iommu_data*mtk_iommu_get_frst_data(structlist_head*hwlist)
{drivers/iommu/mtk_iommu.c +0
-0@@ -923,6 +932,37 @@ static int mtk_iommu_mm_dts_parse(structdevice *dev, return 0;drivers/iommu/mtk_iommu.c static int mtk_iommu_mm_dts_parse(struct · line 943
Quoted 10 lines
drivers/iommu/mtk_iommu.c +7
-0} +static int mtk_iommu_apu_prepare (struct device *dev) +{ +struct device_node *apupower_node; +struct platform_device *apudev; +struct device_link *link; + + apupower_node =of_find_compatible_node (NULL ,NULL ,"mediatek,apusys-power" );Is it expected to have PM ops in the apusys-power driver? Currently, I can't see
any, but maybe it's because of how complex is this entire implementation.
Quoted 11 lines
In any case, the name suggests that this controls power for the entire APU... so
it would be more appropriate if apusys-power would expose a power domain (since it
also has some sort of OPP, from what I can see), in which case you wouldn't be
retrieving it here like you're doing right now... but simply as a power domain,
simplifying the entire handling of that in here.
Hi, Angelo, Thanks for your comments.
In the design, we do use the power domain to enable the power for iommu and reset drivers.
In the APU hardware, it requires sharing all pages if it has more than one iommu in APU hardware. In current iommu driver, it can only wakeup one iommu device so we add the apusys-power as a wrapper to make all iommu resume/suspend at the same time. That's why you can also see another devices drivers, apusys_rv also links to apusys-power to comply with the flow.
Thanks for your comments. We will check your comments and try to optimze the wrapper device link.
Quoted 91 lines
Quoted 91 lines
drivers/iommu/mtk_iommu.c +24
-0+if (!apupower_node) { +dev_warn (dev,"Can't find apu power node!\n" ); +return -EINVAL ; + } + +if (!of_device_is_available (apupower_node)) { +of_node_put (apupower_node); +return -EPERM ; + } + + apudev =of_find_device_by_node (apupower_node); +if (!apudev) { +of_node_put (apupower_node); +return -EPROBE_DEFER ; + } + + link =device_link_add (&apudev->dev, dev,DL_FLAG_PM_RUNTIME ); +if (!link) +dev_err (dev,"Unable link %s.\n" , apudev->name); + +of_node_put (apupower_node); +return 0 ; +} +static int mtk_iommu_probe (struct platform_device *pdev){ struct mtk_iommu_data *data;drivers/iommu/mtk_iommu.c +4
-0@@ -1021,6 +1061,10 @@ static int mtk_iommu_probe(struct platform_device *pdev) } data->pericfg = infracfg; + }else if (MTK_IOMMU_IS_TYPE (data->plat_data,MTK_IOMMU_TYPE_APU )) { + ret =mtk_iommu_apu_prepare (dev); +if (ret) + goto out_runtime_disable; }platform_set_drvdata(pdev, data);drivers/iommu/mtk_iommu.c +3
-0@@ -1268,6 +1312,18 @@ static const struct mtk_iommu_plat_data mt8192_data = { {0, 14, 16}, {0, 13, 18, 17}}, }; +static const struct mtk_iommu_plat_data mt8192_data_apu = { + .m4u_plat =M4U_MT8192 , + .flags = WR_THROT_EN | DCM_DISABLE |
MTK_IOMMU_TYPE_APU|drivers/iommu/mtk_iommu.c +10
-0+ SHARE_PGTABLE, + .inv_sel_reg = REG_MMU_INV_SEL_GEN2, + .hw_list = &apulist, + .bank_nr = 1, + .bank_enable = {true}, + .iova_region = mt8192_multi_dom_apu, + .iova_region_nr = ARRAY_SIZE(mt8192_multi_dom_apu), +}; +static const struct mtk_iommu_plat_data mt8195_data_infra = { .m4u_plat =M4U_MT8195 , .flags = WR_THROT_EN | DCM_DISABLE |@@ -1323,6 +1379,7 @@ static const struct of_device_id mtk_iommu_of_ids[] = { { .compatible ="mediatek,mt8173-m4u" , .data = &mt8173_data}, { .compatible ="mediatek,mt8183-m4u" , .data = &mt8183_data}, { .compatible ="mediatek,mt8192-m4u" , .data = &mt8192_data}, + { .compatible ="mediatek,mt8192-iommu-apu" , .data = &mt8192_data_apu}, { .compatible = "mediatek,mt8195-iommu-infra", .data =
&mt8195_data_infra},
{ .compatible = "mediatek,mt8195-iommu-vdo", .data =&mt8195_data_vdo},
{ .compatible = "mediatek,mt8195-iommu-vpp", .data =&mt8195_data_vpp},include/dt-bindings/memory/mt8192-larb-port.h +1
-0@@ -240,4 +240,8 @@#define M4U_PORT_L20_IPE_RSC_RDMA0 MTK_M4U_ID(20, 4)#define M4U_PORT_L20_IPE_RSC_WDMA MTK_M4U_ID(20, 5) +#define IOMMU_PORT_APU_DATA MTK_M4U_ID(0,0)
include/dt-bindings/memory/mt8192-larb-port.h +3
-0+#define IOMMU_PORT_APU_VLM MTK_M4U_ID(0, 1) +#define IOMMU_PORT_APU_VPU MTK_M4U_ID(0, 2) +#endif
RFC 5/13 soc: mediatek: Add command for APU SMC call
In reply to Flora FuAdd command for APU SMC call.
The tinyys start and stop sequence will porcess in ATF.
--- include/linux/soc/mediatek/mtk_sip_svc.h | 2 ++ 1 file changed, 2 insertions(+)
include/linux/soc/mediatek/mtk_sip_svc.h +2 -0
@@ -22,4 +22,6 @@ARM_SMCCC_CALL_VAL (ARM_SMCCC_FAST_CALL ,MTK_SIP_SMC_CONVENTION , \ARM_SMCCC_OWNER_SIP , fn_id) +/* APUSYS SMC call */ +#define MTK_SIP_APUSYS_CONTROL MTK_SIP_SMC_CMD(0x51E)#endif
Signature · 1 line
2.18.0
RFC 6/13 soc: mediatek: apu: Add apu core driver
In reply to Flora FuAdd apu core driver.
The core driver will init the reset part of apu functions.
--- drivers/soc/mediatek/Kconfig | 18 +++++ drivers/soc/mediatek/apusys/Makefile | 3 + drivers/soc/mediatek/apusys/apu-core.c | 91 ++++++++++++++++++++++++++ drivers/soc/mediatek/apusys/apu-core.h | 11 ++++ 4 files changed, 123 insertions(+) create mode 100644 drivers/soc/mediatek/apusys/apu-core.c create mode 100644 drivers/soc/mediatek/apusys/apu-core.h
drivers/soc/mediatek/Kconfig +18 -0
@@ -24,6 +24,24 @@ config MTK_APU_PM APU power domain shall be enabled before accessing the internal sub modules. +config MTK_APU + tristate "MediaTek APUSYS Support" + select REGMAP + select MTK_APU_PM + select MTK_SCP + help + Say yes here to add support for the APU tinysys. The tinsys is + running on a micro processor in APU. + Its firmware is load and boot from Kernel side. Kernel and tinysys use + IPI to tx/rx messages. + +config MTK_APU_DEBUG + tristate "MediaTek APUSYS debug functions" + depends on MTK_APU + help + Say yes here to enalbe debug on APUSYS. + Disable it if you don't need them. + config MTK_CMDQ tristate "MediaTek CMDQ Support" depends on ARCH_MEDIATEK || COMPILE_TEST
drivers/soc/mediatek/apusys/Makefile +3 -0
@@ -1,2 +1,5 @@ # SPDX-License-Identifier: GPL-2.0 obj-$(CONFIG_MTK_APU_PM) += mtk-apu-pm.o + +obj-$(CONFIG_MTK_APU) += apu.o +apu-objs += apu-core.o
drivers/soc/mediatek/apusys/apu-core.c new file +91 -0
91 lines not on this page · raw message
drivers/soc/mediatek/apusys/apu-core.h new file +11 -0
@@ -0,0 +1,11 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Copyright (c) 2021 MediaTek Inc. +*/ +#ifndef APU_CORE_H +#define APU_CORE_H + +struct apusys_core_info { +struct dentry *dbg_root; +}; +#endif
Signature · 1 line
2.18.0
Re: [RFC 06/13] soc: mediatek: apu: Add apu core driver
Hi,
Quoted 5 lines · Flora Fu
drivers/soc/mediatek/Kconfig +0
-0
drivers/soc/mediatek/Kconfig config MTK_APU_PM · line 33
Quoted 10 lines
drivers/soc/mediatek/Kconfig +7
-0@@ -24,6 +24,24 @@ config MTK_APU_PM APU power domain shall be enabled before accessing the internal sub modules. +config MTK_APU + tristate "MediaTek APUSYS Support" + select REGMAP + select MTK_APU_PM + select MTK_SCP + help + Say yes here to add support for the APU tinysys. The tinsys is
tinysys runs on
drivers/soc/mediatek/Kconfig config MTK_APU_PM · line 34
Quoted 1 line
drivers/soc/mediatek/Kconfig +1
-0+ running on a micro processor in APU.
a microprocessor in the APU.
drivers/soc/mediatek/Kconfig config MTK_APU_PM · line 35
Quoted 1 line
drivers/soc/mediatek/Kconfig +1
-0+ Its firmware is load and boot from Kernel side. Kernel and tinysys use
is loaded and booted
drivers/soc/mediatek/Kconfig config MTK_APU_PM · line 36
Quoted 1 line
drivers/soc/mediatek/Kconfig +1
-0+ IPI to tx/rx messages.
to send/receive messages.
drivers/soc/mediatek/Kconfig config MTK_APU_PM · line 42
Quoted 6 lines
drivers/soc/mediatek/Kconfig +6
-0+ +config MTK_APU_DEBUG + tristate "MediaTek APUSYS debug functions" + depends on MTK_APU + help + Say yes here to enalbe debug on APUSYS.
enable
Quoted 1 line
drivers/soc/mediatek/Kconfig +1
-0+ Disable it if you don't need them.
Signature · 1 line
~Randy
Re: [RFC 06/13] soc: mediatek: apu: Add apu core driver
Quoted 28 lines · Randy Dunlap
Hi,
Quoted 16 lines · Flora Fu
drivers/soc/mediatek/Kconfig +7
-0@@ -24,6 +24,24 @@ config MTK_APU_PM APU power domain shall be enabled before accessing the internal sub modules. +config MTK_APU + tristate "MediaTek APUSYS Support" + select REGMAP + select MTK_APU_PM + select MTK_SCP + help + Say yes here to add support for the APU tinysys. The tinsysQuoted 1 line
is
tinysys
runs ondrivers/soc/mediatek/Kconfig config MTK_APU_PM · line 34
Quoted 1 line
drivers/soc/mediatek/Kconfig +1
-0+ running on a micro processor in APU.a microprocessor in the APU.
Quoted 8 lines
Quoted 2 lines
drivers/soc/mediatek/Kconfig +1
-0+ Its firmware is load and boot from Kernel side. Kernel andtinysys use
is loaded and booted
drivers/soc/mediatek/Kconfig config MTK_APU_PM · line 36
Quoted 1 line
drivers/soc/mediatek/Kconfig +1
-0+ IPI to tx/rx messages.to send/receive messages.
Ack.
Quoted 8 lines
drivers/soc/mediatek/Kconfig config MTK_APU_PM · line 42
Quoted 6 lines
drivers/soc/mediatek/Kconfig +6
-0+ +config MTK_APU_DEBUG + tristate "MediaTek APUSYS debug functions" + depends on MTK_APU + help + Say yes here to enalbe debug on APUSYS.enable
Ack.
The tpyo will be fix in the next submission.
Thanks for your review.
Quoted 4 lines
Quoted 2 lines
drivers/soc/mediatek/Kconfig +1
-0+ Disable it if you don't need them.
AngeloGioacchino Del Regno
maintainerRe: [RFC 06/13] soc: mediatek: apu: Add apu core driver
In reply to Flora FuIl 23/10/21 13:14, Flora Fu ha scritto:
Quoted 4 lines
Add apu core driver.
The core driver will init the reset part of apu functions.Signed-off-by Flora Fu <[email protected]>
Quoted 9 lines
--- drivers/soc/mediatek/Kconfig | 18 +++++ drivers/soc/mediatek/apusys/Makefile | 3 + drivers/soc/mediatek/apusys/apu-core.c | 91 ++++++++++++++++++++++++++ drivers/soc/mediatek/apusys/apu-core.h | 11 ++++ 4 files changed, 123 insertions(+)create mode 100644
drivers/soc/mediatek/apusys/apu-core.ccreate mode 100644drivers/soc/mediatek/apusys/apu-core.h
Hello Flora,
I don't think that this custom probe/init mechanism through apu-core.c can ever be a thing: you should simply register a number of platform drivers (likely modules) and let the kernel decide what to probe first, what to probe last, as it's done for every kernel driver.
I understand that this may reduce probe deferrals, as it's a controlled probe sequence, made specifically for apusys, but it's anyway something that won't give you big gains (and if it was, then you should still let the kernel decide and eventually optimize that mechanism somehow).
I want to note that, since this series is rather huge, I will probably do more than one incremental review of it... and for how things look, this will most probably be split to more than one series, to allow getting reviews from specific subsystem maintainers, leading to better code quality and robustness in the end.
Some more details are coming in reply of other patches in this series.
Thanks,
- Angelo
RFC 7/13 soc: mediatek: apu: Add apu power driver
In reply to Flora FuAPU power driver support for subsys clock and regulator controller. It has device link to iommu-apu and apusys-rv tinysys driver to ensure the power state is ready for hardware in sub modules.
--- drivers/soc/mediatek/apusys/Makefile | 4 + drivers/soc/mediatek/apusys/apu-core.c | 2 + drivers/soc/mediatek/apusys/apu-core.h | 3 + drivers/soc/mediatek/apusys/apu-pwr-dbg.c | 167 ++++++ drivers/soc/mediatek/apusys/apu-pwr-ipi.c | 377 ++++++++++++++ drivers/soc/mediatek/apusys/apu-pwr.c | 599 ++++++++++++++++++++++ drivers/soc/mediatek/apusys/apu-pwr.h | 260 ++++++++++ 7 files changed, 1412 insertions(+) create mode 100644 drivers/soc/mediatek/apusys/apu-pwr-dbg.c create mode 100644 drivers/soc/mediatek/apusys/apu-pwr-ipi.c create mode 100644 drivers/soc/mediatek/apusys/apu-pwr.c create mode 100644 drivers/soc/mediatek/apusys/apu-pwr.h
drivers/soc/mediatek/apusys/Makefile +4 -0
@@ -3,3 +3,7 @@ obj-$(CONFIG_MTK_APU_PM) += mtk-apu-pm.o obj-$(CONFIG_MTK_APU) += apu.o apu-objs += apu-core.o + +apu-objs += apu-pwr.o +apu-objs += apu-pwr-ipi.o +apu-$(CONFIG_MTK_APU_DEBUG) += apu-pwr-dbg.o
drivers/soc/mediatek/apusys/apu-core.c +2 -0
@@ -18,6 +18,7 @@ static struct apusys_core_info g_core_info;* call init function in order at apu.ko init stage */ static int (*apusys_init_func[])(struct apusys_core_info *) = { + apu_power_drv_init, };/*
@@ -25,6 +26,7 @@ static int (*apusys_init_func[])(struct apusys_core_info *) = {* call exit function in order at apu.ko exit stage */ static void (*apusys_exit_func[])(void ) = { + apu_power_drv_exit, };static void create_dbg_root (void )
drivers/soc/mediatek/apusys/apu-core.h +3 -0
@@ -8,4 +8,7 @@struct apusys_core_info {struct dentry *dbg_root; }; + +int apu_power_drv_init (struct apusys_core_info *info); +void apu_power_drv_exit (void );#endif
drivers/soc/mediatek/apusys/apu-pwr-dbg.c new file +167 -0
167 lines not on this page · raw message
drivers/soc/mediatek/apusys/apu-pwr-ipi.c new file +377 -0
377 lines not on this page · raw message
drivers/soc/mediatek/apusys/apu-pwr.c new file +599 -0
599 lines not on this page · raw message
drivers/soc/mediatek/apusys/apu-pwr.h new file +260 -0
260 lines not on this page · raw message
Signature · 1 line
2.18.0
RFC 8/13 soc: mediatek: apu: Add apusys rv driver
In reply to Flora FuAdd driver for control APU tinysys
APU integrated subsystem having MD32RV33 (MD32) that runs tinysys The tinsys is running on a micro processor in APU.
Its firmware is load and boot from Kernel side. Kernel and tinysys use IPI to tx/rx messages.
--- drivers/soc/mediatek/apusys/Makefile | 6 + drivers/soc/mediatek/apusys/apu-config.h | 100 +++ drivers/soc/mediatek/apusys/apu-core.c | 2 + drivers/soc/mediatek/apusys/apu-core.h | 2 + drivers/soc/mediatek/apusys/apu-ipi.c | 486 ++++++++++++ drivers/soc/mediatek/apusys/apu-mbox.c | 83 ++ drivers/soc/mediatek/apusys/apu-mbox.h | 27 + drivers/soc/mediatek/apusys/apu-rproc.c | 806 ++++++++++++++++++++ drivers/soc/mediatek/apusys/apu-sw-logger.c | 429 +++++++++++ drivers/soc/mediatek/apusys/apu.h | 256 +++++++ drivers/soc/mediatek/apusys/mt81xx-plat.c | 320 ++++++++ 11 files changed, 2517 insertions(+) create mode 100644 drivers/soc/mediatek/apusys/apu-config.h create mode 100644 drivers/soc/mediatek/apusys/apu-ipi.c create mode 100644 drivers/soc/mediatek/apusys/apu-mbox.c create mode 100644 drivers/soc/mediatek/apusys/apu-mbox.h create mode 100644 drivers/soc/mediatek/apusys/apu-rproc.c create mode 100644 drivers/soc/mediatek/apusys/apu-sw-logger.c create mode 100644 drivers/soc/mediatek/apusys/apu.h create mode 100644 drivers/soc/mediatek/apusys/mt81xx-plat.c
drivers/soc/mediatek/apusys/Makefile +6 -0
@@ -7,3 +7,9 @@ apu-objs += apu-core.o apu-objs += apu-pwr.o apu-objs += apu-pwr-ipi.o apu-$(CONFIG_MTK_APU_DEBUG) += apu-pwr-dbg.o + +apu-objs += apu-rproc.o +apu-objs += apu-ipi.o +apu-objs += apu-mbox.o +apu-objs += mt81xx-plat.o +apu-$(CONFIG_DEBUG_FS) += apu-sw-logger.o
drivers/soc/mediatek/apusys/apu-config.h new file +100 -0
100 lines not on this page · raw message
drivers/soc/mediatek/apusys/apu-core.c +2 -0
@@ -19,6 +19,7 @@ static struct apusys_core_info g_core_info;*/ static int (*apusys_init_func[])(struct apusys_core_info *) = { apu_power_drv_init, + apu_rproc_init, };/*
@@ -26,6 +27,7 @@ static int (*apusys_init_func[])(struct apusys_core_info *) = {* call exit function in order at apu.ko exit stage */ static void (*apusys_exit_func[])(void ) = { + apu_rproc_exit, apu_power_drv_exit, };
drivers/soc/mediatek/apusys/apu-core.h +2 -0
@@ -11,4 +11,6 @@ struct apusys_core_info {int apu_power_drv_init (struct apusys_core_info *info);void apu_power_drv_exit (void ); +int apu_rproc_init (struct apusys_core_info *info); +void apu_rproc_exit (void );#endif
drivers/soc/mediatek/apusys/apu-ipi.c new file +486 -0
486 lines not on this page · raw message
drivers/soc/mediatek/apusys/apu-mbox.c new file +83 -0
83 lines not on this page · raw message
drivers/soc/mediatek/apusys/apu-mbox.h new file +27 -0
@@ -0,0 +1,27 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Copyright (c) 2021 MediaTek Inc. +*/ + +#ifndef APU_MBOX_H +#define APU_MBOX_H + +struct apu_mbox_hdr { +unsigned int id; +unsigned int len; +unsigned int serial_no; +unsigned int csum; +}; + +#define APU_MBOX_SLOT_SIZE (4) +#define APU_MBOX_HDR_SLOTS \ + (sizeof(struct apu_mbox_hdr) / APU_MBOX_SLOT_SIZE) + +void apu_mbox_ack_outbox (struct mtk_apu *apu); +void apu_mbox_read_outbox (struct mtk_apu *apu,struct apu_mbox_hdr *hdr); +int apu_mbox_wait_inbox (struct mtk_apu *apu); +void apu_mbox_write_inbox (struct mtk_apu *apu,struct apu_mbox_hdr *hdr); +void apu_mbox_inbox_init (struct mtk_apu *apu); +void apu_mbox_hw_init (struct mtk_apu *apu); +void apu_mbox_hw_exit (struct mtk_apu *apu); +#endif /* APU_MBOX_H */
drivers/soc/mediatek/apusys/apu-rproc.c new file +806 -0
806 lines not on this page · raw message
drivers/soc/mediatek/apusys/apu-sw-logger.c new file +429 -0
429 lines not on this page · raw message
drivers/soc/mediatek/apusys/apu.h new file +256 -0
256 lines not on this page · raw message
drivers/soc/mediatek/apusys/mt81xx-plat.c new file +320 -0
320 lines not on this page · raw message
Signature · 1 line
2.18.0
AngeloGioacchino Del Regno
maintainerRe: [RFC 08/13] soc: mediatek: apu: Add apusys rv driver
Il 23/10/21 13:14, Flora Fu ha scritto:
Quoted 7 lines
Add driver for control APU tinysys
APU integrated subsystem having MD32RV33 (MD32) that runs tinysys The tinsys is running on a micro processor in APU.
Its firmware is load and boot from Kernel side. Kernel and tinysys use IPI to tx/rx messages.
Quoted 7 lines
Signed-off-by Flora Fu <[email protected]>--- drivers/soc/mediatek/apusys/Makefile | 6 + drivers/soc/mediatek/apusys/apu-config.h | 100 +++ drivers/soc/mediatek/apusys/apu-core.c | 2 + drivers/soc/mediatek/apusys/apu-core.h | 2 + drivers/soc/mediatek/apusys/apu-ipi.c | 486 ++++++++++++
I'm not sure of that, but your apu-ipi.c may be more suited to be in drivers/remoteproc instead.
Quoted 1 line
drivers/soc/mediatek/apusys/apu-mbox.c | 83 ++
apu-mbox.c should go to drivers/mailbox/ and you should register it with the mailbox API as a mailbox controller instead of what you're currently doing...
From what I see, you have functions in there that can be indeed mapped to struct mbox_chan_ops .send_data and .peek_data... also your function apu_mbox_wait_inbox seems to be waiting on an interrupt, and such irq is apparently your "mbox0_irq" (as you named it in the dt).
In that case, you can also manage that in your drivers/mailbox/ driver. +
Quoted 2 lines
drivers/soc/mediatek/apusys/apu-mbox.h | 27 + drivers/soc/mediatek/apusys/apu-rproc.c | 806 ++++++++++++++++++++
The apu-rproc.c driver seems to be a good candidate to be moved away from
drivers/soc/mediatek/apusys/ - as this is indeed a remoteproc driver.
Having it as drivers/remoteproc/mtk_apu.c seems to be a good option.
Quoted 1 line
drivers/soc/mediatek/apusys/apu-sw-logger.c | 429 +++++++++++
This one definitely belongs here in drivers/soc/mediatek, and it's a consumer of the mailbox driver.
Quoted 2 lines
drivers/soc/mediatek/apusys/apu.h | 256 +++++++ drivers/soc/mediatek/apusys/mt81xx-plat.c | 320 ++++++++
If we end up keeping to be in need to have a separate mt81xx-plat.c file, then I believe this should have another name, so that it becomes one that aggregates all of the very-platform-specific functions in one, instead of having one file for each platform.
Though, it may also be possible that this file will disappear entirely:
since most of the things here will be moved around, it may become mostly empty... but it's probably too soon to judge.
Quoted 10 lines
11 files changed, 2517 insertions(+)create mode 100644
drivers/soc/mediatek/apusys/apu-config.hcreate mode 100644drivers/soc/mediatek/apusys/apu-ipi.ccreate mode 100644drivers/soc/mediatek/apusys/apu-mbox.ccreate mode 100644drivers/soc/mediatek/apusys/apu-mbox.hcreate mode 100644drivers/soc/mediatek/apusys/apu-rproc.ccreate mode 100644drivers/soc/mediatek/apusys/apu-sw-logger.ccreate mode 100644drivers/soc/mediatek/apusys/apu.hcreate mode 100644drivers/soc/mediatek/apusys/mt81xx-plat.c
snip...
Quoted 5 lines
drivers/soc/mediatek/apusys/apu-ipi.c new file +0
-0
snip...
Quoted 29 lines
drivers/soc/mediatek/apusys/apu-ipi.c new file +29
-0+int apu_ipi_init (struct platform_device *pdev,struct mtk_apu *apu) +{ +struct device *dev = apu->dev; +int i, ret; + + tx_serial_no =0 ; + rx_serial_no =0 ; + +mutex_init (&apu->send_lock); +spin_lock_init (&apu->usage_cnt_lock); +for (i =0 ; i <APU_IPI_MAX ; i++) { +mutex_init (&apu->ipi_desc[i].lock); +lockdep_set_class_and_name (&apu->ipi_desc[i].lock, + &ipi_lock_key[i], + apu->platdata->ipi_attrs[i].name); + } + +init_waitqueue_head (&apu->run.wq); +init_waitqueue_head (&apu->ack_wq); + +/* APU initialization IPI register */ + ret =apu_ipi_register (apu,APU_IPI_INIT , apu_init_ipi_handler, apu); +if (ret) { +dev_err (dev,"failed to register ipi for init, ret=%d\n" , + ret); +return ret; + } + +/* add rpmsg subdev */
drivers/soc/mediatek/apusys/apu-ipi.c line 473
Quoted 10 lines
drivers/soc/mediatek/apusys/apu-ipi.c new file +10
-0+apu_add_rpmsg_subdev (apu); + +/* register mailbox IRQ */ + apu->mbox0_irq_number =platform_get_irq_byname (pdev,"mbox0_irq" ); +dev_info (&pdev->dev,"%s: mbox0_irq = %d\n" , __func__, + apu->mbox0_irq_number); + + ret =devm_request_threaded_irq (&pdev->dev, apu->mbox0_irq_number, +NULL , apu_ipi_handler,IRQF_ONESHOT , +"apu_ipi" , apu);
This is the mailbox interrupt... but it's handled in this driver instead of being handler in the mailbox driver... it's a bit confusing.
Is this interrupt supposed to fire as a mailbox doorbell or..? In that case, you should request it in the mailbox driver and register an interrupt controller (still, in the mailbox driver) so that you can export a sw interrupt to this one.
Or, maybe you can use notifiers to catch the mailbox message in this driver?
Quoted 13 lines
drivers/soc/mediatek/apusys/apu-ipi.c new file +13
-0+if (ret <0 ) + goto remove_rpmsg_subdev; + +apu_mbox_hw_init (apu); + +return 0 ; + +remove_rpmsg_subdev: +apu_remove_rpmsg_subdev (apu); +apu_ipi_unregister (apu,APU_IPI_INIT ); + +return ret; +}
snip...
Quoted 65 lines
drivers/soc/mediatek/apusys/apu-rproc.c new file +59
-0@@ -0,0 +1,806 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (c) 2021 MediaTek Inc. +*/ + +#include <linux/delay.h> +#include <linux/device.h> +#include <linux/dma-mapping.h> +#include <linux/interrupt.h> +#include <linux/iommu.h> +#include <linux/irq.h> +#include <linux/module.h> +#include <linux/remoteproc.h> +#include <linux/time64.h> +#include <linux/of_platform.h> +#include <linux/pm_domain.h> +#include <linux/pm_runtime.h> +#include <linux/sched/clock.h> +#include <linux/time64.h> +#include <linux/workqueue.h> + +#include "apu.h" +#include "apu-config.h" +#include "apu-core.h" + +/* cmd */ +enum { +DPIDLE_CMD_LOCK_IPI =0x5a00 , +DPIDLE_CMD_UNLOCK_IPI =0x5a01 , +DPIDLE_CMD_PDN_UNLOCK =0x5a02 , +}; + +/* ack */ +enum { +DPIDLE_ACK_OK =0 , +DPIDLE_ACK_LOCK_BUSY , +DPIDLE_ACK_POWER_DOWN_FAIL , +}; + +static struct work_struct *apu_pwr_work; +static struct workqueue_struct *apu_pwr_wq; +static struct dentry *dbg_root; + +static void *apu_da_to_va (struct rproc *rproc,u64 da,size_t len, +bool *is_iomem) +{ +void *ptr =NULL ; +struct mtk_apu *apu = (struct mtk_apu *)rproc->priv; + +if (da >=DRAM_OFFSET && da <DRAM_OFFSET +CODE_BUF_SIZE ) { + ptr = apu->code_buf + (da -DRAM_OFFSET ); + }else { +dev_err (apu->dev,"%s: invalid da: da = 0x%llx, len = %zu\n" , + __func__, da, len); + } +return ptr; +} + +static int apu_run (struct rproc *rproc)
drivers/soc/mediatek/apusys/apu-rproc.c line 69
Quoted 10 lines
drivers/soc/mediatek/apusys/apu-rproc.c new file +10
-0+{ +struct mtk_apu *apu = (struct mtk_apu *)rproc->priv; +struct mtk_apu_hw_ops *hw_ops = &apu->platdata->ops; +struct device *dev = apu->dev; +struct apu_run *run = &apu->run; +struct timespec64 begin, end, delta; +int ret; + +pm_runtime_get_sync (apu->dev); + hw_ops->start (apu);
Don't forget to always check return values.....
drivers/soc/mediatek/apusys/apu-rproc.c line 75
Quoted 6 lines
drivers/soc/mediatek/apusys/apu-rproc.c new file +6
-0+ +/* check if boot success */ +ktime_get_ts64 (&begin); + ret =wait_event_interruptible_timeout (run->wq, + run->signaled, +msecs_to_jiffies (10000 ));
#define APU_INIT_TIMEOUT_MS 10000
...but then, does it really need 10 *seconds* for that?! That's a lot of time...
Quoted 24 lines
drivers/soc/mediatek/apusys/apu-rproc.c new file +24
-0+ktime_get_ts64 (&end); +if (ret ==0 ) { +dev_info (dev,"APU initialization timeout!!\n" ); + ret = -ETIME ; + goto stop; + } +if (ret == -ERESTARTSYS ) { +dev_info (dev,"wait APU interrupted by a signal!!\n" ); + goto stop; + } + + apu->boot_done = true; + delta =timespec64_sub (end, begin); +dev_info (dev,"APU uP boot success. boot time: %llu s, %llu ns\n" , + (u64 )delta.tv_sec, (u64 )delta.tv_nsec); + +return 0 ; + +stop: + hw_ops->stop (apu); + +return ret; +} +
snip...
Quoted 19 lines
drivers/soc/mediatek/apusys/apu-rproc.c new file +19
-0+ +static int apu_config_setup (struct mtk_apu *apu) +{ +struct device *dev = apu->dev; +unsigned long flags; +int ret; + + apu->conf_buf =dma_alloc_coherent (apu->dev,CONFIG_SIZE , + &apu->conf_da,GFP_KERNEL ); + +if (!apu->conf_buf || apu->conf_da ==0 ) { +dev_info (dev,"%s: dma_alloc_coherent fail\n" , __func__); +return -ENOMEM ; + } +memset (apu->conf_buf,0 ,CONFIG_SIZE ); + +apu_config_user_ptr_init (apu); +spin_lock_irqsave (&apu->reg_lock, flags); +iowrite32 ((u32 )apu->conf_da, apu->apu_mbox +HOST_CONFIG_ADDR );
drivers/soc/mediatek/apusys/apu-rproc.c line 436
Quoted 10 lines
drivers/soc/mediatek/apusys/apu-rproc.c new file +10
-0+spin_unlock_irqrestore (&apu->reg_lock, flags); + + apu->conf_buf->time_offset =sched_clock (); + ret =apu_ipi_config_init (apu); +if (ret) { +dev_info (dev,"apu ipi config init failed\n" ); + goto out; + } + + ret =sw_logger_config_init (apu);
From what I understand, the sw logger is not critical for functionality... so it should probably be a "pluggable" instead.
Also, since that sw logger seems to be "simply" reading from a mailbox, it should be pretty straightforward to make it so, in which case, you wouldn't be initializing it here, but as a platform driver instead (if debugging enabled?)
Quoted 13 lines
drivers/soc/mediatek/apusys/apu-rproc.c new file +13
-0+if (ret) { +dev_err (dev,"sw logger config init failed\n" ); + goto err_sw_logger; + } + +return 0 ; + +err_sw_logger: +apu_ipi_config_remove (apu); +out: +return ret; +} +
snip...
Quoted 26 lines
drivers/soc/mediatek/apusys/apu.h new file +20
-0@@ -0,0 +1,256 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Copyright (c) 2021 MediaTek Inc. +*/ + +#ifndef APU_H +#define APU_H +#include <linux/platform_device.h> +#include <linux/spinlock.h> +#include <linux/rpmsg/mtk_rpmsg.h> + +#include "apu-config.h" + +/* setup the SMC command ops */ +#define MTK_SIP_APU_START_MCU 0x00 +#define MTK_SIP_APU_STOP_MCU 0x01 + +/* md32_sysctrl register definition */ +#define MD32_SYS_CTRL 0x0 +#define MD32_MON_PC 0x838
drivers/soc/mediatek/apusys/apu.h line 30
Quoted 10 lines
drivers/soc/mediatek/apusys/apu.h new file +10
-0+#define MD32_MON_LR 0x83c +#define MD32_MON_SP 0x840 +#define MD32_STATUS 0x844 + +/*wdt register */ +#define WDT_INT 0x0 +#define WDT_CTRL0 0x4 +#define WDT_EN BIT(31) + +/* apu_mbox spare regiter */
/* apu_mbox spare register: mbox 0..6, spare 0..3 */
#define REG_MBOX_SPARE(mbox, reg) ((0x40 + (0x100 * mbox)) + (reg * 0x4))
#define REG_MBOX0_SPARE(n) REG_MBOX_SPARE(0, n)
#define REG_MBOX6_SPARE(n) REG_MBOX_SPARE(6, n)
#define HOST_CONFIG_ADDR REG_MBOX_SPARE(0, 2)
Would that be better? Granted, mbox1-5 are also accessible and perhaps used in the future.
Quoted 9 lines
drivers/soc/mediatek/apusys/apu.h new file +9
-0+#define MBOX0_SPARE0 0x40 +#define MBOX0_SPARE1 0x44 +#define MBOX0_SPARE2 0x48 +#define MBOX0_SPARE3 0x4C +#define MBOX6_SPARE0 0x640 +#define MBOX6_SPARE1 0x644 +#define MBOX6_SPARE2 0x648 +#define MBOX6_SPARE3 0x64C +
drivers/soc/mediatek/apusys/apu.h line 49
Quoted 10 lines
drivers/soc/mediatek/apusys/apu.h new file +10
-0+#define HOST_CONFIG_ADDR MBOX0_SPARE2 + +#define LOG_W_PTR (MBOX0_SPARE0) +#define LOG_R_PTR (MBOX0_SPARE1) +#define LOG_OV_FLG (MBOX0_SPARE3) + +/* rv setup */ +#define F_PRELOAD_FIRMWARE BIT(0) +#define F_AUTO_BOOT BIT(1) +
Use SZ_* macros where possible
Quoted 75 lines
drivers/soc/mediatek/apusys/apu.h new file +75
-0+#define TCM_SIZE (128UL * 1024UL) +#define CODE_BUF_SIZE (1024UL * 1024UL) +#define DRAM_DUMP_SIZE (CODE_BUF_SIZE - TCM_SIZE) +#define REG_SIZE (4UL * 151UL) +#define TBUF_SIZE (4UL * 32UL) +#define CACHE_DUMP_SIZE (37UL * 1024UL) +#define DRAM_OFFSET (0x00000UL) +#define DRAM_DUMP_OFFSET (TCM_SIZE) +#define TCM_OFFSET (0x1d700000UL) +#define CODE_BUF_DA (DRAM_OFFSET) + +/* ipi */ +#define APU_FW_VER_LEN 32 +#define APU_SHARE_BUFFER_SIZE 256 + +#define IPI_LOCKED 1 +#define IPI_UNLOCKED 0 + +#define IPI_HOST_INITIATE 0 +#define IPI_APU_INITIATE 1 +#define IPI_WITH_ACK 1 +#define IPI_WITHOUT_ACK 0 + +enum { +APU_IPI_INIT =0 , +APU_IPI_NS_SERVICE , +APU_IPI_DEEP_IDLE , +APU_IPI_CTRL_RPMSG , +APU_IPI_MIDDLEWARE , +APU_IPI_REVISER_RPMSG , +APU_IPI_PWR_TX , +APU_IPI_PWR_RX , +APU_IPI_MDLA_TX , +APU_IPI_MDLA_RX , +APU_IPI_TIMESYNC , +APU_IPI_EDMA_TX , +APU_IPI_MNOC_TX , +APU_IPI_MAX , +}; + +struct mtk_apu ; + +struct mtk_apu_hw_ops { +int (*init)(struct mtk_apu *apu); +int (*exit)(struct mtk_apu *apu); +int (*start)(struct mtk_apu *apu); +int (*stop)(struct mtk_apu *apu); +int (*resume)(struct mtk_apu *apu); +int (*apu_memmap_init)(struct mtk_apu *apu); +void (*apu_memmap_remove)(struct mtk_apu *apu); +void (*cg_gating)(struct mtk_apu *apu); +void (*cg_ungating)(struct mtk_apu *apu); +void (*rv_cachedump)(struct mtk_apu *apu); + +/* power related ops */ +int (*power_init)(struct mtk_apu *apu); +int (*power_on)(struct mtk_apu *apu); +int (*power_off)(struct mtk_apu *apu); +}; + +struct apu_ipi { +char *name; +unsigned int direction:1 ; +unsigned int ack:1 ; +}; + +struct mtk_apu_platdata { +u32 flags; +struct mtk_apu_hw_ops ops; +const struct apu_ipi *ipi_attrs; +}; + +struct dpidle_msg { +u32 cmd; +u32 ack;
drivers/soc/mediatek/apusys/apu.h line 134
Quoted 10 lines
drivers/soc/mediatek/apusys/apu.h new file +10
-0+}; + +struct apu_run { +s8 fw_ver[APU_FW_VER_LEN ]; +u32 signaled; +wait_queue_head_t wq; +}; + +struct apu_ipi_desc { +struct mutex lock;/*ipi hanlder mutex */
typo
Quoted 136 lines
drivers/soc/mediatek/apusys/apu.h new file +122
-0+ipi_handler_t handler; +void *priv; +/* +* positive: host-initiated ipi outstanding count +* negative: apu-initiated ipi outstanding count +*/ +int usage_cnt; +}; + +struct mtk_share_obj { +u8 share_buf[APU_SHARE_BUFFER_SIZE ]; +}; + +struct sw_logger_seq_data { +u32 w_ptr; +u32 r_ptr; +u32 overflow_flg; +int i; +int is_finished; +char *data; +bool startl_first; +}; + +struct mtk_apu { +struct rproc *rproc; +struct device *dev; +void __iomem *apu_mbox; +void __iomem *md32_sysctrl; +void __iomem *apu_wdt; +int mbox0_irq_number; +int wdt_irq_number; +spinlock_t reg_lock;/* register r/w lock */ + +/* Buffer to place execution area */ +void *code_buf; +dma_addr_t code_da; + +/* Buffer to place config area */ +struct config_v1 *conf_buf; +dma_addr_t conf_da; + +/* to synchronize boot status of remote processor */ +struct apu_run run; + +/* to prevent multiple ipi_send run concurrently */ +struct mutex send_lock; +spinlock_t usage_cnt_lock;/* ipi occipued lock */ +struct apu_ipi_desc ipi_desc[APU_IPI_MAX ]; +bool ipi_id_ack[APU_IPI_MAX ];/* per-ipi ack */ +bool ipi_inbound_locked; +wait_queue_head_t ack_wq;/* for waiting for ipi ack */ + +/* ipi */ +struct rproc_subdev *rpmsg_subdev; +dma_addr_t recv_buf_da; +struct mtk_share_obj *recv_buf; +dma_addr_t send_buf_da; +struct mtk_share_obj *send_buf; + +/* time sync */ +struct work_struct timesync_work; +struct workqueue_struct *timesync_wq; +u64 timesync_stamp; + +/*deep idle */ +struct dpidle_msg recv_msg; +struct work_struct deepidle_work; +struct workqueue_struct *apu_deepidle_workq; +struct work_struct pwron_dbg_wk; + +struct mtk_apu_platdata *platdata; + +/* link power deive */ +struct device *power_dev; +bool boot_done; +struct work_struct pwr_work; + +/* logger and debug */ +struct dentry *dbg_root; +dma_addr_t handle; +char *sw_log_buf; +spinlock_t sw_logger_spinlock;/* logger status update lock */ +struct sw_logger_seq_data pseqdata_lock; +struct sw_logger_seq_data *pseqdata; +}; + +struct apu_coredump { +char tcmdump[TCM_SIZE ]; +char ramdump[DRAM_DUMP_SIZE ]; +char regdump[REG_SIZE ]; +char tbufdump[TBUF_SIZE ]; +u32 cachedump[CACHE_DUMP_SIZE /sizeof (u32)]; +} __packed; + +int apu_ipi_config_init (struct mtk_apu *apu); +void apu_ipi_config_remove (struct mtk_apu *apu); +void apu_ipi_remove (struct mtk_apu *apu); +int apu_ipi_init (struct platform_device *pdev,struct mtk_apu *apu); +int apu_ipi_register (struct mtk_apu *apu,u32 id, +ipi_handler_t handler,void *priv); +void apu_ipi_unregister (struct mtk_apu *apu,u32 id); +int apu_ipi_send (struct mtk_apu *apu,u32 id,void *data,u32 len, +u32 wait_ms); +int apu_ipi_lock (struct mtk_apu *apu); +void apu_ipi_unlock (struct mtk_apu *apu); + +void apu_deepidle_power_on_aputop (struct mtk_apu *apu); + +#if IS_ENABLED (CONFIG_DEBUG_FS ) +int sw_logger_config_init (struct mtk_apu *apu); +void sw_logger_config_remove (struct mtk_apu *apu); +int apu_sw_logger_init (struct mtk_apu *apu); +void apu_sw_logger_remove (struct mtk_apu *apu); +#else +static inline int sw_logger_config_init (struct mtk_apu *apu) {return 0 ; } +static inline void sw_logger_config_remove (struct mtk_apu *apu) { } +static inline int apu_sw_logger_init (struct mtk_apu *apu) {return 0 ; } +static inline void apu_sw_logger_remove (struct mtk_apu *apu) { } +#endif + +extern const struct mtk_apu_platdata mt8192_platdata; +#endif /* APU_H */ drivers/soc/mediatek/apusys/mt81xx-plat.c new file +8
-0@@ -0,0 +1,320 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (c) 2021 MediaTek Inc. +*/ + +#include <linux/arm-smccc.h> +#include <linux/delay.h> +#include <linux/device.h>
drivers/soc/mediatek/apusys/mt81xx-plat.c line 18
Quoted 10 lines
drivers/soc/mediatek/apusys/mt81xx-plat.c new file +10
-0+#include <linux/io.h> +#include <linux/iopoll.h> +#include <linux/of_platform.h> +#include <linux/pm_runtime.h> +#include <linux/sched/clock.h> +#include <linux/soc/mediatek/mtk_sip_svc.h> + +#include "apu.h" + +static const struct apu_ipi mt81xx_ipi_attrs[APU_IPI_MAX ] = {
In here, this is used only to pass it to the remoteproc "ipi" driver: it would make sense if this was in the ipi driver, associated to a compatible like mediatek,mt8192-ipi.
Quoted 94 lines
drivers/soc/mediatek/apusys/mt81xx-plat.c new file +94
-0+ [APU_IPI_INIT ] = { + .name ="init" , + .direction =IPI_APU_INITIATE , + .ack =IPI_WITHOUT_ACK , + }, + [APU_IPI_NS_SERVICE ] = { + .name ="name-service" , + .direction =IPI_APU_INITIATE , + .ack =IPI_WITHOUT_ACK , + }, + [APU_IPI_DEEP_IDLE ] = { + .name ="deep_idle" , + .direction =IPI_APU_INITIATE , + .ack =IPI_WITH_ACK , + }, + [APU_IPI_CTRL_RPMSG ] = { + .name ="apu-ctrl-rpmsg" , + .direction =IPI_APU_INITIATE , + .ack =IPI_WITH_ACK , + }, + [APU_IPI_MIDDLEWARE ] = { + .name ="apu-mdw-rpmsg" , + .direction =IPI_HOST_INITIATE , + .ack =IPI_WITH_ACK , + }, + [APU_IPI_REVISER_RPMSG ] = { + .name ="apu-reviser-rpmsg" , + .direction =IPI_HOST_INITIATE , + .ack =IPI_WITH_ACK , + }, + [APU_IPI_PWR_TX ] = { + .name ="apupwr-tx-rpmsg" , + .direction =IPI_HOST_INITIATE , + .ack =IPI_WITH_ACK , + }, + [APU_IPI_PWR_RX ] = { + .name ="apupwr-rx-rpmsg" , + .direction =IPI_APU_INITIATE , + .ack =IPI_WITH_ACK , + }, + [APU_IPI_MDLA_TX ] = { + .name ="mdla-tx-rpmsg" , + .direction =IPI_HOST_INITIATE , + .ack =IPI_WITH_ACK , + }, + [APU_IPI_MDLA_RX ] = { + .name ="mdla-rx-rpmsg" , + .direction =IPI_APU_INITIATE , + .ack =IPI_WITH_ACK , + }, + [APU_IPI_TIMESYNC ] = { + .name ="apu-timesync" , + .direction =IPI_APU_INITIATE , + .ack =IPI_WITH_ACK , + }, + [APU_IPI_EDMA_TX ] = { + .name ="apu-edma-rpmsg" , + .direction =IPI_HOST_INITIATE , + .ack =IPI_WITHOUT_ACK , + }, + [APU_IPI_MNOC_TX ] = { + .name ="apu-mnoc-rpmsg" , + .direction =IPI_HOST_INITIATE , + .ack =IPI_WITHOUT_ACK , + }, +}; + +static void apu_reset_mcu (struct mtk_apu *apu) +{ +u32 reg; + +/* assert mcu reset */ + reg =ioread32 (apu->md32_sysctrl); +iowrite32 (reg & ~0x1 , apu->md32_sysctrl); +mdelay (10 ); +iowrite32 (reg |0x1 , apu->md32_sysctrl); +} + +static int apu_start_mcu (struct mtk_apu *apu) +{ +struct arm_smccc_res ares; + +/* initialize IOMMU and ACP config (iommu_tr_en=1, acp_en=0) */ +iowrite32 (0xEA9 , apu->md32_sysctrl); + +arm_smccc_smc (MTK_SIP_APUSYS_CONTROL ,MTK_SIP_APU_START_MCU , +0 ,0 ,0 ,0 ,0 ,0 , &ares); +if (ares.a0) +dev_err (apu->dev,"start mcu fail: %lu\n" , ares.a0); + +return 0 ; +} + +static int apu_stop_mcu (struct mtk_apu *apu)
drivers/soc/mediatek/apusys/mt81xx-plat.c line 122
Quoted 10 lines
drivers/soc/mediatek/apusys/mt81xx-plat.c new file +10
-0+{ +struct arm_smccc_res ares; + +arm_smccc_smc (MTK_SIP_APUSYS_CONTROL ,MTK_SIP_APU_STOP_MCU , +0 ,0 ,0 ,0 ,0 ,0 , &ares); +if (ares.a0) +dev_err (apu->dev,"stop mcufail: %lu\n" , ares.a0); + +return 0 ; +}
Is it expected for other SoCs to have different (or more) secure world calls? If it is, then it may be worth it to move this to a different driver in drivers/firmware, so that you will be able to map different/more values to different compatibles.
Otherwise, keep it here.
drivers/soc/mediatek/apusys/mt81xx-plat.c line 123
Quoted 1 line
drivers/soc/mediatek/apusys/mt81xx-plat.c new file +1
-0+
Thanks,
- Angelo
Re: [RFC 08/13] soc: mediatek: apu: Add apusys rv driver
Quoted 42 lines · AngeloGioacchino Del Regno
Il 23/10/21 13:14, Flora Fu ha scritto:
Quoted 8 lines
Add driver for control APU tinysys
APU integrated subsystem having MD32RV33 (MD32) that runs tinysys The tinsys is running on a micro processor in APU.
Its firmware is load and boot from Kernel side. Kernel and tinysys use
IPI to tx/rx messages.Quoted 7 lines
Signed-off-by Flora Fu <[email protected]>--- drivers/soc/mediatek/apusys/Makefile | 6 + drivers/soc/mediatek/apusys/apu-config.h | 100 +++ drivers/soc/mediatek/apusys/apu-core.c | 2 + drivers/soc/mediatek/apusys/apu-core.h | 2 + drivers/soc/mediatek/apusys/apu-ipi.c | 486 ++++++++++++I'm not sure of that, but your
apu-ipi.cmay be more suited to be indrivers/remoteprocinstead.Quoted 1 line
drivers/soc/mediatek/apusys/apu-mbox.c | 83 ++
apu-mbox.cshould go todrivers/mailbox/and you should register it with
the mailbox API as a mailbox controller instead of what you're currently
doing...From what I see, you have functions in there that can be indeed
mapped
to structmbox_chan_ops.send_data and .peek_data... also your functionapu_mbox_wait_inboxseems to be waiting on an interrupt, and such irq is
apparently your "mbox0_irq" (as you named it in the dt). In that case, you can also manage that in yourdrivers/mailbox/driver.
+Quoted 3 lines
drivers/soc/mediatek/apusys/apu-mbox.h | 27 + drivers/soc/mediatek/apusys/apu-rproc.c | 806++++++++++++++++++++
Quoted 7 lines
The
apu-rproc.cdriver seems to be a good candidate to be moved away from
drivers/soc/mediatek/apusys/- as this is indeed a remoteproc driver.Having it as
drivers/remoteproc/mtk_apu.cseems to be a good option.
For mbox/ipi/apu-rproc, we will check the kernel framework and make more fix on it.
Quoted 18 lines
Quoted 2 lines
drivers/soc/mediatek/apusys/apu-sw-logger.c | 429 +++++++++++This one definitely belongs here in
drivers/soc/mediatek, and it's a consumer
of the mailbox driver.Quoted 2 lines
drivers/soc/mediatek/apusys/apu.h | 256 +++++++ drivers/soc/mediatek/apusys/mt81xx-plat.c | 320 ++++++++If we end up keeping to be in need to have a separate
mt81xx-plat.cfile,
then I believe this should have another name, so that it becomes one that
aggregates all of the very-platform-specific functions in one, instead of
having one file for each platform.
Quoted 5 lines
Though, it may also be possible that this file will disappear entirely:
since most of the things here will be moved around, it may become mostly
empty... but it's probably too soon to judge.
The mt81xx-platform.c is prepared for the similiar apu desing platforms but some of them will have differnt operations in the functions. I will just keep it and we can reivew it again in the feature versions.
Quoted 81 lines
Quoted 11 lines
11 files changed, 2517 insertions(+)create mode 100644
drivers/soc/mediatek/apusys/apu-config.hcreate mode 100644drivers/soc/mediatek/apusys/apu-ipi.ccreate mode 100644drivers/soc/mediatek/apusys/apu-mbox.ccreate mode 100644drivers/soc/mediatek/apusys/apu-mbox.hcreate mode 100644drivers/soc/mediatek/apusys/apu-rproc.ccreate mode 100644drivers/soc/mediatek/apusys/apu-sw-logger.ccreate mode 100644drivers/soc/mediatek/apusys/apu.hcreate mode 100644drivers/soc/mediatek/apusys/mt81xx-plat.csnip...
Quoted 6 lines
drivers/soc/mediatek/apusys/apu-ipi.c new file +0
-0snip...
Quoted 45 lines
+int
apu_ipi_init(struct platform_device *pdev, struct mtk_apu *apu)drivers/soc/mediatek/apusys/apu-ipi.c new file +14
-0+{ +struct device *dev = apu->dev; +int i, ret; + + tx_serial_no =0 ; + rx_serial_no =0 ; + +mutex_init (&apu->send_lock); +spin_lock_init (&apu->usage_cnt_lock); +for (i =0 ; i <APU_IPI_MAX ; i++) { +mutex_init (&apu->ipi_desc[i].lock); + lockdep_set_class_and_name(&apu->ipi_desc[i].lock, + &ipi_lock_key[i], + apu->platdata-Quoted 1 line
ipi_attrs[i].name);
drivers/soc/mediatek/apusys/apu-ipi.c new file +7
-0+ } + +init_waitqueue_head (&apu->run.wq); +init_waitqueue_head (&apu->ack_wq); + +/* APU initialization IPI register */ + ret = apu_ipi_register(apu, APU_IPI_INIT, apu_init_ipi_handler,apu);
drivers/soc/mediatek/apusys/apu-ipi.c new file +2
-0+if (ret) { + dev_err(dev, "failed to register ipi for init,ret=%d\n",
drivers/soc/mediatek/apusys/apu-ipi.c new file +9
-0+ ret); +return ret; + } + +/* add rpmsg subdev */ +apu_add_rpmsg_subdev (apu); + +/* register mailbox IRQ */ + apu->mbox0_irq_number = platform_get_irq_byname(pdev,"
mbox0_irq");drivers/soc/mediatek/apusys/apu-ipi.c new file +4
-0+dev_info (&pdev->dev,"%s: mbox0_irq = %d\n" , __func__, + apu->mbox0_irq_number); + + ret = devm_request_threaded_irq(&pdev->dev, apu-Quoted 1 line
mbox0_irq_number,drivers/soc/mediatek/apusys/apu-ipi.c new file +1
-0+ NULL, apu_ipi_handler,
IRQF_ONESHOT,drivers/soc/mediatek/apusys/apu-ipi.c line 473
Quoted 1 line
drivers/soc/mediatek/apusys/apu-ipi.c new file +1
-0+ "apu_ipi", apu);This is the mailbox interrupt... but it's handled in this driver instead of
being handler in the mailbox driver... it's a bit confusing.Is this interrupt supposed to fire as a mailbox doorbell or..? In that case, you should request it in the mailbox driver and register an
interrupt controller (still, in the mailbox driver) so that you can export
a sw interrupt to this one.
Quoted 2 lines
Or, maybe you can use notifiers to catch the mailbox message in this driver?
Ack.
Quoted 87 lines
Quoted 13 lines
drivers/soc/mediatek/apusys/apu-ipi.c new file +13
-0+if (ret <0 ) + goto remove_rpmsg_subdev; + +apu_mbox_hw_init (apu); + +return 0 ; + +remove_rpmsg_subdev: +apu_remove_rpmsg_subdev (apu); +apu_ipi_unregister (apu,APU_IPI_INIT ); + +return ret; +}snip...
Quoted 71 lines
drivers/soc/mediatek/apusys/apu-rproc.c new file +53
-0@@ -0,0 +1,806 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (c) 2021 MediaTek Inc. +*/ + +#include <linux/delay.h> +#include <linux/device.h> +#include <linux/dma-mapping.h> +#include <linux/interrupt.h> +#include <linux/iommu.h> +#include <linux/irq.h> +#include <linux/module.h> +#include <linux/remoteproc.h> +#include <linux/time64.h> +#include <linux/of_platform.h> +#include <linux/pm_domain.h> +#include <linux/pm_runtime.h> +#include <linux/sched/clock.h> +#include <linux/time64.h> +#include <linux/workqueue.h> + +#include "apu.h" +#include "apu-config.h" +#include "apu-core.h" + +/* cmd */ +enum { +DPIDLE_CMD_LOCK_IPI =0x5a00 , +DPIDLE_CMD_UNLOCK_IPI =0x5a01 , +DPIDLE_CMD_PDN_UNLOCK =0x5a02 , +}; + +/* ack */ +enum { +DPIDLE_ACK_OK =0 , +DPIDLE_ACK_LOCK_BUSY , +DPIDLE_ACK_POWER_DOWN_FAIL , +}; + +static struct work_struct *apu_pwr_work; +static struct workqueue_struct *apu_pwr_wq; +static struct dentry *dbg_root; + +static void *apu_da_to_va (struct rproc *rproc,u64 da,size_t len, +bool *is_iomem) +{ +void *ptr =NULL ; +struct mtk_apu *apu = (struct mtk_apu *)rproc->priv; + +if (da >=DRAM_OFFSET && da <DRAM_OFFSET +CODE_BUF_SIZE ) { + ptr = apu->code_buf + (da -DRAM_OFFSET ); + }else { + dev_err(apu->dev, "%s: invalid da: da = 0x%llx, len =%zu\n",
drivers/soc/mediatek/apusys/apu-rproc.c new file +10
-0+ __func__, da, len); + } +return ptr; +} + +static int apu_run (struct rproc *rproc) +{ +struct mtk_apu *apu = (struct mtk_apu *)rproc->priv; +struct mtk_apu_hw_ops *hw_ops = &apu->platdata->ops; +struct device *dev = apu->dev;
Quoted 8 lines
drivers/soc/mediatek/apusys/apu-rproc.c line 69
Quoted 6 lines
drivers/soc/mediatek/apusys/apu-rproc.c new file +6
-0+struct apu_run *run = &apu->run; +struct timespec64 begin, end, delta; +int ret; + +pm_runtime_get_sync (apu->dev); + hw_ops->start (apu);Don't forget to always check return values.....
Ack.
Quoted 76 lines
Quoted 8 lines
drivers/soc/mediatek/apusys/apu-rproc.c new file +6
-0+ +/* check if boot success */ +ktime_get_ts64 (&begin); + ret =wait_event_interruptible_timeout (run->wq, + run->signaled, +msecs_to_jiffies (10000 ));
#define
APU_INIT_TIMEOUT_MS10000...but then, does it really need 10 *seconds* for that?! That's a lot of time...
Quoted 25 lines
drivers/soc/mediatek/apusys/apu-rproc.c new file +14
-0+ktime_get_ts64 (&end); +if (ret ==0 ) { +dev_info (dev,"APU initialization timeout!!\n" ); + ret = -ETIME ; + goto stop; + } +if (ret == -ERESTARTSYS ) { +dev_info (dev,"wait APU interrupted by a signal!!\n" ); + goto stop; + } + + apu->boot_done = true; + delta =timespec64_sub (end, begin); + dev_info(dev, "APU uP boot success. boot time: %llu s, %lluns\n",
drivers/soc/mediatek/apusys/apu-rproc.c new file +10
-0+ (u64)delta.tv_sec, (u64)delta.tv_nsec); + +return 0 ; + +stop: + hw_ops->stop (apu); + +return ret; +} +snip...
Quoted 20 lines
drivers/soc/mediatek/apusys/apu-rproc.c new file +12
-0+ +static int apu_config_setup (struct mtk_apu *apu) +{ +struct device *dev = apu->dev; +unsigned long flags; +int ret; + + apu->conf_buf =dma_alloc_coherent (apu->dev,CONFIG_SIZE , + &apu->conf_da,GFP_KERNEL ); + +if (!apu->conf_buf || apu->conf_da ==0 ) { + dev_info(dev, "%s: dma_alloc_coherent fail\n",
__func__);drivers/soc/mediatek/apusys/apu-rproc.c new file +7
-0+return -ENOMEM ; + } +memset (apu->conf_buf,0 ,CONFIG_SIZE ); + +apu_config_user_ptr_init (apu); +spin_lock_irqsave (&apu->reg_lock, flags); +iowrite32 ((u32 )apu->conf_da, apu->apu_mbox +HOST_CONFIG_ADDR );drivers/soc/mediatek/apusys/apu-rproc.c line 436
Quoted 10 lines
drivers/soc/mediatek/apusys/apu-rproc.c new file +10
-0+spin_unlock_irqrestore (&apu->reg_lock, flags); + + apu->conf_buf->time_offset =sched_clock (); + ret =apu_ipi_config_init (apu); +if (ret) { +dev_info (dev,"apu ipi config init failed\n" ); + goto out; + } + + ret =sw_logger_config_init (apu);From what I understand, the sw logger is not critical for
Quoted 8 lines
functionality... so
it should probably be a "pluggable" instead.
Also, since that sw logger seems to be "simply" reading from a mailbox, it
should be pretty straightforward to make it so, in which case, you wouldn't
be initializing it here, but as a platform driver instead (if debugging enabled?)
It is for debug usage and I think it can be a pluggable module. But it still needs configurations in the boot stage to make micorprocessor enable the logger. I will update this part.
Quoted 61 lines
Quoted 14 lines
drivers/soc/mediatek/apusys/apu-rproc.c new file +13
-0+if (ret) { +dev_err (dev,"sw logger config init failed\n" ); + goto err_sw_logger; + } + +return 0 ; + +err_sw_logger: +apu_ipi_config_remove (apu); +out: +return ret; +} +snip...
Quoted 27 lines
drivers/soc/mediatek/apusys/apu.h new file +20
-0@@ -0,0 +1,256 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Copyright (c) 2021 MediaTek Inc. +*/ + +#ifndef APU_H +#define APU_H +#include <linux/platform_device.h> +#include <linux/spinlock.h> +#include <linux/rpmsg/mtk_rpmsg.h> + +#include "apu-config.h" + +/* setup the SMC command ops */ +#define MTK_SIP_APU_START_MCU 0x00 +#define MTK_SIP_APU_STOP_MCU 0x01 + +/* md32_sysctrl register definition */ +#define MD32_SYS_CTRL 0x0 +#define MD32_MON_PC 0x838drivers/soc/mediatek/apusys/apu.h line 30
Quoted 10 lines
drivers/soc/mediatek/apusys/apu.h new file +10
-0+#define MD32_MON_LR 0x83c +#define MD32_MON_SP 0x840 +#define MD32_STATUS 0x844 + +/*wdt register */ +#define WDT_INT 0x0 +#define WDT_CTRL0 0x4 +#define WDT_EN BIT(31) + +/* apu_mbox spare regiter */ /*
apu_mboxspare register: mbox 0..6, spare 0..3 */
#defineREG_MBOX_SPARE(mbox, reg)((0x40+ (0x100* mbox)) + (reg
*0x4))
#defineREG_MBOX0_SPARE(n)REG_MBOX_SPARE(0, n)
#defineREG_MBOX6_SPARE(n)REG_MBOX_SPARE(6, n)
Quoted 5 lines
#define
HOST_CONFIG_ADDRREG_MBOX_SPARE(0, 2)Would that be better? Granted, mbox1-5 are also accessible and perhaps used
in the future.
Ack.
Quoted 13 lines
Quoted 13 lines
drivers/soc/mediatek/apusys/apu.h new file +13
-0+#define MBOX0_SPARE0 0x40 +#define MBOX0_SPARE1 0x44 +#define MBOX0_SPARE2 0x48 +#define MBOX0_SPARE3 0x4C +#define MBOX6_SPARE0 0x640 +#define MBOX6_SPARE1 0x644 +#define MBOX6_SPARE2 0x648 +#define MBOX6_SPARE3 0x64C + +#define HOST_CONFIG_ADDR MBOX0_SPARE2 + +#define LOG_W_PTR (MBOX0_SPARE0) +#define LOG_R_PTR (MBOX0_SPARE1)
Quoted 8 lines
drivers/soc/mediatek/apusys/apu.h line 49
Quoted 6 lines
drivers/soc/mediatek/apusys/apu.h new file +6
-0+#define LOG_OV_FLG (MBOX0_SPARE3) + +/* rv setup */ +#define F_PRELOAD_FIRMWARE BIT(0) +#define F_AUTO_BOOT BIT(1) +Use SZ_* macros where possible
Ack.
Quoted 80 lines
Quoted 80 lines
drivers/soc/mediatek/apusys/apu.h new file +79
-0+#define TCM_SIZE (128UL * 1024UL) +#define CODE_BUF_SIZE (1024UL * 1024UL) +#define DRAM_DUMP_SIZE (CODE_BUF_SIZE - TCM_SIZE) +#define REG_SIZE (4UL * 151UL) +#define TBUF_SIZE (4UL * 32UL) +#define CACHE_DUMP_SIZE (37UL * 1024UL) +#define DRAM_OFFSET (0x00000UL) +#define DRAM_DUMP_OFFSET (TCM_SIZE) +#define TCM_OFFSET (0x1d700000UL) +#define CODE_BUF_DA (DRAM_OFFSET) + +/* ipi */ +#define APU_FW_VER_LEN 32 +#define APU_SHARE_BUFFER_SIZE 256 + +#define IPI_LOCKED 1 +#define IPI_UNLOCKED 0 + +#define IPI_HOST_INITIATE 0 +#define IPI_APU_INITIATE 1 +#define IPI_WITH_ACK 1 +#define IPI_WITHOUT_ACK 0 + +enum { +APU_IPI_INIT =0 , +APU_IPI_NS_SERVICE , +APU_IPI_DEEP_IDLE , +APU_IPI_CTRL_RPMSG , +APU_IPI_MIDDLEWARE , +APU_IPI_REVISER_RPMSG , +APU_IPI_PWR_TX , +APU_IPI_PWR_RX , +APU_IPI_MDLA_TX , +APU_IPI_MDLA_RX , +APU_IPI_TIMESYNC , +APU_IPI_EDMA_TX , +APU_IPI_MNOC_TX , +APU_IPI_MAX , +}; + +struct mtk_apu ; + +struct mtk_apu_hw_ops { +int (*init)(struct mtk_apu *apu); +int (*exit)(struct mtk_apu *apu); +int (*start)(struct mtk_apu *apu); +int (*stop)(struct mtk_apu *apu); +int (*resume)(struct mtk_apu *apu); +int (*apu_memmap_init)(struct mtk_apu *apu); +void (*apu_memmap_remove)(struct mtk_apu *apu); +void (*cg_gating)(struct mtk_apu *apu); +void (*cg_ungating)(struct mtk_apu *apu); +void (*rv_cachedump)(struct mtk_apu *apu); + +/* power related ops */ +int (*power_init)(struct mtk_apu *apu); +int (*power_on)(struct mtk_apu *apu); +int (*power_off)(struct mtk_apu *apu); +}; + +struct apu_ipi { +char *name; +unsigned int direction:1 ; +unsigned int ack:1 ; +}; + +struct mtk_apu_platdata { +u32 flags; +struct mtk_apu_hw_ops ops; +const struct apu_ipi *ipi_attrs; +}; + +struct dpidle_msg { +u32 cmd; +u32 ack; +}; + +struct apu_run { +s8 fw_ver[APU_FW_VER_LEN ];
Quoted 9 lines
drivers/soc/mediatek/apusys/apu.h line 134
Quoted 6 lines
drivers/soc/mediatek/apusys/apu.h new file +6
-0+u32 signaled; +wait_queue_head_t wq; +}; + +struct apu_ipi_desc { +struct mutex lock;/*ipi hanlder mutex */ typo
Ack.
Quoted 148 lines
Quoted 148 lines
drivers/soc/mediatek/apusys/apu.h new file +98
-0+ipi_handler_t handler; +void *priv; +/* +* positive: host-initiated ipi outstanding count +* negative: apu-initiated ipi outstanding count +*/ +int usage_cnt; +}; + +struct mtk_share_obj { +u8 share_buf[APU_SHARE_BUFFER_SIZE ]; +}; + +struct sw_logger_seq_data { +u32 w_ptr; +u32 r_ptr; +u32 overflow_flg; +int i; +int is_finished; +char *data; +bool startl_first; +}; + +struct mtk_apu { +struct rproc *rproc; +struct device *dev; +void __iomem *apu_mbox; +void __iomem *md32_sysctrl; +void __iomem *apu_wdt; +int mbox0_irq_number; +int wdt_irq_number; +spinlock_t reg_lock;/* register r/w lock */ + +/* Buffer to place execution area */ +void *code_buf; +dma_addr_t code_da; + +/* Buffer to place config area */ +struct config_v1 *conf_buf; +dma_addr_t conf_da; + +/* to synchronize boot status of remote processor */ +struct apu_run run; + +/* to prevent multiple ipi_send run concurrently */ +struct mutex send_lock; +spinlock_t usage_cnt_lock;/* ipi occipued lock */ +struct apu_ipi_desc ipi_desc[APU_IPI_MAX ]; +bool ipi_id_ack[APU_IPI_MAX ];/* per-ipi ack */ +bool ipi_inbound_locked; +wait_queue_head_t ack_wq;/* for waiting for ipi ack */ + +/* ipi */ +struct rproc_subdev *rpmsg_subdev; +dma_addr_t recv_buf_da; +struct mtk_share_obj *recv_buf; +dma_addr_t send_buf_da; +struct mtk_share_obj *send_buf; + +/* time sync */ +struct work_struct timesync_work; +struct workqueue_struct *timesync_wq; +u64 timesync_stamp; + +/*deep idle */ +struct dpidle_msg recv_msg; +struct work_struct deepidle_work; +struct workqueue_struct *apu_deepidle_workq; +struct work_struct pwron_dbg_wk; + +struct mtk_apu_platdata *platdata; + +/* link power deive */ +struct device *power_dev; +bool boot_done; +struct work_struct pwr_work; + +/* logger and debug */ +struct dentry *dbg_root; +dma_addr_t handle; +char *sw_log_buf; +spinlock_t sw_logger_spinlock;/* logger status update lock */ +struct sw_logger_seq_data pseqdata_lock; +struct sw_logger_seq_data *pseqdata; +}; + +struct apu_coredump { +char tcmdump[TCM_SIZE ]; +char ramdump[DRAM_DUMP_SIZE ]; +char regdump[REG_SIZE ]; +char tbufdump[TBUF_SIZE ]; +u32 cachedump[CACHE_DUMP_SIZE /sizeof (u32)]; +} __packed; + +int apu_ipi_config_init (struct mtk_apu *apu); +void apu_ipi_config_remove (struct mtk_apu *apu); +void apu_ipi_remove (struct mtk_apu *apu); +int apu_ipi_init(struct platform_device *pdev, struct mtk_apu*apu);
drivers/soc/mediatek/apusys/apu.h new file +17
-0+int apu_ipi_register (struct mtk_apu *apu,u32 id, +ipi_handler_t handler,void *priv); +void apu_ipi_unregister (struct mtk_apu *apu,u32 id); +int apu_ipi_send (struct mtk_apu *apu,u32 id,void *data,u32 len, +u32 wait_ms); +int apu_ipi_lock (struct mtk_apu *apu); +void apu_ipi_unlock (struct mtk_apu *apu); + +void apu_deepidle_power_on_aputop (struct mtk_apu *apu); + +#if IS_ENABLED (CONFIG_DEBUG_FS ) +int sw_logger_config_init (struct mtk_apu *apu); +void sw_logger_config_remove (struct mtk_apu *apu); +int apu_sw_logger_init (struct mtk_apu *apu); +void apu_sw_logger_remove (struct mtk_apu *apu); +#else +static inline int sw_logger_config_init (struct mtk_apu *apu) {return 0; }
+static inline voidsw_logger_config_remove(struct mtk_apu *apu){ }
+static inline intapu_sw_logger_init(struct mtk_apu *apu){ return 0; }drivers/soc/mediatek/apusys/apu.h new file +5
-0+static inline void apu_sw_logger_remove (struct mtk_apu *apu) { } +#endif + +extern const struct mtk_apu_platdata mt8192_platdata; +#endif /* APU_H */ drivers/soc/mediatek/apusys/mt81xx-plat.c new file +15
-0@@ -0,0 +1,320 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (c) 2021 MediaTek Inc. +*/ + +#include <linux/arm-smccc.h> +#include <linux/delay.h> +#include <linux/device.h> +#include <linux/io.h> +#include <linux/iopoll.h> +#include <linux/of_platform.h> +#include <linux/pm_runtime.h> +#include <linux/sched/clock.h> +#include <linux/soc/mediatek/mtk_sip_svc.h> +
Quoted 9 lines
drivers/soc/mediatek/apusys/mt81xx-plat.c line 18
Quoted 3 lines
drivers/soc/mediatek/apusys/mt81xx-plat.c new file +3
-0+#include "apu.h" + +static const struct apu_ipi mt81xx_ipi_attrs[APU_IPI_MAX ] = {In here, this is used only to pass it to the remoteproc "ipi" driver:
it would make
sense if this was in the ipi driver, associated to a compatible like mediatek,mt8192-ipi.
Hi, Algelo,
I am not quite sure about the comments. Could you explain more details?
The list is used in kernel as ipi channe attributes by platforms(different platfrom will has differnt settings) to create ipi channesl by mtk-rpmsg. The ipi-attrs is add into platform data.
const struct mtk_apu_platdata mt8192_platdata = {
.flags = F_AUTO_BOOT,
.ipi_attrs = mt81xx_ipi_attrs,
.ops = {
.init = NULL,
snip.
.power_init = mt81xx_apu_power_init,
.power_on = mt81xx_apu_power_on,
.power_off = mt81xx_apu_power_off,
},
};Quoted 113 lines
Quoted 94 lines
drivers/soc/mediatek/apusys/mt81xx-plat.c new file +94
-0+ [APU_IPI_INIT ] = { + .name ="init" , + .direction =IPI_APU_INITIATE , + .ack =IPI_WITHOUT_ACK , + }, + [APU_IPI_NS_SERVICE ] = { + .name ="name-service" , + .direction =IPI_APU_INITIATE , + .ack =IPI_WITHOUT_ACK , + }, + [APU_IPI_DEEP_IDLE ] = { + .name ="deep_idle" , + .direction =IPI_APU_INITIATE , + .ack =IPI_WITH_ACK , + }, + [APU_IPI_CTRL_RPMSG ] = { + .name ="apu-ctrl-rpmsg" , + .direction =IPI_APU_INITIATE , + .ack =IPI_WITH_ACK , + }, + [APU_IPI_MIDDLEWARE ] = { + .name ="apu-mdw-rpmsg" , + .direction =IPI_HOST_INITIATE , + .ack =IPI_WITH_ACK , + }, + [APU_IPI_REVISER_RPMSG ] = { + .name ="apu-reviser-rpmsg" , + .direction =IPI_HOST_INITIATE , + .ack =IPI_WITH_ACK , + }, + [APU_IPI_PWR_TX ] = { + .name ="apupwr-tx-rpmsg" , + .direction =IPI_HOST_INITIATE , + .ack =IPI_WITH_ACK , + }, + [APU_IPI_PWR_RX ] = { + .name ="apupwr-rx-rpmsg" , + .direction =IPI_APU_INITIATE , + .ack =IPI_WITH_ACK , + }, + [APU_IPI_MDLA_TX ] = { + .name ="mdla-tx-rpmsg" , + .direction =IPI_HOST_INITIATE , + .ack =IPI_WITH_ACK , + }, + [APU_IPI_MDLA_RX ] = { + .name ="mdla-rx-rpmsg" , + .direction =IPI_APU_INITIATE , + .ack =IPI_WITH_ACK , + }, + [APU_IPI_TIMESYNC ] = { + .name ="apu-timesync" , + .direction =IPI_APU_INITIATE , + .ack =IPI_WITH_ACK , + }, + [APU_IPI_EDMA_TX ] = { + .name ="apu-edma-rpmsg" , + .direction =IPI_HOST_INITIATE , + .ack =IPI_WITHOUT_ACK , + }, + [APU_IPI_MNOC_TX ] = { + .name ="apu-mnoc-rpmsg" , + .direction =IPI_HOST_INITIATE , + .ack =IPI_WITHOUT_ACK , + }, +}; + +static void apu_reset_mcu (struct mtk_apu *apu) +{ +u32 reg; + +/* assert mcu reset */ + reg =ioread32 (apu->md32_sysctrl); +iowrite32 (reg & ~0x1 , apu->md32_sysctrl); +mdelay (10 ); +iowrite32 (reg |0x1 , apu->md32_sysctrl); +} + +static int apu_start_mcu (struct mtk_apu *apu) +{ +struct arm_smccc_res ares; + +/* initialize IOMMU and ACP config (iommu_tr_en=1, acp_en=0) */ +iowrite32 (0xEA9 , apu->md32_sysctrl); + +arm_smccc_smc (MTK_SIP_APUSYS_CONTROL ,MTK_SIP_APU_START_MCU , +0 ,0 ,0 ,0 ,0 ,0 , &ares); +if (ares.a0) +dev_err (apu->dev,"start mcu fail: %lu\n" , ares.a0); + +return 0 ; +} + +static int apu_stop_mcu (struct mtk_apu *apu)drivers/soc/mediatek/apusys/mt81xx-plat.c line 122
Quoted 10 lines
drivers/soc/mediatek/apusys/mt81xx-plat.c new file +10
-0+{ +struct arm_smccc_res ares; + +arm_smccc_smc (MTK_SIP_APUSYS_CONTROL ,MTK_SIP_APU_STOP_MCU , +0 ,0 ,0 ,0 ,0 ,0 , &ares); +if (ares.a0) +dev_err (apu->dev,"stop mcufail: %lu\n" , ares.a0); + +return 0 ; +}Is it expected for other SoCs to have different (or more) secure world calls?
If it is, then it may be worth it to move this to a different driver indrivers/firmware, so that you will be able to map different/more values to
different compatibles.
Quoted 1 line
Otherwise, keep it here.
This is for apu usage and only for apu. I will keep it here. The SMC receivers are also found in ATF upstream.
https://review.trustedfirmware.org/c/TF-A/trusted-firmware-a/+/9709/11.
Thanks for your comments.
Quoted 1 line
- Angelo
AngeloGioacchino Del Regno
maintainerRe: [RFC 08/13] soc: mediatek: apu: Add apusys rv driver
Il 26/11/21 10:25, Flora.Fu ha scritto:
Quoted 535 lines · AngeloGioacchino Del Regno
Quoted 42 lines
Il 23/10/21 13:14, Flora Fu ha scritto:
Quoted 8 lines
Add driver for control APU tinysys
APU integrated subsystem having MD32RV33 (MD32) that runs tinysys The tinsys is running on a micro processor in APU.
Its firmware is load and boot from Kernel side. Kernel and tinysys use
IPI to tx/rx messages.Quoted 7 lines
Signed-off-by Flora Fu <[email protected]>--- drivers/soc/mediatek/apusys/Makefile | 6 + drivers/soc/mediatek/apusys/apu-config.h | 100 +++ drivers/soc/mediatek/apusys/apu-core.c | 2 + drivers/soc/mediatek/apusys/apu-core.h | 2 + drivers/soc/mediatek/apusys/apu-ipi.c | 486 ++++++++++++I'm not sure of that, but your
apu-ipi.cmay be more suited to be indrivers/remoteprocinstead.Quoted 1 line
drivers/soc/mediatek/apusys/apu-mbox.c | 83 ++
apu-mbox.cshould go todrivers/mailbox/and you should register it with
the mailbox API as a mailbox controller instead of what you're currently
doing...From what I see, you have functions in there that can be indeed
mapped
to structmbox_chan_ops.send_data and .peek_data... also your functionapu_mbox_wait_inboxseems to be waiting on an interrupt, and such irq is
apparently your "mbox0_irq" (as you named it in the dt). In that case, you can also manage that in yourdrivers/mailbox/driver.
+Quoted 3 lines
drivers/soc/mediatek/apusys/apu-mbox.h | 27 + drivers/soc/mediatek/apusys/apu-rproc.c | 806++++++++++++++++++++
Quoted 7 lines
The
apu-rproc.cdriver seems to be a good candidate to be moved away from
drivers/soc/mediatek/apusys/- as this is indeed a remoteproc driver.Having it as
drivers/remoteproc/mtk_apu.cseems to be a good option.For mbox/ipi/apu-rproc, we will check the kernel framework and make more fix on it.
Quoted 18 lines
Quoted 2 lines
drivers/soc/mediatek/apusys/apu-sw-logger.c | 429 +++++++++++This one definitely belongs here in
drivers/soc/mediatek, and it's a consumer
of the mailbox driver.Quoted 2 lines
drivers/soc/mediatek/apusys/apu.h | 256 +++++++ drivers/soc/mediatek/apusys/mt81xx-plat.c | 320 ++++++++If we end up keeping to be in need to have a separate
mt81xx-plat.cfile,
then I believe this should have another name, so that it becomes one that
aggregates all of the very-platform-specific functions in one, instead of
having one file for each platform.Quoted 5 lines
Though, it may also be possible that this file will disappear entirely:
since most of the things here will be moved around, it may become mostly
empty... but it's probably too soon to judge.The
mt81xx-platform.cis prepared for the similiar apu desing platforms but some of them will have differnt operations in the functions. I will just keep it and we can reivew it again in the feature versions.Quoted 81 lines
Quoted 11 lines
11 files changed, 2517 insertions(+)create mode 100644
drivers/soc/mediatek/apusys/apu-config.hcreate mode 100644drivers/soc/mediatek/apusys/apu-ipi.ccreate mode 100644drivers/soc/mediatek/apusys/apu-mbox.ccreate mode 100644drivers/soc/mediatek/apusys/apu-mbox.hcreate mode 100644drivers/soc/mediatek/apusys/apu-rproc.ccreate mode 100644drivers/soc/mediatek/apusys/apu-sw-logger.ccreate mode 100644drivers/soc/mediatek/apusys/apu.hcreate mode 100644drivers/soc/mediatek/apusys/mt81xx-plat.csnip...
Quoted 6 lines
drivers/soc/mediatek/apusys/apu-ipi.c new file +0
-0snip...
Quoted 45 lines
+int
apu_ipi_init(struct platform_device *pdev, struct mtk_apu *apu)drivers/soc/mediatek/apusys/apu-ipi.c new file +14
-0+{ +struct device *dev = apu->dev; +int i, ret; + + tx_serial_no =0 ; + rx_serial_no =0 ; + +mutex_init (&apu->send_lock); +spin_lock_init (&apu->usage_cnt_lock); +for (i =0 ; i <APU_IPI_MAX ; i++) { +mutex_init (&apu->ipi_desc[i].lock); + lockdep_set_class_and_name(&apu->ipi_desc[i].lock, + &ipi_lock_key[i], + apu->platdata-Quoted 1 line
ipi_attrs[i].name);
drivers/soc/mediatek/apusys/apu-ipi.c new file +7
-0+ } + +init_waitqueue_head (&apu->run.wq); +init_waitqueue_head (&apu->ack_wq); + +/* APU initialization IPI register */ + ret = apu_ipi_register(apu, APU_IPI_INIT, apu_init_ipi_handler,apu);
drivers/soc/mediatek/apusys/apu-ipi.c new file +2
-0+if (ret) { + dev_err(dev, "failed to register ipi for init,ret=%d\n",
drivers/soc/mediatek/apusys/apu-ipi.c new file +9
-0+ ret); +return ret; + } + +/* add rpmsg subdev */ +apu_add_rpmsg_subdev (apu); + +/* register mailbox IRQ */ + apu->mbox0_irq_number = platform_get_irq_byname(pdev,"
mbox0_irq");drivers/soc/mediatek/apusys/apu-ipi.c new file +4
-0+dev_info (&pdev->dev,"%s: mbox0_irq = %d\n" , __func__, + apu->mbox0_irq_number); + + ret = devm_request_threaded_irq(&pdev->dev, apu-Quoted 1 line
mbox0_irq_number,drivers/soc/mediatek/apusys/apu-ipi.c new file +1
-0+ NULL, apu_ipi_handler,
IRQF_ONESHOT,drivers/soc/mediatek/apusys/apu-ipi.c line 473
Quoted 1 line
drivers/soc/mediatek/apusys/apu-ipi.c new file +1
-0+ "apu_ipi", apu);This is the mailbox interrupt... but it's handled in this driver instead of
being handler in the mailbox driver... it's a bit confusing.Is this interrupt supposed to fire as a mailbox doorbell or..? In that case, you should request it in the mailbox driver and register an
interrupt controller (still, in the mailbox driver) so that you can export
a sw interrupt to this one.Quoted 2 lines
Or, maybe you can use notifiers to catch the mailbox message in this driver?
Ack.
Quoted 87 lines
Quoted 13 lines
drivers/soc/mediatek/apusys/apu-ipi.c new file +13
-0+if (ret <0 ) + goto remove_rpmsg_subdev; + +apu_mbox_hw_init (apu); + +return 0 ; + +remove_rpmsg_subdev: +apu_remove_rpmsg_subdev (apu); +apu_ipi_unregister (apu,APU_IPI_INIT ); + +return ret; +}snip...
Quoted 71 lines
drivers/soc/mediatek/apusys/apu-rproc.c new file +53
-0@@ -0,0 +1,806 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (c) 2021 MediaTek Inc. +*/ + +#include <linux/delay.h> +#include <linux/device.h> +#include <linux/dma-mapping.h> +#include <linux/interrupt.h> +#include <linux/iommu.h> +#include <linux/irq.h> +#include <linux/module.h> +#include <linux/remoteproc.h> +#include <linux/time64.h> +#include <linux/of_platform.h> +#include <linux/pm_domain.h> +#include <linux/pm_runtime.h> +#include <linux/sched/clock.h> +#include <linux/time64.h> +#include <linux/workqueue.h> + +#include "apu.h" +#include "apu-config.h" +#include "apu-core.h" + +/* cmd */ +enum { +DPIDLE_CMD_LOCK_IPI =0x5a00 , +DPIDLE_CMD_UNLOCK_IPI =0x5a01 , +DPIDLE_CMD_PDN_UNLOCK =0x5a02 , +}; + +/* ack */ +enum { +DPIDLE_ACK_OK =0 , +DPIDLE_ACK_LOCK_BUSY , +DPIDLE_ACK_POWER_DOWN_FAIL , +}; + +static struct work_struct *apu_pwr_work; +static struct workqueue_struct *apu_pwr_wq; +static struct dentry *dbg_root; + +static void *apu_da_to_va (struct rproc *rproc,u64 da,size_t len, +bool *is_iomem) +{ +void *ptr =NULL ; +struct mtk_apu *apu = (struct mtk_apu *)rproc->priv; + +if (da >=DRAM_OFFSET && da <DRAM_OFFSET +CODE_BUF_SIZE ) { + ptr = apu->code_buf + (da -DRAM_OFFSET ); + }else { + dev_err(apu->dev, "%s: invalid da: da = 0x%llx, len =%zu\n",
drivers/soc/mediatek/apusys/apu-rproc.c new file +10
-0+ __func__, da, len); + } +return ptr; +} + +static int apu_run (struct rproc *rproc) +{ +struct mtk_apu *apu = (struct mtk_apu *)rproc->priv; +struct mtk_apu_hw_ops *hw_ops = &apu->platdata->ops; +struct device *dev = apu->dev;Quoted 8 lines
drivers/soc/mediatek/apusys/apu-rproc.c line 69
Quoted 6 lines
drivers/soc/mediatek/apusys/apu-rproc.c new file +6
-0+struct apu_run *run = &apu->run; +struct timespec64 begin, end, delta; +int ret; + +pm_runtime_get_sync (apu->dev); + hw_ops->start (apu);Don't forget to always check return values.....
Ack.
Quoted 76 lines
Quoted 8 lines
drivers/soc/mediatek/apusys/apu-rproc.c new file +6
-0+ +/* check if boot success */ +ktime_get_ts64 (&begin); + ret =wait_event_interruptible_timeout (run->wq, + run->signaled, +msecs_to_jiffies (10000 ));
#define
APU_INIT_TIMEOUT_MS10000...but then, does it really need 10 *seconds* for that?! That's a lot of time...
Quoted 25 lines
drivers/soc/mediatek/apusys/apu-rproc.c new file +14
-0+ktime_get_ts64 (&end); +if (ret ==0 ) { +dev_info (dev,"APU initialization timeout!!\n" ); + ret = -ETIME ; + goto stop; + } +if (ret == -ERESTARTSYS ) { +dev_info (dev,"wait APU interrupted by a signal!!\n" ); + goto stop; + } + + apu->boot_done = true; + delta =timespec64_sub (end, begin); + dev_info(dev, "APU uP boot success. boot time: %llu s, %lluns\n",
drivers/soc/mediatek/apusys/apu-rproc.c new file +10
-0+ (u64)delta.tv_sec, (u64)delta.tv_nsec); + +return 0 ; + +stop: + hw_ops->stop (apu); + +return ret; +} +snip...
Quoted 20 lines
drivers/soc/mediatek/apusys/apu-rproc.c new file +12
-0+ +static int apu_config_setup (struct mtk_apu *apu) +{ +struct device *dev = apu->dev; +unsigned long flags; +int ret; + + apu->conf_buf =dma_alloc_coherent (apu->dev,CONFIG_SIZE , + &apu->conf_da,GFP_KERNEL ); + +if (!apu->conf_buf || apu->conf_da ==0 ) { + dev_info(dev, "%s: dma_alloc_coherent fail\n",
__func__);drivers/soc/mediatek/apusys/apu-rproc.c new file +7
-0+return -ENOMEM ; + } +memset (apu->conf_buf,0 ,CONFIG_SIZE ); + +apu_config_user_ptr_init (apu); +spin_lock_irqsave (&apu->reg_lock, flags); +iowrite32 ((u32 )apu->conf_da, apu->apu_mbox +HOST_CONFIG_ADDR );drivers/soc/mediatek/apusys/apu-rproc.c line 436
Quoted 10 lines
drivers/soc/mediatek/apusys/apu-rproc.c new file +10
-0+spin_unlock_irqrestore (&apu->reg_lock, flags); + + apu->conf_buf->time_offset =sched_clock (); + ret =apu_ipi_config_init (apu); +if (ret) { +dev_info (dev,"apu ipi config init failed\n" ); + goto out; + } + + ret =sw_logger_config_init (apu);From what I understand, the sw logger is not critical for
Quoted 8 lines
functionality... so
it should probably be a "pluggable" instead.
Also, since that sw logger seems to be "simply" reading from a mailbox, it
should be pretty straightforward to make it so, in which case, you wouldn't
be initializing it here, but as a platform driver instead (if debugging enabled?)It is for debug usage and I think it can be a pluggable module. But it still needs configurations in the boot stage to make micorprocessor enable the logger. I will update this part.
Quoted 61 lines
Quoted 14 lines
drivers/soc/mediatek/apusys/apu-rproc.c new file +13
-0+if (ret) { +dev_err (dev,"sw logger config init failed\n" ); + goto err_sw_logger; + } + +return 0 ; + +err_sw_logger: +apu_ipi_config_remove (apu); +out: +return ret; +} +snip...
Quoted 27 lines
drivers/soc/mediatek/apusys/apu.h new file +20
-0@@ -0,0 +1,256 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Copyright (c) 2021 MediaTek Inc. +*/ + +#ifndef APU_H +#define APU_H +#include <linux/platform_device.h> +#include <linux/spinlock.h> +#include <linux/rpmsg/mtk_rpmsg.h> + +#include "apu-config.h" + +/* setup the SMC command ops */ +#define MTK_SIP_APU_START_MCU 0x00 +#define MTK_SIP_APU_STOP_MCU 0x01 + +/* md32_sysctrl register definition */ +#define MD32_SYS_CTRL 0x0 +#define MD32_MON_PC 0x838drivers/soc/mediatek/apusys/apu.h line 30
Quoted 10 lines
drivers/soc/mediatek/apusys/apu.h new file +10
-0+#define MD32_MON_LR 0x83c +#define MD32_MON_SP 0x840 +#define MD32_STATUS 0x844 + +/*wdt register */ +#define WDT_INT 0x0 +#define WDT_CTRL0 0x4 +#define WDT_EN BIT(31) + +/* apu_mbox spare regiter */ /*
apu_mboxspare register: mbox 0..6, spare 0..3 */
#defineREG_MBOX_SPARE(mbox, reg)((0x40+ (0x100* mbox)) + (reg
*0x4))
#defineREG_MBOX0_SPARE(n)REG_MBOX_SPARE(0, n)
#defineREG_MBOX6_SPARE(n)REG_MBOX_SPARE(6, n)Quoted 5 lines
#define
HOST_CONFIG_ADDRREG_MBOX_SPARE(0, 2)Would that be better? Granted, mbox1-5 are also accessible and perhaps used
in the future.Ack.
Quoted 13 lines
Quoted 13 lines
drivers/soc/mediatek/apusys/apu.h new file +13
-0+#define MBOX0_SPARE0 0x40 +#define MBOX0_SPARE1 0x44 +#define MBOX0_SPARE2 0x48 +#define MBOX0_SPARE3 0x4C +#define MBOX6_SPARE0 0x640 +#define MBOX6_SPARE1 0x644 +#define MBOX6_SPARE2 0x648 +#define MBOX6_SPARE3 0x64C + +#define HOST_CONFIG_ADDR MBOX0_SPARE2 + +#define LOG_W_PTR (MBOX0_SPARE0) +#define LOG_R_PTR (MBOX0_SPARE1)Quoted 8 lines
drivers/soc/mediatek/apusys/apu.h line 49
Quoted 6 lines
drivers/soc/mediatek/apusys/apu.h new file +6
-0+#define LOG_OV_FLG (MBOX0_SPARE3) + +/* rv setup */ +#define F_PRELOAD_FIRMWARE BIT(0) +#define F_AUTO_BOOT BIT(1) +Use SZ_* macros where possible
Ack.
Quoted 80 lines
Quoted 80 lines
drivers/soc/mediatek/apusys/apu.h new file +79
-0+#define TCM_SIZE (128UL * 1024UL) +#define CODE_BUF_SIZE (1024UL * 1024UL) +#define DRAM_DUMP_SIZE (CODE_BUF_SIZE - TCM_SIZE) +#define REG_SIZE (4UL * 151UL) +#define TBUF_SIZE (4UL * 32UL) +#define CACHE_DUMP_SIZE (37UL * 1024UL) +#define DRAM_OFFSET (0x00000UL) +#define DRAM_DUMP_OFFSET (TCM_SIZE) +#define TCM_OFFSET (0x1d700000UL) +#define CODE_BUF_DA (DRAM_OFFSET) + +/* ipi */ +#define APU_FW_VER_LEN 32 +#define APU_SHARE_BUFFER_SIZE 256 + +#define IPI_LOCKED 1 +#define IPI_UNLOCKED 0 + +#define IPI_HOST_INITIATE 0 +#define IPI_APU_INITIATE 1 +#define IPI_WITH_ACK 1 +#define IPI_WITHOUT_ACK 0 + +enum { +APU_IPI_INIT =0 , +APU_IPI_NS_SERVICE , +APU_IPI_DEEP_IDLE , +APU_IPI_CTRL_RPMSG , +APU_IPI_MIDDLEWARE , +APU_IPI_REVISER_RPMSG , +APU_IPI_PWR_TX , +APU_IPI_PWR_RX , +APU_IPI_MDLA_TX , +APU_IPI_MDLA_RX , +APU_IPI_TIMESYNC , +APU_IPI_EDMA_TX , +APU_IPI_MNOC_TX , +APU_IPI_MAX , +}; + +struct mtk_apu ; + +struct mtk_apu_hw_ops { +int (*init)(struct mtk_apu *apu); +int (*exit)(struct mtk_apu *apu); +int (*start)(struct mtk_apu *apu); +int (*stop)(struct mtk_apu *apu); +int (*resume)(struct mtk_apu *apu); +int (*apu_memmap_init)(struct mtk_apu *apu); +void (*apu_memmap_remove)(struct mtk_apu *apu); +void (*cg_gating)(struct mtk_apu *apu); +void (*cg_ungating)(struct mtk_apu *apu); +void (*rv_cachedump)(struct mtk_apu *apu); + +/* power related ops */ +int (*power_init)(struct mtk_apu *apu); +int (*power_on)(struct mtk_apu *apu); +int (*power_off)(struct mtk_apu *apu); +}; + +struct apu_ipi { +char *name; +unsigned int direction:1 ; +unsigned int ack:1 ; +}; + +struct mtk_apu_platdata { +u32 flags; +struct mtk_apu_hw_ops ops; +const struct apu_ipi *ipi_attrs; +}; + +struct dpidle_msg { +u32 cmd; +u32 ack; +}; + +struct apu_run { +s8 fw_ver[APU_FW_VER_LEN ];Quoted 9 lines
drivers/soc/mediatek/apusys/apu.h line 134
Quoted 6 lines
drivers/soc/mediatek/apusys/apu.h new file +6
-0+u32 signaled; +wait_queue_head_t wq; +}; + +struct apu_ipi_desc { +struct mutex lock;/*ipi hanlder mutex */ typo
Quoted 153 lines
Ack.
Quoted 152 lines
Quoted 151 lines
drivers/soc/mediatek/apusys/apu.h new file +98
-0+ipi_handler_t handler; +void *priv; +/* +* positive: host-initiated ipi outstanding count +* negative: apu-initiated ipi outstanding count +*/ +int usage_cnt; +}; + +struct mtk_share_obj { +u8 share_buf[APU_SHARE_BUFFER_SIZE ]; +}; + +struct sw_logger_seq_data { +u32 w_ptr; +u32 r_ptr; +u32 overflow_flg; +int i; +int is_finished; +char *data; +bool startl_first; +}; + +struct mtk_apu { +struct rproc *rproc; +struct device *dev; +void __iomem *apu_mbox; +void __iomem *md32_sysctrl; +void __iomem *apu_wdt; +int mbox0_irq_number; +int wdt_irq_number; +spinlock_t reg_lock;/* register r/w lock */ + +/* Buffer to place execution area */ +void *code_buf; +dma_addr_t code_da; + +/* Buffer to place config area */ +struct config_v1 *conf_buf; +dma_addr_t conf_da; + +/* to synchronize boot status of remote processor */ +struct apu_run run; + +/* to prevent multiple ipi_send run concurrently */ +struct mutex send_lock; +spinlock_t usage_cnt_lock;/* ipi occipued lock */ +struct apu_ipi_desc ipi_desc[APU_IPI_MAX ]; +bool ipi_id_ack[APU_IPI_MAX ];/* per-ipi ack */ +bool ipi_inbound_locked; +wait_queue_head_t ack_wq;/* for waiting for ipi ack */ + +/* ipi */ +struct rproc_subdev *rpmsg_subdev; +dma_addr_t recv_buf_da; +struct mtk_share_obj *recv_buf; +dma_addr_t send_buf_da; +struct mtk_share_obj *send_buf; + +/* time sync */ +struct work_struct timesync_work; +struct workqueue_struct *timesync_wq; +u64 timesync_stamp; + +/*deep idle */ +struct dpidle_msg recv_msg; +struct work_struct deepidle_work; +struct workqueue_struct *apu_deepidle_workq; +struct work_struct pwron_dbg_wk; + +struct mtk_apu_platdata *platdata; + +/* link power deive */ +struct device *power_dev; +bool boot_done; +struct work_struct pwr_work; + +/* logger and debug */ +struct dentry *dbg_root; +dma_addr_t handle; +char *sw_log_buf; +spinlock_t sw_logger_spinlock;/* logger status update lock */ +struct sw_logger_seq_data pseqdata_lock; +struct sw_logger_seq_data *pseqdata; +}; + +struct apu_coredump { +char tcmdump[TCM_SIZE ]; +char ramdump[DRAM_DUMP_SIZE ]; +char regdump[REG_SIZE ]; +char tbufdump[TBUF_SIZE ]; +u32 cachedump[CACHE_DUMP_SIZE /sizeof (u32)]; +} __packed; + +int apu_ipi_config_init (struct mtk_apu *apu); +void apu_ipi_config_remove (struct mtk_apu *apu); +void apu_ipi_remove (struct mtk_apu *apu); +int apu_ipi_init(struct platform_device *pdev, struct mtk_apu*apu);
drivers/soc/mediatek/apusys/apu.h new file +17
-0+int apu_ipi_register (struct mtk_apu *apu,u32 id, +ipi_handler_t handler,void *priv); +void apu_ipi_unregister (struct mtk_apu *apu,u32 id); +int apu_ipi_send (struct mtk_apu *apu,u32 id,void *data,u32 len, +u32 wait_ms); +int apu_ipi_lock (struct mtk_apu *apu); +void apu_ipi_unlock (struct mtk_apu *apu); + +void apu_deepidle_power_on_aputop (struct mtk_apu *apu); + +#if IS_ENABLED (CONFIG_DEBUG_FS ) +int sw_logger_config_init (struct mtk_apu *apu); +void sw_logger_config_remove (struct mtk_apu *apu); +int apu_sw_logger_init (struct mtk_apu *apu); +void apu_sw_logger_remove (struct mtk_apu *apu); +#else +static inline int sw_logger_config_init (struct mtk_apu *apu) {return 0; }
+static inline voidsw_logger_config_remove(struct mtk_apu *apu){ }
+static inline intapu_sw_logger_init(struct mtk_apu *apu){ return 0; }drivers/soc/mediatek/apusys/apu.h new file +5
-0+static inline void apu_sw_logger_remove (struct mtk_apu *apu) { } +#endif + +extern const struct mtk_apu_platdata mt8192_platdata; +#endif /* APU_H */ drivers/soc/mediatek/apusys/mt81xx-plat.c new file +18
-0@@ -0,0 +1,320 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (c) 2021 MediaTek Inc. +*/ + +#include <linux/arm-smccc.h> +#include <linux/delay.h> +#include <linux/device.h> +#include <linux/io.h> +#include <linux/iopoll.h> +#include <linux/of_platform.h> +#include <linux/pm_runtime.h> +#include <linux/sched/clock.h> +#include <linux/soc/mediatek/mtk_sip_svc.h> + +#include "apu.h" + +static const struct apu_ipi mt81xx_ipi_attrs[APU_IPI_MAX ] = {
Hello Flora,
Quoted 3 lines
Quoted 3 lines
In here, this is used only to pass it to the remoteproc "ipi" driver:
it would make
sense if this was in the ipi driver, associated to a compatible like
^^^^^ Sorry, I was meaning the -> rproc driver <-
Quoted 9 lines
Quoted 2 lines
mediatek,mt8192-ipi.
Hi, Algelo,
I am not quite sure about the comments. Could you explain more details?The list is used in kernel as ipi channe attributes by platforms(different platfrom will has differnt settings) to create ipi channesl by mtk-rpmsg. The ipi-attrs is add into platform data.
Quoted 12 lines
const struct mtk_apu_platdata mt8192_platdata = {
.flags = F_AUTO_BOOT,
.ipi_attrs = mt81xx_ipi_attrs,
.ops = {
.init = NULL,
snip.
.power_init = mt81xx_apu_power_init,
.power_on = mt81xx_apu_power_on,
.power_off = mt81xx_apu_power_off,
},
};Reiterating: this file is very short and also it looks like the code in here will be common (or commonizable) between multiple SoCs, so please move everything that is in here to apu-rproc.c.
Regards,
- Angelo
Quoted 122 lines
Quoted 113 lines
Quoted 94 lines
drivers/soc/mediatek/apusys/mt81xx-plat.c new file +94
-0+ [APU_IPI_INIT ] = { + .name ="init" , + .direction =IPI_APU_INITIATE , + .ack =IPI_WITHOUT_ACK , + }, + [APU_IPI_NS_SERVICE ] = { + .name ="name-service" , + .direction =IPI_APU_INITIATE , + .ack =IPI_WITHOUT_ACK , + }, + [APU_IPI_DEEP_IDLE ] = { + .name ="deep_idle" , + .direction =IPI_APU_INITIATE , + .ack =IPI_WITH_ACK , + }, + [APU_IPI_CTRL_RPMSG ] = { + .name ="apu-ctrl-rpmsg" , + .direction =IPI_APU_INITIATE , + .ack =IPI_WITH_ACK , + }, + [APU_IPI_MIDDLEWARE ] = { + .name ="apu-mdw-rpmsg" , + .direction =IPI_HOST_INITIATE , + .ack =IPI_WITH_ACK , + }, + [APU_IPI_REVISER_RPMSG ] = { + .name ="apu-reviser-rpmsg" , + .direction =IPI_HOST_INITIATE , + .ack =IPI_WITH_ACK , + }, + [APU_IPI_PWR_TX ] = { + .name ="apupwr-tx-rpmsg" , + .direction =IPI_HOST_INITIATE , + .ack =IPI_WITH_ACK , + }, + [APU_IPI_PWR_RX ] = { + .name ="apupwr-rx-rpmsg" , + .direction =IPI_APU_INITIATE , + .ack =IPI_WITH_ACK , + }, + [APU_IPI_MDLA_TX ] = { + .name ="mdla-tx-rpmsg" , + .direction =IPI_HOST_INITIATE , + .ack =IPI_WITH_ACK , + }, + [APU_IPI_MDLA_RX ] = { + .name ="mdla-rx-rpmsg" , + .direction =IPI_APU_INITIATE , + .ack =IPI_WITH_ACK , + }, + [APU_IPI_TIMESYNC ] = { + .name ="apu-timesync" , + .direction =IPI_APU_INITIATE , + .ack =IPI_WITH_ACK , + }, + [APU_IPI_EDMA_TX ] = { + .name ="apu-edma-rpmsg" , + .direction =IPI_HOST_INITIATE , + .ack =IPI_WITHOUT_ACK , + }, + [APU_IPI_MNOC_TX ] = { + .name ="apu-mnoc-rpmsg" , + .direction =IPI_HOST_INITIATE , + .ack =IPI_WITHOUT_ACK , + }, +}; + +static void apu_reset_mcu (struct mtk_apu *apu) +{ +u32 reg; + +/* assert mcu reset */ + reg =ioread32 (apu->md32_sysctrl); +iowrite32 (reg & ~0x1 , apu->md32_sysctrl); +mdelay (10 ); +iowrite32 (reg |0x1 , apu->md32_sysctrl); +} + +static int apu_start_mcu (struct mtk_apu *apu) +{ +struct arm_smccc_res ares; + +/* initialize IOMMU and ACP config (iommu_tr_en=1, acp_en=0) */ +iowrite32 (0xEA9 , apu->md32_sysctrl); + +arm_smccc_smc (MTK_SIP_APUSYS_CONTROL ,MTK_SIP_APU_START_MCU , +0 ,0 ,0 ,0 ,0 ,0 , &ares); +if (ares.a0) +dev_err (apu->dev,"start mcu fail: %lu\n" , ares.a0); + +return 0 ; +} + +static int apu_stop_mcu (struct mtk_apu *apu)drivers/soc/mediatek/apusys/mt81xx-plat.c line 122
Quoted 10 lines
drivers/soc/mediatek/apusys/mt81xx-plat.c new file +10
-0+{ +struct arm_smccc_res ares; + +arm_smccc_smc (MTK_SIP_APUSYS_CONTROL ,MTK_SIP_APU_STOP_MCU , +0 ,0 ,0 ,0 ,0 ,0 , &ares); +if (ares.a0) +dev_err (apu->dev,"stop mcufail: %lu\n" , ares.a0); + +return 0 ; +}Is it expected for other SoCs to have different (or more) secure world calls?
If it is, then it may be worth it to move this to a different driver indrivers/firmware, so that you will be able to map different/more values to
different compatibles.Quoted 1 line
Otherwise, keep it here.
This is for apu usage and only for apu. I will keep it here. The SMC receivers are also found in ATF upstream.
https://review.trustedfirmware.org/c/TF-A/trusted-firmware-a/+/9709/11.Thanks for your comments.
Quoted 1 line
- Angelo
RFC 9/13 soc: mediatek: apu: Add middleware driver
In reply to Flora FuAPU middleware is responsible to receive all user's requests and control command and device related flow.
In Kernel side, the middleware use the IPI to send command to remote tinysys to dispatch commands to AI engines in APU.
--- drivers/soc/mediatek/apusys/Makefile | 9 + drivers/soc/mediatek/apusys/apu-core.c | 2 + drivers/soc/mediatek/apusys/apu-core.h | 2 + drivers/soc/mediatek/apusys/apu-device.h | 39 + drivers/soc/mediatek/apusys/mdw-cmd.c | 618 +++++++++++++++ drivers/soc/mediatek/apusys/mdw-drv.c | 211 +++++ drivers/soc/mediatek/apusys/mdw-ioctl.c | 331 ++++++++ drivers/soc/mediatek/apusys/mdw-ioctl.h | 256 +++++++ drivers/soc/mediatek/apusys/mdw-mem.c | 938 +++++++++++++++++++++++ drivers/soc/mediatek/apusys/mdw-mem.h | 23 + drivers/soc/mediatek/apusys/mdw-rv-cmd.c | 158 ++++ drivers/soc/mediatek/apusys/mdw-rv-dev.c | 386 ++++++++++ drivers/soc/mediatek/apusys/mdw-rv-msg.h | 90 +++ drivers/soc/mediatek/apusys/mdw-rv.c | 131 ++++ drivers/soc/mediatek/apusys/mdw-rv.h | 98 +++ drivers/soc/mediatek/apusys/mdw-sysfs.c | 200 +++++ drivers/soc/mediatek/apusys/mdw.h | 208 +++++ 17 files changed, 3700 insertions(+) create mode 100644 drivers/soc/mediatek/apusys/apu-device.h create mode 100644 drivers/soc/mediatek/apusys/mdw-cmd.c create mode 100644 drivers/soc/mediatek/apusys/mdw-drv.c create mode 100644 drivers/soc/mediatek/apusys/mdw-ioctl.c create mode 100644 drivers/soc/mediatek/apusys/mdw-ioctl.h create mode 100644 drivers/soc/mediatek/apusys/mdw-mem.c create mode 100644 drivers/soc/mediatek/apusys/mdw-mem.h create mode 100644 drivers/soc/mediatek/apusys/mdw-rv-cmd.c create mode 100644 drivers/soc/mediatek/apusys/mdw-rv-dev.c create mode 100644 drivers/soc/mediatek/apusys/mdw-rv-msg.h create mode 100644 drivers/soc/mediatek/apusys/mdw-rv.c create mode 100644 drivers/soc/mediatek/apusys/mdw-rv.h create mode 100644 drivers/soc/mediatek/apusys/mdw-sysfs.c create mode 100644 drivers/soc/mediatek/apusys/mdw.h
drivers/soc/mediatek/apusys/Makefile +9 -0
@@ -13,3 +13,12 @@ apu-objs += apu-ipi.o apu-objs += apu-mbox.o apu-objs += mt81xx-plat.o apu-$(CONFIG_DEBUG_FS) += apu-sw-logger.o + +apu-objs += mdw-drv.o +apu-objs += mdw-ioctl.o +apu-objs += mdw-mem.o +apu-objs += mdw-cmd.o +apu-objs += mdw-rv.o +apu-objs += mdw-rv-cmd.o +apu-objs += mdw-rv-dev.o +apu-$(CONFIG_DEBUG_FS) += mdw-sysfs.o
drivers/soc/mediatek/apusys/apu-core.c +2 -0
@@ -19,6 +19,7 @@ static struct apusys_core_info g_core_info;*/ static int (*apusys_init_func[])(struct apusys_core_info *) = { apu_power_drv_init, + mdw_init, apu_rproc_init, };
@@ -28,6 +29,7 @@ static int (*apusys_init_func[])(struct apusys_core_info *) = {*/ static void (*apusys_exit_func[])(void ) = { apu_rproc_exit, + mdw_exit, apu_power_drv_exit, };
drivers/soc/mediatek/apusys/apu-core.h +2 -0
@@ -11,6 +11,8 @@ struct apusys_core_info {int apu_power_drv_init (struct apusys_core_info *info);void apu_power_drv_exit (void ); +int mdw_init (struct apusys_core_info *info); +void mdw_exit (void );int apu_rproc_init (struct apusys_core_info *info);void apu_rproc_exit (void );#endif
drivers/soc/mediatek/apusys/apu-device.h new file +39 -0
@@ -0,0 +1,39 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Copyright (c) 2021 MediaTek Inc. +*/ + +#ifndef APUSYS_DEVICE_H +#define APUSYS_DEVICE_H + +#include <linux/dma-buf.h> + +/* device type */ +enum { +APUSYS_DEVICE_NONE , + +APUSYS_DEVICE_SAMPLE , +APUSYS_DEVICE_MDLA , +APUSYS_DEVICE_VPU , +APUSYS_DEVICE_EDMA , +APUSYS_DEVICE_RT =32 , +APUSYS_DEVICE_SAMPLE_RT , +APUSYS_DEVICE_MDLA_RT , +APUSYS_DEVICE_VPU_RT , + +APUSYS_DEVICE_MAX =64 , +}; + +/* device definition */ +#define APUSYS_DEVICE_META_SIZE (32) + +struct apusys_device { +int dev_type; +int idx; +int preempt_type; +u8 preempt_level; +char meta_data[APUSYS_DEVICE_META_SIZE ]; +void *private; +int (*send_cmd)(int type,void *hnd,struct apusys_device *dev); +}; +#endif
drivers/soc/mediatek/apusys/mdw-cmd.c new file +618 -0
618 lines not on this page · raw message
drivers/soc/mediatek/apusys/mdw-drv.c new file +211 -0
211 lines not on this page · raw message
drivers/soc/mediatek/apusys/mdw-ioctl.c new file +331 -0
331 lines not on this page · raw message
drivers/soc/mediatek/apusys/mdw-ioctl.h new file +256 -0
256 lines not on this page · raw message
drivers/soc/mediatek/apusys/mdw-mem.c new file +938 -0
938 lines not on this page · raw message
drivers/soc/mediatek/apusys/mdw-mem.h new file +23 -0
@@ -0,0 +1,23 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Copyright (c) 2021 MediaTek Inc. +*/ + +#ifndef __MTK_APU_MDW_MEM_H__ +#define __MTK_APU_MDW_MEM_H__ + +struct mdw_mem *mdw_mem_alloc (struct mdw_fpriv *mpriv,u32 size, +u32 align,u64 flags, +enum mdw_mem_type type); +struct mdw_mem *mdw_mem_import (struct mdw_fpriv *mpriv,u64 handle,u32 size); +struct mdw_mem *mdw_mem_get (int handle); +int mdw_mem_map (struct mdw_mem *m); +int mdw_mem_unmap (struct mdw_mem *m); +int mdw_mem_init (struct mdw_device *mdev); +void mdw_mem_deinit (struct mdw_device *mdev); +int mdw_mem_free (struct mdw_mem *mem); +int mdw_mem_dma_map (struct mdw_mem *mem); +int mdw_mem_dma_unmap (struct mdw_mem *mem); +int apusys_mem_flush_kva (void *kva,u32 size); +int apusys_mem_invalidate_kva (void *kva,u32 size); +#endif
drivers/soc/mediatek/apusys/mdw-rv-cmd.c new file +158 -0
158 lines not on this page · raw message
drivers/soc/mediatek/apusys/mdw-rv-dev.c new file +386 -0
386 lines not on this page · raw message
drivers/soc/mediatek/apusys/mdw-rv-msg.h new file +90 -0
6 lines not on this page · raw message
drivers/soc/mediatek/apusys/mdw-rv.c new file +131 -0
131 lines not on this page · raw message
drivers/soc/mediatek/apusys/mdw-rv.h new file +98 -0
98 lines not on this page · raw message
drivers/soc/mediatek/apusys/mdw-sysfs.c new file +200 -0
200 lines not on this page · raw message
drivers/soc/mediatek/apusys/mdw.h new file +208 -0
208 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.18.0
Part of the diff is not shown here. View the raw message.
RFC 10/13 arm64: dts: mt8192: Add APU-IOMMU nodes
In reply to Flora FuFrom: Yong Wu <[email protected]>
Add APU-IOMMI nodes
--- arch/arm64/boot/dts/mediatek/mt8192.dtsi | 9 +++++++++ 1 file changed, 9 insertions(+)
arch/arm64/boot/dts/mediatek/mt8192.dtsi +9 -0
@@ -8,6 +8,7 @@ #include <dt-bindings/clock/mt8192-clk.h> #include <dt-bindings/interrupt-controller/arm-gic.h> #include <dt-bindings/interrupt-controller/irq.h> +#include <dt-bindings/memory/mt8192-larb-port.h> #include <dt-bindings/pinctrl/mt8192-pinfunc.h> #include <dt-bindings/power/mt8192-power.h>
@@ -916,6 +917,14 @@ #clock-cells = <1>; }; + iommu_apu: m4u@19010000 { + compatible = "mediatek,mt8192-iommu-apu"; + reg = <0 0x19010000 0 0x1000>; + interrupts = <GIC_SPI 394 IRQ_TYPE_LEVEL_HIGH 0>; + power-domains = <&apuspm 0>; + #iommu-cells = <1>; + }; + apu_conn: apu_conn@19020000 { compatible = "mediatek,mt8192-apu-conn", "syscon"; reg = <0 0x19020000 0 0x1000>;
Signature · 1 line
2.18.0
RFC 11/13 arm64: dts: mt8192: Add apu power nodes
In reply to Flora FuAdd apu power node.
--- arch/arm64/boot/dts/mediatek/mt8192.dtsi | 62 ++++++++++++++++++++++++ 1 file changed, 62 insertions(+)
arch/arm64/boot/dts/mediatek/mt8192.dtsi +62 -0
@@ -964,6 +964,68 @@ }; }; + apusys_power: apusys_power@190f1000 { + compatible = "mediatek,apusys-power", + "mediatek,mt8192-apu-power"; + reg = <0 0x190f1000 0 0x1000>, + <0 0x19000600 0 0x100>; + reg-names = "apu_pcu", + "apu_spare"; + power-domains = <&apuspm 0>; + clocks = <&topckgen CLK_TOP_DSP_SEL>, + <&topckgen CLK_TOP_DSP1_SEL>, + <&topckgen CLK_TOP_DSP1_NPUPLL_SEL>, + <&topckgen CLK_TOP_DSP2_SEL>, + <&topckgen CLK_TOP_DSP2_NPUPLL_SEL>, + <&topckgen CLK_TOP_DSP5_SEL>, + <&topckgen CLK_TOP_DSP5_APUPLL_SEL>, + <&topckgen CLK_TOP_IPU_IF_SEL>, + <&clk26m>, + <&topckgen CLK_TOP_MAINPLL_D4_D2>, + <&topckgen CLK_TOP_UNIVPLL_D4_D2>, + <&topckgen CLK_TOP_UNIVPLL_D6_D2>, + <&topckgen CLK_TOP_MMPLL_D6>, + <&topckgen CLK_TOP_MMPLL_D5>, + <&topckgen CLK_TOP_MMPLL_D4>, + <&topckgen CLK_TOP_UNIVPLL_D5>, + <&topckgen CLK_TOP_UNIVPLL_D4>, + <&topckgen CLK_TOP_UNIVPLL_D3>, + <&topckgen CLK_TOP_MAINPLL_D6>, + <&topckgen CLK_TOP_MAINPLL_D4>, + <&topckgen CLK_TOP_MAINPLL_D3>, + <&topckgen CLK_TOP_TVDPLL>, + <&topckgen CLK_TOP_APUPLL>, + <&topckgen CLK_TOP_NPUPLL>, + <&apmixedsys CLK_APMIXED_APUPLL>, + <&apmixedsys CLK_APMIXED_NPUPLL>; + clock-names = "clk_top_dsp_sel", + "clk_top_dsp1_sel", + "clk_top_dsp1_npupll_sel", + "clk_top_dsp2_sel", + "clk_top_dsp2_npupll_sel", + "clk_top_dsp5_sel", + "clk_top_dsp5_apupll_sel", + "clk_top_ipu_if_sel", + "clk_top_clk26m", + "clk_top_mainpll_d4_d2", + "clk_top_univpll_d4_d2", + "clk_top_univpll_d6_d2", + "clk_top_mmpll_d6", + "clk_top_mmpll_d5", + "clk_top_mmpll_d4", + "clk_top_univpll_d5", + "clk_top_univpll_d4", + "clk_top_univpll_d3", + "clk_top_mainpll_d6", + "clk_top_mainpll_d4", + "clk_top_mainpll_d3", + "clk_top_tvdpll_ck", + "clk_top_apupll_ck", + "clk_top_npupll_ck", + "clk_apmixed_apupll_rate", + "clk_apmixed_npupll_rate"; + }; + camsys: clock-controller@1a000000 { compatible = "mediatek,mt8192-camsys"; reg = <0 0x1a000000 0 0x1000>;
Signature · 1 line
2.18.0
RFC 12/13 arm64: dts: mt8192: Add apu tinysys
In reply to Flora FuAdd node for APU tinysys.
--- arch/arm64/boot/dts/mediatek/mt8192.dtsi | 36 ++++++++++++++++++++++++ 1 file changed, 36 insertions(+)
arch/arm64/boot/dts/mediatek/mt8192.dtsi +36 -0
@@ -925,6 +925,42 @@ #iommu-cells = <1>; }; + apusys_rv@19001000 { + compatible = "mediatek,mt8192-apusys-rv"; + reg = <0 0x19000000 0 0x1000>, + <0 0x19001000 0 0x1000>, + <0 0x19002000 0 0x10>; + reg-names = "apu_mbox", + "md32_sysctrl", + "apu_wdt"; + mediatek,apusys-power = <&apusys_power>; + power-domains = <&apuspm 0>; + iommus = <&iommu_apu IOMMU_PORT_APU_DATA>; + interrupts = <GIC_SPI 393 IRQ_TYPE_LEVEL_HIGH 0>, + <GIC_SPI 404 IRQ_TYPE_LEVEL_HIGH 0>; + interrupt-names = "apu_wdt", + "mbox0_irq"; + apu_ctrl { + compatible = "mediatek,apu-ctrl-rpmsg"; + mtk,rpmsg-name = "apu-ctrl-rpmsg"; + }; + + apu_pwr_tx { + compatible = "mediatek,apupwr-tx-rpmsg"; + mtk,rpmsg-name = "apupwr-tx-rpmsg"; + }; + + apu_pwr_rx { + compatible = "mediatek,apupwr-rx-rpmsg"; + mtk,rpmsg-name = "apupwr-rx-rpmsg"; + }; + + apu_mdw_rpmsg { + compatible = "mediatek,apu-mdw-rpmsg"; + mtk,rpmsg-name = "apu-mdw-rpmsg"; + }; + }; + apu_conn: apu_conn@19020000 { compatible = "mediatek,mt8192-apu-conn", "syscon"; reg = <0 0x19020000 0 0x1000>;
Signature · 1 line
2.18.0
AngeloGioacchino Del Regno
maintainerRe: [RFC 12/13] arm64: dts: mt8192: Add apu tinysys
Il 23/10/21 13:14, Flora Fu ha scritto:
Quoted 14 lines
Add node for APU tinysys.
Signed-off-by Flora Fu <[email protected]>--- arch/arm64/boot/dts/mediatek/mt8192.dtsi | 36 ++++++++++++++++++++++++ 1 file changed, 36 insertions(+)arch/arm64/boot/dts/mediatek/mt8192.dtsi +0
-0@@ -925,6 +925,42 @@ #iommu-cells = <1>; };
arch/arm64/boot/dts/mediatek/mt8192.dtsi line 936
Quoted 10 lines
arch/arm64/boot/dts/mediatek/mt8192.dtsi +9
-0+ apusys_rv@19001000 { + compatible = "mediatek,mt8192-apusys-rv"; + reg = <0 0x19000000 0 0x1000>, + <0 0x19001000 0 0x1000>, + <0 0x19002000 0 0x10>; + reg-names = "apu_mbox", + "md32_sysctrl", + "apu_wdt"; + mediatek,apusys-power = <&apusys_power>;
As said on the IOMMU commit, I think that apusys-power can be passed as a power domain here as well... also keeping in mind that the apuspm power domain is being used in both the IOMMU and in apusys-power already, so you could even pass only the apusys-power pd here, because apuspm would be already being turned on by the former...
...unless there's any possibility to have some functionality with apuspm up but apusys-power down? From how it looks right now, that's not a thing.
arch/arm64/boot/dts/mediatek/mt8192.dtsi line 945
Quoted 9 lines
arch/arm64/boot/dts/mediatek/mt8192.dtsi +9
-0+ power-domains = <&apuspm 0>; + iommus = <&iommu_apu IOMMU_PORT_APU_DATA>; + interrupts = <GIC_SPI 393 IRQ_TYPE_LEVEL_HIGH 0>, + <GIC_SPI 404 IRQ_TYPE_LEVEL_HIGH 0>; + interrupt-names = "apu_wdt", + "mbox0_irq"; + apu_ctrl { + compatible = "mediatek,apu-ctrl-rpmsg"; + mtk,rpmsg-name = "apu-ctrl-rpmsg";
This is supposed to be "mediatek,rpmsg-name" instead... or it won't work.
Quoted 22 lines
arch/arm64/boot/dts/mediatek/mt8192.dtsi +18
-0+ }; + + apu_pwr_tx { + compatible = "mediatek,apupwr-tx-rpmsg"; + mtk,rpmsg-name = "apupwr-tx-rpmsg"; + }; + + apu_pwr_rx { + compatible = "mediatek,apupwr-rx-rpmsg"; + mtk,rpmsg-name = "apupwr-rx-rpmsg"; + }; + + apu_mdw_rpmsg { + compatible = "mediatek,apu-mdw-rpmsg"; + mtk,rpmsg-name = "apu-mdw-rpmsg"; + }; + }; + apu_conn: apu_conn@19020000 { compatible = "mediatek,mt8192-apu-conn", "syscon"; reg = <0 0x19020000 0 0x1000>;
Re: [RFC 12/13] arm64: dts: mt8192: Add apu tinysys
Quoted 38 lines · AngeloGioacchino Del Regno
Il 23/10/21 13:14, Flora Fu ha scritto:
Quoted 16 lines
Add node for APU tinysys.
Signed-off-by Flora Fu <[email protected]>--- arch/arm64/boot/dts/mediatek/mt8192.dtsi | 36 ++++++++++++++++++++++++ 1 file changed, 36 insertions(+)arch/arm64/boot/dts/mediatek/mt8192.dtsi +0
-0@@ -925,6 +925,42 @@ #iommu-cells = <1>; };arch/arm64/boot/dts/mediatek/mt8192.dtsi line 936
Quoted 10 lines
arch/arm64/boot/dts/mediatek/mt8192.dtsi +9
-0+ apusys_rv@19001000 { + compatible = "mediatek,mt8192-apusys-rv"; + reg = <0 0x19000000 0 0x1000>, + <0 0x19001000 0 0x1000>, + <0 0x19002000 0 0x10>; + reg-names = "apu_mbox", + "md32_sysctrl", + "apu_wdt"; + mediatek,apusys-power = <&apusys_power>;As said on the IOMMU commit, I think that apusys-power can be passed as a
power domain here as well... also keeping in mind that the apuspm power
domain is being used in both the IOMMU and in apusys-power already, so you
could even pass only the apusys-power pd here, because apuspm would be
already being turned on by the former...
Quoted 5 lines
...unless there's any possibility to have some functionality with apuspm up
but apusys-power down? From how it looks right now, that's not a thing.
OK, we will check it.
Quoted 6 lines
Quoted 6 lines
arch/arm64/boot/dts/mediatek/mt8192.dtsi +4
-0+ power-domains = <&apuspm 0>; + iommus = <&iommu_apu IOMMU_PORT_APU_DATA>; + interrupts = <GIC_SPI 393 IRQ_TYPE_LEVEL_HIGH 0>, + <GIC_SPI 404 IRQ_TYPE_LEVEL_HIGH 0>;
Quoted 9 lines
arch/arm64/boot/dts/mediatek/mt8192.dtsi line 945
Quoted 5 lines
arch/arm64/boot/dts/mediatek/mt8192.dtsi +5
-0+ interrupt-names = "apu_wdt", + "mbox0_irq"; + apu_ctrl { + compatible = "mediatek,apu-ctrl-rpmsg"; + mtk,rpmsg-name = "apu-ctrl-rpmsg";This is supposed to be "mediatek,rpmsg-name" instead... or it won't work.
The latest kernel uses "mediatek,rpmsg-name" and I will update the string in the next submission.
Quoted 25 lines
Quoted 25 lines
arch/arm64/boot/dts/mediatek/mt8192.dtsi +9
-0+ }; + + apu_pwr_tx { + compatible = "mediatek,apupwr-tx- rpmsg"; + mtk,rpmsg-name = "apupwr-tx-rpmsg"; + }; + + apu_pwr_rx { + compatible = "mediatek,apupwr-rx-rpmsg";
arch/arm64/boot/dts/mediatek/mt8192.dtsi +9
-0+ mtk,rpmsg-name = "apupwr-rx-rpmsg"; + }; + + apu_mdw_rpmsg { + compatible = "mediatek,apu-mdw-rpmsg"; + mtk,rpmsg-name = "apu-mdw-rpmsg"; + }; + }; + apu_conn: apu_conn@19020000 { compatible = "mediatek,mt8192-apu-conn","syscon";
reg = <00x1902000000x1000>;
RFC 13/13 arm64: dts: mt8192: Add regulator for APU
In reply to Flora FuAdd regulator for mt8192 evb board.
--- arch/arm64/boot/dts/mediatek/mt8192-evb.dts | 5 +++++ 1 file changed, 5 insertions(+)
arch/arm64/boot/dts/mediatek/mt8192-evb.dts +5 -0
@@ -35,3 +35,8 @@ domain-supply = <&mt6359_vproc1_buck_reg>; }; }; + +&apusys_power { + vvpu-supply = <&mt6359_vproc1_buck_reg>; + vmdla-supply = <&mt6359_vproc2_buck_reg>; +};
Signature · 1 line
2.18.0