c6b0606087c5cf2270d0d3faa5392c029a2e5c73
[openwrt/openwrt.git] / target / linux / bcm27xx / patches-4.19 / 950-0447-staging-vc04_services-Use-correct-cache-line-size.patch
1 From 63079fbe20c954140f8eb61f858b0774890f301c Mon Sep 17 00:00:00 2001
2 From: Phil Elwell <phil@raspberrypi.org>
3 Date: Mon, 17 Sep 2018 09:22:21 +0100
4 Subject: [PATCH] staging/vc04_services: Use correct cache line size
5
6 Use the compatible string in the DTB to select the correct cache line
7 size for the SoC - 32 for BCM2835, and 64 for BCM2836 and BCM2837.
8
9 Signed-off-by: Phil Elwell <phil@raspberrypi.org>
10 Tested-by: Stefan Wahren <stefan.wahren@i2se.com>
11 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
12 ---
13 .../interface/vchiq_arm/vchiq_2835_arm.c | 15 ++------
14 .../interface/vchiq_arm/vchiq_arm.c | 35 +++++++++++++------
15 .../interface/vchiq_arm/vchiq_arm.h | 5 +++
16 3 files changed, 33 insertions(+), 22 deletions(-)
17
18 --- a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_2835_arm.c
19 +++ b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_2835_arm.c
20 @@ -117,7 +117,8 @@ free_pagelist(struct vchiq_pagelist_info
21 int vchiq_platform_init(struct platform_device *pdev, VCHIQ_STATE_T *state)
22 {
23 struct device *dev = &pdev->dev;
24 - struct rpi_firmware *fw = platform_get_drvdata(pdev);
25 + struct vchiq_drvdata *drvdata = platform_get_drvdata(pdev);
26 + struct rpi_firmware *fw = drvdata->fw;
27 VCHIQ_SLOT_ZERO_T *vchiq_slot_zero;
28 struct resource *res;
29 void *slot_mem;
30 @@ -135,17 +136,7 @@ int vchiq_platform_init(struct platform_
31 if (err < 0)
32 return err;
33
34 - /*
35 - * The tempting L1_CACHE_BYTES macro doesn't work in the case of
36 - * a kernel built with bcm2835_defconfig running on a BCM2836/7
37 - * processor, hence the need for a runtime check. The dcache line size
38 - * is encoded in one of the coprocessor registers, but there is no
39 - * convenient way to access it short of embedded assembler, hence
40 - * the use of read_cpuid_id(). The following test evaluates to true
41 - * on a BCM2835 showing that it is ARMv6-ish, whereas
42 - * cpu_architecture() will indicate that it is an ARMv7.
43 - */
44 - g_cache_line_size = ((read_cpuid_id() & 0x7f000) == 0x7b000) ? 32 : 64;
45 + g_cache_line_size = drvdata->cache_line_size;
46 g_fragments_size = 2 * g_cache_line_size;
47
48 /* Allocate space for the channels in coherent memory */
49 --- a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c
50 +++ b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c
51 @@ -173,6 +173,14 @@ static struct platform_device *bcm2835_c
52 static struct platform_device *bcm2835_codec;
53 static struct platform_device *vcsm_cma;
54
55 +static struct vchiq_drvdata bcm2835_drvdata = {
56 + .cache_line_size = 32,
57 +};
58 +
59 +static struct vchiq_drvdata bcm2836_drvdata = {
60 + .cache_line_size = 64,
61 +};
62 +
63 static const char *const ioctl_names[] = {
64 "CONNECT",
65 "SHUTDOWN",
66 @@ -3607,12 +3615,25 @@ vchiq_register_child(struct platform_dev
67 return new_dev;
68 }
69
70 +static const struct of_device_id vchiq_of_match[] = {
71 + { .compatible = "brcm,bcm2835-vchiq", .data = &bcm2835_drvdata },
72 + { .compatible = "brcm,bcm2836-vchiq", .data = &bcm2836_drvdata },
73 + {},
74 +};
75 +MODULE_DEVICE_TABLE(of, vchiq_of_match);
76 +
77 static int vchiq_probe(struct platform_device *pdev)
78 {
79 struct device_node *fw_node;
80 - struct rpi_firmware *fw;
81 + const struct of_device_id *of_id;
82 + struct vchiq_drvdata *drvdata;
83 int err;
84
85 + of_id = of_match_node(vchiq_of_match, pdev->dev.of_node);
86 + drvdata = (struct vchiq_drvdata *)of_id->data;
87 + if (!drvdata)
88 + return -EINVAL;
89 +
90 fw_node = of_find_compatible_node(NULL, NULL,
91 "raspberrypi,bcm2835-firmware");
92 if (!fw_node) {
93 @@ -3620,12 +3641,12 @@ static int vchiq_probe(struct platform_d
94 return -ENOENT;
95 }
96
97 - fw = rpi_firmware_get(fw_node);
98 + drvdata->fw = rpi_firmware_get(fw_node);
99 of_node_put(fw_node);
100 - if (!fw)
101 + if (!drvdata->fw)
102 return -EPROBE_DEFER;
103
104 - platform_set_drvdata(pdev, fw);
105 + platform_set_drvdata(pdev, drvdata);
106
107 err = vchiq_platform_init(pdev, &g_state);
108 if (err != 0)
109 @@ -3703,12 +3724,6 @@ static int vchiq_remove(struct platform_
110 return 0;
111 }
112
113 -static const struct of_device_id vchiq_of_match[] = {
114 - { .compatible = "brcm,bcm2835-vchiq", },
115 - {},
116 -};
117 -MODULE_DEVICE_TABLE(of, vchiq_of_match);
118 -
119 static struct platform_driver vchiq_driver = {
120 .driver = {
121 .name = "bcm2835_vchiq",
122 --- a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.h
123 +++ b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.h
124 @@ -123,6 +123,11 @@ typedef struct vchiq_arm_state_struct {
125
126 } VCHIQ_ARM_STATE_T;
127
128 +struct vchiq_drvdata {
129 + const unsigned int cache_line_size;
130 + struct rpi_firmware *fw;
131 +};
132 +
133 extern int vchiq_arm_log_level;
134 extern int vchiq_susp_log_level;
135