Skip to content

Commit 6305166

Browse files
makarandpawagictmarinas
authored andcommitted
bus: fsl-mc: Add ACPI support for fsl-mc
Add ACPI support in the fsl-mc driver. Driver parses MC DSDT table to extract memory and other resources. Interrupt (GIC ITS) information is extracted from the MADT table by drivers/irqchip/irq-gic-v3-its-fsl-mc-msi.c. IORT table is parsed to configure DMA. Signed-off-by: Makarand Pawagi <[email protected]> Signed-off-by: Diana Craciun <[email protected]> Signed-off-by: Laurentiu Tudor <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Catalin Marinas <[email protected]>
1 parent 998fb7b commit 6305166

File tree

3 files changed

+150
-52
lines changed

3 files changed

+150
-52
lines changed

drivers/bus/fsl-mc/fsl-mc-bus.c

Lines changed: 55 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
#include <linux/bitops.h>
1919
#include <linux/msi.h>
2020
#include <linux/dma-mapping.h>
21+
#include <linux/acpi.h>
22+
#include <linux/iommu.h>
2123

2224
#include "fsl-mc-private.h"
2325

@@ -38,6 +40,7 @@ struct fsl_mc {
3840
struct fsl_mc_device *root_mc_bus_dev;
3941
u8 num_translation_ranges;
4042
struct fsl_mc_addr_translation_range *translation_ranges;
43+
void *fsl_mc_regs;
4144
};
4245

4346
/**
@@ -56,6 +59,10 @@ struct fsl_mc_addr_translation_range {
5659
phys_addr_t start_phys_addr;
5760
};
5861

62+
#define FSL_MC_FAPR 0x28
63+
#define MC_FAPR_PL BIT(18)
64+
#define MC_FAPR_BMT BIT(17)
65+
5966
/**
6067
* fsl_mc_bus_match - device to driver matching callback
6168
* @dev: the fsl-mc device to match against
@@ -124,7 +131,10 @@ static int fsl_mc_dma_configure(struct device *dev)
124131
while (dev_is_fsl_mc(dma_dev))
125132
dma_dev = dma_dev->parent;
126133

127-
return of_dma_configure_id(dev, dma_dev->of_node, 0, &input_id);
134+
if (dev_of_node(dma_dev))
135+
return of_dma_configure_id(dev, dma_dev->of_node, 0, &input_id);
136+
137+
return acpi_dma_configure_id(dev, DEV_DMA_COHERENT, &input_id);
128138
}
129139

130140
static ssize_t modalias_show(struct device *dev, struct device_attribute *attr,
@@ -865,28 +875,45 @@ static int fsl_mc_bus_probe(struct platform_device *pdev)
865875
struct fsl_mc_io *mc_io = NULL;
866876
int container_id;
867877
phys_addr_t mc_portal_phys_addr;
868-
u32 mc_portal_size;
869-
struct resource res;
878+
u32 mc_portal_size, mc_stream_id;
879+
struct resource *plat_res;
880+
881+
if (!iommu_present(&fsl_mc_bus_type))
882+
return -EPROBE_DEFER;
870883

871884
mc = devm_kzalloc(&pdev->dev, sizeof(*mc), GFP_KERNEL);
872885
if (!mc)
873886
return -ENOMEM;
874887

875888
platform_set_drvdata(pdev, mc);
876889

890+
plat_res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
891+
mc->fsl_mc_regs = devm_ioremap_resource(&pdev->dev, plat_res);
892+
if (IS_ERR(mc->fsl_mc_regs))
893+
return PTR_ERR(mc->fsl_mc_regs);
894+
895+
if (IS_ENABLED(CONFIG_ACPI) && !dev_of_node(&pdev->dev)) {
896+
mc_stream_id = readl(mc->fsl_mc_regs + FSL_MC_FAPR);
897+
/*
898+
* HW ORs the PL and BMT bit, places the result in bit 15 of
899+
* the StreamID and ORs in the ICID. Calculate it accordingly.
900+
*/
901+
mc_stream_id = (mc_stream_id & 0xffff) |
902+
((mc_stream_id & (MC_FAPR_PL | MC_FAPR_BMT)) ?
903+
0x4000 : 0);
904+
error = acpi_dma_configure_id(&pdev->dev, DEV_DMA_COHERENT,
905+
&mc_stream_id);
906+
if (error)
907+
dev_warn(&pdev->dev, "failed to configure dma: %d.\n",
908+
error);
909+
}
910+
877911
/*
878912
* Get physical address of MC portal for the root DPRC:
879913
*/
880-
error = of_address_to_resource(pdev->dev.of_node, 0, &res);
881-
if (error < 0) {
882-
dev_err(&pdev->dev,
883-
"of_address_to_resource() failed for %pOF\n",
884-
pdev->dev.of_node);
885-
return error;
886-
}
887-
888-
mc_portal_phys_addr = res.start;
889-
mc_portal_size = resource_size(&res);
914+
plat_res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
915+
mc_portal_phys_addr = plat_res->start;
916+
mc_portal_size = resource_size(plat_res);
890917
error = fsl_create_mc_io(&pdev->dev, mc_portal_phys_addr,
891918
mc_portal_size, NULL,
892919
FSL_MC_IO_ATOMIC_CONTEXT_PORTAL, &mc_io);
@@ -903,11 +930,13 @@ static int fsl_mc_bus_probe(struct platform_device *pdev)
903930
dev_info(&pdev->dev, "MC firmware version: %u.%u.%u\n",
904931
mc_version.major, mc_version.minor, mc_version.revision);
905932

906-
error = get_mc_addr_translation_ranges(&pdev->dev,
907-
&mc->translation_ranges,
908-
&mc->num_translation_ranges);
909-
if (error < 0)
910-
goto error_cleanup_mc_io;
933+
if (dev_of_node(&pdev->dev)) {
934+
error = get_mc_addr_translation_ranges(&pdev->dev,
935+
&mc->translation_ranges,
936+
&mc->num_translation_ranges);
937+
if (error < 0)
938+
goto error_cleanup_mc_io;
939+
}
911940

912941
error = dprc_get_container_id(mc_io, 0, &container_id);
913942
if (error < 0) {
@@ -934,6 +963,7 @@ static int fsl_mc_bus_probe(struct platform_device *pdev)
934963
goto error_cleanup_mc_io;
935964

936965
mc->root_mc_bus_dev = mc_bus_dev;
966+
mc_bus_dev->dev.fwnode = pdev->dev.fwnode;
937967
return 0;
938968

939969
error_cleanup_mc_io:
@@ -967,11 +997,18 @@ static const struct of_device_id fsl_mc_bus_match_table[] = {
967997

968998
MODULE_DEVICE_TABLE(of, fsl_mc_bus_match_table);
969999

1000+
static const struct acpi_device_id fsl_mc_bus_acpi_match_table[] = {
1001+
{"NXP0008", 0 },
1002+
{ }
1003+
};
1004+
MODULE_DEVICE_TABLE(acpi, fsl_mc_bus_acpi_match_table);
1005+
9701006
static struct platform_driver fsl_mc_bus_driver = {
9711007
.driver = {
9721008
.name = "fsl_mc_bus",
9731009
.pm = NULL,
9741010
.of_match_table = fsl_mc_bus_match_table,
1011+
.acpi_match_table = fsl_mc_bus_acpi_match_table,
9751012
},
9761013
.probe = fsl_mc_bus_probe,
9771014
.remove = fsl_mc_bus_remove,

drivers/bus/fsl-mc/fsl-mc-msi.c

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <linux/irq.h>
1414
#include <linux/irqdomain.h>
1515
#include <linux/msi.h>
16+
#include <linux/acpi_iort.h>
1617

1718
#include "fsl-mc-private.h"
1819

@@ -179,25 +180,31 @@ struct irq_domain *fsl_mc_msi_create_irq_domain(struct fwnode_handle *fwnode,
179180

180181
struct irq_domain *fsl_mc_find_msi_domain(struct device *dev)
181182
{
182-
struct irq_domain *msi_domain = NULL;
183+
struct device *root_dprc_dev;
184+
struct device *bus_dev;
185+
struct irq_domain *msi_domain;
183186
struct fsl_mc_device *mc_dev = to_fsl_mc_device(dev);
184187

185-
msi_domain = of_msi_map_get_device_domain(dev, mc_dev->icid,
188+
fsl_mc_get_root_dprc(dev, &root_dprc_dev);
189+
bus_dev = root_dprc_dev->parent;
190+
191+
if (bus_dev->of_node) {
192+
msi_domain = of_msi_map_get_device_domain(dev,
193+
mc_dev->icid,
186194
DOMAIN_BUS_FSL_MC_MSI);
187195

188-
/*
189-
* if the msi-map property is missing assume that all the
190-
* child containers inherit the domain from the parent
191-
*/
192-
if (!msi_domain) {
193-
struct device *root_dprc_dev;
194-
struct device *bus_dev;
195-
196-
fsl_mc_get_root_dprc(dev, &root_dprc_dev);
197-
bus_dev = root_dprc_dev->parent;
198-
msi_domain = of_msi_get_domain(bus_dev,
199-
bus_dev->of_node,
200-
DOMAIN_BUS_FSL_MC_MSI);
196+
/*
197+
* if the msi-map property is missing assume that all the
198+
* child containers inherit the domain from the parent
199+
*/
200+
if (!msi_domain)
201+
202+
msi_domain = of_msi_get_domain(bus_dev,
203+
bus_dev->of_node,
204+
DOMAIN_BUS_FSL_MC_MSI);
205+
} else {
206+
msi_domain = iort_get_device_domain(dev, mc_dev->icid,
207+
DOMAIN_BUS_FSL_MC_MSI);
201208
}
202209

203210
return msi_domain;

drivers/irqchip/irq-gic-v3-its-fsl-mc-msi.c

Lines changed: 73 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
*
88
*/
99

10+
#include <linux/acpi.h>
11+
#include <linux/acpi_iort.h>
1012
#include <linux/of_device.h>
1113
#include <linux/of_address.h>
1214
#include <linux/irq.h>
@@ -30,7 +32,8 @@ static u32 fsl_mc_msi_domain_get_msi_id(struct irq_domain *domain,
3032
u32 out_id;
3133

3234
of_node = irq_domain_get_of_node(domain);
33-
out_id = of_msi_map_id(&mc_dev->dev, of_node, mc_dev->icid);
35+
out_id = of_node ? of_msi_map_id(&mc_dev->dev, of_node, mc_dev->icid) :
36+
iort_msi_map_id(&mc_dev->dev, mc_dev->icid);
3437

3538
return out_id;
3639
}
@@ -79,36 +82,87 @@ static const struct of_device_id its_device_id[] = {
7982
{},
8083
};
8184

82-
static int __init its_fsl_mc_msi_init(void)
85+
static void __init its_fsl_mc_msi_init_one(struct fwnode_handle *handle,
86+
const char *name)
8387
{
84-
struct device_node *np;
8588
struct irq_domain *parent;
8689
struct irq_domain *mc_msi_domain;
8790

91+
parent = irq_find_matching_fwnode(handle, DOMAIN_BUS_NEXUS);
92+
if (!parent || !msi_get_domain_info(parent)) {
93+
pr_err("%s: unable to locate ITS domain\n", name);
94+
return;
95+
}
96+
97+
mc_msi_domain = fsl_mc_msi_create_irq_domain(handle,
98+
&its_fsl_mc_msi_domain_info,
99+
parent);
100+
if (!mc_msi_domain) {
101+
pr_err("%s: unable to create fsl-mc domain\n", name);
102+
return;
103+
}
104+
105+
pr_info("fsl-mc MSI: %s domain created\n", name);
106+
}
107+
108+
#ifdef CONFIG_ACPI
109+
static int __init
110+
its_fsl_mc_msi_parse_madt(union acpi_subtable_headers *header,
111+
const unsigned long end)
112+
{
113+
struct acpi_madt_generic_translator *its_entry;
114+
struct fwnode_handle *dom_handle;
115+
const char *node_name;
116+
int err = 0;
117+
118+
its_entry = (struct acpi_madt_generic_translator *)header;
119+
node_name = kasprintf(GFP_KERNEL, "ITS@0x%lx",
120+
(long)its_entry->base_address);
121+
122+
dom_handle = iort_find_domain_token(its_entry->translation_id);
123+
if (!dom_handle) {
124+
pr_err("%s: Unable to locate ITS domain handle\n", node_name);
125+
err = -ENXIO;
126+
goto out;
127+
}
128+
129+
its_fsl_mc_msi_init_one(dom_handle, node_name);
130+
131+
out:
132+
kfree(node_name);
133+
return err;
134+
}
135+
136+
137+
static void __init its_fsl_mc_acpi_msi_init(void)
138+
{
139+
acpi_table_parse_madt(ACPI_MADT_TYPE_GENERIC_TRANSLATOR,
140+
its_fsl_mc_msi_parse_madt, 0);
141+
}
142+
#else
143+
static inline void its_fsl_mc_acpi_msi_init(void) { }
144+
#endif
145+
146+
static void __init its_fsl_mc_of_msi_init(void)
147+
{
148+
struct device_node *np;
149+
88150
for (np = of_find_matching_node(NULL, its_device_id); np;
89151
np = of_find_matching_node(np, its_device_id)) {
90152
if (!of_device_is_available(np))
91153
continue;
92154
if (!of_property_read_bool(np, "msi-controller"))
93155
continue;
94156

95-
parent = irq_find_matching_host(np, DOMAIN_BUS_NEXUS);
96-
if (!parent || !msi_get_domain_info(parent)) {
97-
pr_err("%pOF: unable to locate ITS domain\n", np);
98-
continue;
99-
}
100-
101-
mc_msi_domain = fsl_mc_msi_create_irq_domain(
102-
of_node_to_fwnode(np),
103-
&its_fsl_mc_msi_domain_info,
104-
parent);
105-
if (!mc_msi_domain) {
106-
pr_err("%pOF: unable to create fsl-mc domain\n", np);
107-
continue;
108-
}
109-
110-
pr_info("fsl-mc MSI: %pOF domain created\n", np);
157+
its_fsl_mc_msi_init_one(of_node_to_fwnode(np),
158+
np->full_name);
111159
}
160+
}
161+
162+
static int __init its_fsl_mc_msi_init(void)
163+
{
164+
its_fsl_mc_of_msi_init();
165+
its_fsl_mc_acpi_msi_init();
112166

113167
return 0;
114168
}

0 commit comments

Comments
 (0)