Commit cd70d465 authored by Emil Medve's avatar Emil Medve Committed by Joerg Roedel

iommu/fsl: Various cleanups

Currently a PAMU driver patch is very likely to receive some
checkpatch complaints about the code in the context of the
patch. This patch is an attempt to fix most of that and make
the driver more readable

Also fixed a subset of the sparse and coccinelle reported
issues.
Signed-off-by: default avatarEmil Medve <Emilian.Medve@Freescale.com>
Signed-off-by: default avatarJoerg Roedel <jroedel@suse.de>
parent 8cd4f751
...@@ -18,22 +18,13 @@ ...@@ -18,22 +18,13 @@
#define pr_fmt(fmt) "fsl-pamu: %s: " fmt, __func__ #define pr_fmt(fmt) "fsl-pamu: %s: " fmt, __func__
#include <linux/init.h> #include "fsl_pamu.h"
#include <linux/iommu.h>
#include <linux/slab.h>
#include <linux/module.h>
#include <linux/types.h>
#include <linux/mm.h>
#include <linux/interrupt.h> #include <linux/interrupt.h>
#include <linux/device.h>
#include <linux/of_platform.h>
#include <linux/bootmem.h>
#include <linux/genalloc.h> #include <linux/genalloc.h>
#include <asm/io.h>
#include <asm/bitops.h>
#include <asm/fsl_guts.h>
#include "fsl_pamu.h" #include <asm/mpc85xx.h>
#include <asm/fsl_guts.h>
/* define indexes for each operation mapping scenario */ /* define indexes for each operation mapping scenario */
#define OMI_QMAN 0x00 #define OMI_QMAN 0x00
...@@ -44,13 +35,13 @@ ...@@ -44,13 +35,13 @@
#define make64(high, low) (((u64)(high) << 32) | (low)) #define make64(high, low) (((u64)(high) << 32) | (low))
struct pamu_isr_data { struct pamu_isr_data {
void __iomem *pamu_reg_base; /* Base address of PAMU regs*/ void __iomem *pamu_reg_base; /* Base address of PAMU regs */
unsigned int count; /* The number of PAMUs */ unsigned int count; /* The number of PAMUs */
}; };
static struct paace *ppaact; static struct paace *ppaact;
static struct paace *spaact; static struct paace *spaact;
static struct ome *omt; static struct ome *omt __initdata;
/* /*
* Table for matching compatible strings, for device tree * Table for matching compatible strings, for device tree
...@@ -58,14 +49,13 @@ static struct ome *omt; ...@@ -58,14 +49,13 @@ static struct ome *omt;
* "fsl,qoriq-device-config-2.0" corresponds to T4 & B4 * "fsl,qoriq-device-config-2.0" corresponds to T4 & B4
* SOCs. For the older SOCs "fsl,qoriq-device-config-1.0" * SOCs. For the older SOCs "fsl,qoriq-device-config-1.0"
* string would be used. * string would be used.
*/ */
static const struct of_device_id guts_device_ids[] = { static const struct of_device_id guts_device_ids[] __initconst = {
{ .compatible = "fsl,qoriq-device-config-1.0", }, { .compatible = "fsl,qoriq-device-config-1.0", },
{ .compatible = "fsl,qoriq-device-config-2.0", }, { .compatible = "fsl,qoriq-device-config-2.0", },
{} {}
}; };
/* /*
* Table for matching compatible strings, for device tree * Table for matching compatible strings, for device tree
* L3 cache controller node. * L3 cache controller node.
...@@ -73,7 +63,7 @@ static const struct of_device_id guts_device_ids[] = { ...@@ -73,7 +63,7 @@ static const struct of_device_id guts_device_ids[] = {
* "fsl,b4860-l3-cache-controller" corresponds to B4 & * "fsl,b4860-l3-cache-controller" corresponds to B4 &
* "fsl,p4080-l3-cache-controller" corresponds to other, * "fsl,p4080-l3-cache-controller" corresponds to other,
* SOCs. * SOCs.
*/ */
static const struct of_device_id l3_device_ids[] = { static const struct of_device_id l3_device_ids[] = {
{ .compatible = "fsl,t4240-l3-cache-controller", }, { .compatible = "fsl,t4240-l3-cache-controller", },
{ .compatible = "fsl,b4860-l3-cache-controller", }, { .compatible = "fsl,b4860-l3-cache-controller", },
...@@ -85,7 +75,7 @@ static const struct of_device_id l3_device_ids[] = { ...@@ -85,7 +75,7 @@ static const struct of_device_id l3_device_ids[] = {
static u32 max_subwindow_count; static u32 max_subwindow_count;
/* Pool for fspi allocation */ /* Pool for fspi allocation */
struct gen_pool *spaace_pool; static struct gen_pool *spaace_pool;
/** /**
* pamu_get_max_subwin_cnt() - Return the maximum supported * pamu_get_max_subwin_cnt() - Return the maximum supported
...@@ -170,7 +160,7 @@ int pamu_disable_liodn(int liodn) ...@@ -170,7 +160,7 @@ int pamu_disable_liodn(int liodn)
static unsigned int map_addrspace_size_to_wse(phys_addr_t addrspace_size) static unsigned int map_addrspace_size_to_wse(phys_addr_t addrspace_size)
{ {
/* Bug if not a power of 2 */ /* Bug if not a power of 2 */
BUG_ON((addrspace_size & (addrspace_size - 1))); BUG_ON(addrspace_size & (addrspace_size - 1));
/* window size is 2^(WSE+1) bytes */ /* window size is 2^(WSE+1) bytes */
return fls64(addrspace_size) - 2; return fls64(addrspace_size) - 2;
...@@ -241,7 +231,7 @@ static struct paace *pamu_get_spaace(struct paace *paace, u32 wnum) ...@@ -241,7 +231,7 @@ static struct paace *pamu_get_spaace(struct paace *paace, u32 wnum)
* If no SPAACE entry is available or the allocator can not reserve the required * If no SPAACE entry is available or the allocator can not reserve the required
* number of contiguous entries function returns ULONG_MAX indicating a failure. * number of contiguous entries function returns ULONG_MAX indicating a failure.
* *
*/ */
static unsigned long pamu_get_fspi_and_allocate(u32 subwin_cnt) static unsigned long pamu_get_fspi_and_allocate(u32 subwin_cnt)
{ {
unsigned long spaace_addr; unsigned long spaace_addr;
...@@ -288,10 +278,9 @@ int pamu_update_paace_stash(int liodn, u32 subwin, u32 value) ...@@ -288,10 +278,9 @@ int pamu_update_paace_stash(int liodn, u32 subwin, u32 value)
} }
if (subwin) { if (subwin) {
paace = pamu_get_spaace(paace, subwin - 1); paace = pamu_get_spaace(paace, subwin - 1);
if (!paace) { if (!paace)
return -ENOENT; return -ENOENT;
} }
}
set_bf(paace->impl_attr, PAACE_IA_CID, value); set_bf(paace->impl_attr, PAACE_IA_CID, value);
mb(); mb();
...@@ -311,11 +300,9 @@ int pamu_disable_spaace(int liodn, u32 subwin) ...@@ -311,11 +300,9 @@ int pamu_disable_spaace(int liodn, u32 subwin)
} }
if (subwin) { if (subwin) {
paace = pamu_get_spaace(paace, subwin - 1); paace = pamu_get_spaace(paace, subwin - 1);
if (!paace) { if (!paace)
return -ENOENT; return -ENOENT;
} set_bf(paace->addr_bitfields, PAACE_AF_V, PAACE_V_INVALID);
set_bf(paace->addr_bitfields, PAACE_AF_V,
PAACE_V_INVALID);
} else { } else {
set_bf(paace->addr_bitfields, PAACE_AF_AP, set_bf(paace->addr_bitfields, PAACE_AF_AP,
PAACE_AP_PERMS_DENIED); PAACE_AP_PERMS_DENIED);
...@@ -326,7 +313,6 @@ int pamu_disable_spaace(int liodn, u32 subwin) ...@@ -326,7 +313,6 @@ int pamu_disable_spaace(int liodn, u32 subwin)
return 0; return 0;
} }
/** /**
* pamu_config_paace() - Sets up PPAACE entry for specified liodn * pamu_config_paace() - Sets up PPAACE entry for specified liodn
* *
...@@ -352,7 +338,8 @@ int pamu_config_ppaace(int liodn, phys_addr_t win_addr, phys_addr_t win_size, ...@@ -352,7 +338,8 @@ int pamu_config_ppaace(int liodn, phys_addr_t win_addr, phys_addr_t win_size,
unsigned long fspi; unsigned long fspi;
if ((win_size & (win_size - 1)) || win_size < PAMU_PAGE_SIZE) { if ((win_size & (win_size - 1)) || win_size < PAMU_PAGE_SIZE) {
pr_debug("window size too small or not a power of two %pa\n", &win_size); pr_debug("window size too small or not a power of two %pa\n",
&win_size);
return -EINVAL; return -EINVAL;
} }
...@@ -362,9 +349,8 @@ int pamu_config_ppaace(int liodn, phys_addr_t win_addr, phys_addr_t win_size, ...@@ -362,9 +349,8 @@ int pamu_config_ppaace(int liodn, phys_addr_t win_addr, phys_addr_t win_size,
} }
ppaace = pamu_get_ppaace(liodn); ppaace = pamu_get_ppaace(liodn);
if (!ppaace) { if (!ppaace)
return -ENOENT; return -ENOENT;
}
/* window size is 2^(WSE+1) bytes */ /* window size is 2^(WSE+1) bytes */
set_bf(ppaace->addr_bitfields, PPAACE_AF_WSE, set_bf(ppaace->addr_bitfields, PPAACE_AF_WSE,
...@@ -442,7 +428,6 @@ int pamu_config_spaace(int liodn, u32 subwin_cnt, u32 subwin, ...@@ -442,7 +428,6 @@ int pamu_config_spaace(int liodn, u32 subwin_cnt, u32 subwin,
{ {
struct paace *paace; struct paace *paace;
/* setup sub-windows */ /* setup sub-windows */
if (!subwin_cnt) { if (!subwin_cnt) {
pr_debug("Invalid subwindow count\n"); pr_debug("Invalid subwindow count\n");
...@@ -510,11 +495,11 @@ int pamu_config_spaace(int liodn, u32 subwin_cnt, u32 subwin, ...@@ -510,11 +495,11 @@ int pamu_config_spaace(int liodn, u32 subwin_cnt, u32 subwin,
} }
/** /**
* get_ome_index() - Returns the index in the operation mapping table * get_ome_index() - Returns the index in the operation mapping table
* for device. * for device.
* @*omi_index: pointer for storing the index value * @*omi_index: pointer for storing the index value
* *
*/ */
void get_ome_index(u32 *omi_index, struct device *dev) void get_ome_index(u32 *omi_index, struct device *dev)
{ {
if (of_device_is_compatible(dev->of_node, "fsl,qman-portal")) if (of_device_is_compatible(dev->of_node, "fsl,qman-portal"))
...@@ -544,9 +529,10 @@ u32 get_stash_id(u32 stash_dest_hint, u32 vcpu) ...@@ -544,9 +529,10 @@ u32 get_stash_id(u32 stash_dest_hint, u32 vcpu)
if (stash_dest_hint == PAMU_ATTR_CACHE_L3) { if (stash_dest_hint == PAMU_ATTR_CACHE_L3) {
node = of_find_matching_node(NULL, l3_device_ids); node = of_find_matching_node(NULL, l3_device_ids);
if (node) { if (node) {
prop = of_get_property(node, "cache-stash-id", 0); prop = of_get_property(node, "cache-stash-id", NULL);
if (!prop) { if (!prop) {
pr_debug("missing cache-stash-id at %s\n", node->full_name); pr_debug("missing cache-stash-id at %s\n",
node->full_name);
of_node_put(node); of_node_put(node);
return ~(u32)0; return ~(u32)0;
} }
...@@ -570,9 +556,10 @@ u32 get_stash_id(u32 stash_dest_hint, u32 vcpu) ...@@ -570,9 +556,10 @@ u32 get_stash_id(u32 stash_dest_hint, u32 vcpu)
/* find the hwnode that represents the cache */ /* find the hwnode that represents the cache */
for (cache_level = PAMU_ATTR_CACHE_L1; (cache_level < PAMU_ATTR_CACHE_L3) && found; cache_level++) { for (cache_level = PAMU_ATTR_CACHE_L1; (cache_level < PAMU_ATTR_CACHE_L3) && found; cache_level++) {
if (stash_dest_hint == cache_level) { if (stash_dest_hint == cache_level) {
prop = of_get_property(node, "cache-stash-id", 0); prop = of_get_property(node, "cache-stash-id", NULL);
if (!prop) { if (!prop) {
pr_debug("missing cache-stash-id at %s\n", node->full_name); pr_debug("missing cache-stash-id at %s\n",
node->full_name);
of_node_put(node); of_node_put(node);
return ~(u32)0; return ~(u32)0;
} }
...@@ -580,7 +567,7 @@ u32 get_stash_id(u32 stash_dest_hint, u32 vcpu) ...@@ -580,7 +567,7 @@ u32 get_stash_id(u32 stash_dest_hint, u32 vcpu)
return be32_to_cpup(prop); return be32_to_cpup(prop);
} }
prop = of_get_property(node, "next-level-cache", 0); prop = of_get_property(node, "next-level-cache", NULL);
if (!prop) { if (!prop) {
pr_debug("can't find next-level-cache at %s\n", pr_debug("can't find next-level-cache at %s\n",
node->full_name); node->full_name);
...@@ -612,7 +599,7 @@ u32 get_stash_id(u32 stash_dest_hint, u32 vcpu) ...@@ -612,7 +599,7 @@ u32 get_stash_id(u32 stash_dest_hint, u32 vcpu)
* Memory accesses to QMAN and BMAN private memory need not be coherent, so * Memory accesses to QMAN and BMAN private memory need not be coherent, so
* clear the PAACE entry coherency attribute for them. * clear the PAACE entry coherency attribute for them.
*/ */
static void setup_qbman_paace(struct paace *ppaace, int paace_type) static void __init setup_qbman_paace(struct paace *ppaace, int paace_type)
{ {
switch (paace_type) { switch (paace_type) {
case QMAN_PAACE: case QMAN_PAACE:
...@@ -626,7 +613,7 @@ static void setup_qbman_paace(struct paace *ppaace, int paace_type) ...@@ -626,7 +613,7 @@ static void setup_qbman_paace(struct paace *ppaace, int paace_type)
case QMAN_PORTAL_PAACE: case QMAN_PORTAL_PAACE:
set_bf(ppaace->impl_attr, PAACE_IA_OTM, PAACE_OTM_INDEXED); set_bf(ppaace->impl_attr, PAACE_IA_OTM, PAACE_OTM_INDEXED);
ppaace->op_encode.index_ot.omi = OMI_QMAN; ppaace->op_encode.index_ot.omi = OMI_QMAN;
/*Set DQRR and Frame stashing for the L3 cache */ /* Set DQRR and Frame stashing for the L3 cache */
set_bf(ppaace->impl_attr, PAACE_IA_CID, get_stash_id(PAMU_ATTR_CACHE_L3, 0)); set_bf(ppaace->impl_attr, PAACE_IA_CID, get_stash_id(PAMU_ATTR_CACHE_L3, 0));
break; break;
case BMAN_PAACE: case BMAN_PAACE:
...@@ -679,7 +666,7 @@ static void __init setup_omt(struct ome *omt) ...@@ -679,7 +666,7 @@ static void __init setup_omt(struct ome *omt)
* Get the maximum number of PAACT table entries * Get the maximum number of PAACT table entries
* and subwindows supported by PAMU * and subwindows supported by PAMU
*/ */
static void get_pamu_cap_values(unsigned long pamu_reg_base) static void __init get_pamu_cap_values(unsigned long pamu_reg_base)
{ {
u32 pc_val; u32 pc_val;
...@@ -689,7 +676,7 @@ static void get_pamu_cap_values(unsigned long pamu_reg_base) ...@@ -689,7 +676,7 @@ static void get_pamu_cap_values(unsigned long pamu_reg_base)
} }
/* Setup PAMU registers pointing to PAACT, SPAACT and OMT */ /* Setup PAMU registers pointing to PAACT, SPAACT and OMT */
int setup_one_pamu(unsigned long pamu_reg_base, unsigned long pamu_reg_size, static int __init setup_one_pamu(unsigned long pamu_reg_base, unsigned long pamu_reg_size,
phys_addr_t ppaact_phys, phys_addr_t spaact_phys, phys_addr_t ppaact_phys, phys_addr_t spaact_phys,
phys_addr_t omt_phys) phys_addr_t omt_phys)
{ {
...@@ -772,7 +759,7 @@ static void __init setup_liodns(void) ...@@ -772,7 +759,7 @@ static void __init setup_liodns(void)
} }
} }
irqreturn_t pamu_av_isr(int irq, void *arg) static irqreturn_t pamu_av_isr(int irq, void *arg)
{ {
struct pamu_isr_data *data = arg; struct pamu_isr_data *data = arg;
phys_addr_t phys; phys_addr_t phys;
...@@ -792,10 +779,12 @@ irqreturn_t pamu_av_isr(int irq, void *arg) ...@@ -792,10 +779,12 @@ irqreturn_t pamu_av_isr(int irq, void *arg)
pr_emerg("POES2=%08x\n", in_be32(p + PAMU_POES2)); pr_emerg("POES2=%08x\n", in_be32(p + PAMU_POES2));
pr_emerg("AVS1=%08x\n", avs1); pr_emerg("AVS1=%08x\n", avs1);
pr_emerg("AVS2=%08x\n", in_be32(p + PAMU_AVS2)); pr_emerg("AVS2=%08x\n", in_be32(p + PAMU_AVS2));
pr_emerg("AVA=%016llx\n", make64(in_be32(p + PAMU_AVAH), pr_emerg("AVA=%016llx\n",
make64(in_be32(p + PAMU_AVAH),
in_be32(p + PAMU_AVAL))); in_be32(p + PAMU_AVAL)));
pr_emerg("UDAD=%08x\n", in_be32(p + PAMU_UDAD)); pr_emerg("UDAD=%08x\n", in_be32(p + PAMU_UDAD));
pr_emerg("POEA=%016llx\n", make64(in_be32(p + PAMU_POEAH), pr_emerg("POEA=%016llx\n",
make64(in_be32(p + PAMU_POEAH),
in_be32(p + PAMU_POEAL))); in_be32(p + PAMU_POEAL)));
phys = make64(in_be32(p + PAMU_POEAH), phys = make64(in_be32(p + PAMU_POEAH),
...@@ -807,11 +796,12 @@ irqreturn_t pamu_av_isr(int irq, void *arg) ...@@ -807,11 +796,12 @@ irqreturn_t pamu_av_isr(int irq, void *arg)
/* Only the first four words are relevant */ /* Only the first four words are relevant */
for (j = 0; j < 4; j++) for (j = 0; j < 4; j++)
pr_emerg("PAACE[%u]=%08x\n", j, in_be32(paace + j)); pr_emerg("PAACE[%u]=%08x\n",
j, in_be32(paace + j));
} }
/* clear access violation condition */ /* clear access violation condition */
out_be32((p + PAMU_AVS1), avs1 & PAMU_AV_MASK); out_be32(p + PAMU_AVS1, avs1 & PAMU_AV_MASK);
paace = pamu_get_ppaace(avs1 >> PAMU_AVS1_LIODN_SHIFT); paace = pamu_get_ppaace(avs1 >> PAMU_AVS1_LIODN_SHIFT);
BUG_ON(!paace); BUG_ON(!paace);
/* check if we got a violation for a disabled LIODN */ /* check if we got a violation for a disabled LIODN */
...@@ -827,13 +817,13 @@ irqreturn_t pamu_av_isr(int irq, void *arg) ...@@ -827,13 +817,13 @@ irqreturn_t pamu_av_isr(int irq, void *arg)
/* Disable the LIODN */ /* Disable the LIODN */
ret = pamu_disable_liodn(avs1 >> PAMU_AVS1_LIODN_SHIFT); ret = pamu_disable_liodn(avs1 >> PAMU_AVS1_LIODN_SHIFT);
BUG_ON(ret); BUG_ON(ret);
pr_emerg("Disabling liodn %x\n", avs1 >> PAMU_AVS1_LIODN_SHIFT); pr_emerg("Disabling liodn %x\n",
avs1 >> PAMU_AVS1_LIODN_SHIFT);
} }
out_be32((p + PAMU_PICS), pics); out_be32((p + PAMU_PICS), pics);
} }
} }
return IRQ_HANDLED; return IRQ_HANDLED;
} }
...@@ -952,7 +942,7 @@ static int __init create_csd(phys_addr_t phys, size_t size, u32 csd_port_id) ...@@ -952,7 +942,7 @@ static int __init create_csd(phys_addr_t phys, size_t size, u32 csd_port_id)
} }
if (i == 0 || i == num_laws) { if (i == 0 || i == num_laws) {
/* This should never happen*/ /* This should never happen */
ret = -ENOENT; ret = -ENOENT;
goto error; goto error;
} }
...@@ -998,26 +988,27 @@ static int __init create_csd(phys_addr_t phys, size_t size, u32 csd_port_id) ...@@ -998,26 +988,27 @@ static int __init create_csd(phys_addr_t phys, size_t size, u32 csd_port_id)
static const struct { static const struct {
u32 svr; u32 svr;
u32 port_id; u32 port_id;
} port_id_map[] = { } port_id_map[] __initconst = {
{0x82100010, 0xFF000000}, /* P2040 1.0 */ {(SVR_P2040 << 8) | 0x10, 0xFF000000}, /* P2040 1.0 */
{0x82100011, 0xFF000000}, /* P2040 1.1 */ {(SVR_P2040 << 8) | 0x11, 0xFF000000}, /* P2040 1.1 */
{0x82100110, 0xFF000000}, /* P2041 1.0 */ {(SVR_P2041 << 8) | 0x10, 0xFF000000}, /* P2041 1.0 */
{0x82100111, 0xFF000000}, /* P2041 1.1 */ {(SVR_P2041 << 8) | 0x11, 0xFF000000}, /* P2041 1.1 */
{0x82110310, 0xFF000000}, /* P3041 1.0 */ {(SVR_P3041 << 8) | 0x10, 0xFF000000}, /* P3041 1.0 */
{0x82110311, 0xFF000000}, /* P3041 1.1 */ {(SVR_P3041 << 8) | 0x11, 0xFF000000}, /* P3041 1.1 */
{0x82010020, 0xFFF80000}, /* P4040 2.0 */ {(SVR_P4040 << 8) | 0x20, 0xFFF80000}, /* P4040 2.0 */
{0x82000020, 0xFFF80000}, /* P4080 2.0 */ {(SVR_P4080 << 8) | 0x20, 0xFFF80000}, /* P4080 2.0 */
{0x82210010, 0xFC000000}, /* P5010 1.0 */ {(SVR_P5010 << 8) | 0x10, 0xFC000000}, /* P5010 1.0 */
{0x82210020, 0xFC000000}, /* P5010 2.0 */ {(SVR_P5010 << 8) | 0x20, 0xFC000000}, /* P5010 2.0 */
{0x82200010, 0xFC000000}, /* P5020 1.0 */ {(SVR_P5020 << 8) | 0x10, 0xFC000000}, /* P5020 1.0 */
{0x82050010, 0xFF800000}, /* P5021 1.0 */ {(SVR_P5021 << 8) | 0x10, 0xFF800000}, /* P5021 1.0 */
{0x82040010, 0xFF800000}, /* P5040 1.0 */ {(SVR_P5040 << 8) | 0x10, 0xFF800000}, /* P5040 1.0 */
}; };
#define SVR_SECURITY 0x80000 /* The Security (E) bit */ #define SVR_SECURITY 0x80000 /* The Security (E) bit */
static int __init fsl_pamu_probe(struct platform_device *pdev) static int __init fsl_pamu_probe(struct platform_device *pdev)
{ {
struct device *dev = &pdev->dev;
void __iomem *pamu_regs = NULL; void __iomem *pamu_regs = NULL;
struct ccsr_guts __iomem *guts_regs = NULL; struct ccsr_guts __iomem *guts_regs = NULL;
u32 pamubypenr, pamu_counter; u32 pamubypenr, pamu_counter;
...@@ -1042,22 +1033,21 @@ static int __init fsl_pamu_probe(struct platform_device *pdev) ...@@ -1042,22 +1033,21 @@ static int __init fsl_pamu_probe(struct platform_device *pdev)
* NOTE : All PAMUs share the same LIODN tables. * NOTE : All PAMUs share the same LIODN tables.
*/ */
pamu_regs = of_iomap(pdev->dev.of_node, 0); pamu_regs = of_iomap(dev->of_node, 0);
if (!pamu_regs) { if (!pamu_regs) {
dev_err(&pdev->dev, "ioremap of PAMU node failed\n"); dev_err(dev, "ioremap of PAMU node failed\n");
return -ENOMEM; return -ENOMEM;
} }
of_get_address(pdev->dev.of_node, 0, &size, NULL); of_get_address(dev->of_node, 0, &size, NULL);
irq = irq_of_parse_and_map(pdev->dev.of_node, 0); irq = irq_of_parse_and_map(dev->of_node, 0);
if (irq == NO_IRQ) { if (irq == NO_IRQ) {
dev_warn(&pdev->dev, "no interrupts listed in PAMU node\n"); dev_warn(dev, "no interrupts listed in PAMU node\n");
goto error; goto error;
} }
data = kzalloc(sizeof(struct pamu_isr_data), GFP_KERNEL); data = kzalloc(sizeof(*data), GFP_KERNEL);
if (!data) { if (!data) {
dev_err(&pdev->dev, "PAMU isr data memory allocation failed\n");
ret = -ENOMEM; ret = -ENOMEM;
goto error; goto error;
} }
...@@ -1067,15 +1057,14 @@ static int __init fsl_pamu_probe(struct platform_device *pdev) ...@@ -1067,15 +1057,14 @@ static int __init fsl_pamu_probe(struct platform_device *pdev)
/* The ISR needs access to the regs, so we won't iounmap them */ /* The ISR needs access to the regs, so we won't iounmap them */
ret = request_irq(irq, pamu_av_isr, 0, "pamu", data); ret = request_irq(irq, pamu_av_isr, 0, "pamu", data);
if (ret < 0) { if (ret < 0) {
dev_err(&pdev->dev, "error %i installing ISR for irq %i\n", dev_err(dev, "error %i installing ISR for irq %i\n", ret, irq);
ret, irq);
goto error; goto error;
} }
guts_node = of_find_matching_node(NULL, guts_device_ids); guts_node = of_find_matching_node(NULL, guts_device_ids);
if (!guts_node) { if (!guts_node) {
dev_err(&pdev->dev, "could not find GUTS node %s\n", dev_err(dev, "could not find GUTS node %s\n",
pdev->dev.of_node->full_name); dev->of_node->full_name);
ret = -ENODEV; ret = -ENODEV;
goto error; goto error;
} }
...@@ -1083,7 +1072,7 @@ static int __init fsl_pamu_probe(struct platform_device *pdev) ...@@ -1083,7 +1072,7 @@ static int __init fsl_pamu_probe(struct platform_device *pdev)
guts_regs = of_iomap(guts_node, 0); guts_regs = of_iomap(guts_node, 0);
of_node_put(guts_node); of_node_put(guts_node);
if (!guts_regs) { if (!guts_regs) {
dev_err(&pdev->dev, "ioremap of GUTS node failed\n"); dev_err(dev, "ioremap of GUTS node failed\n");
ret = -ENODEV; ret = -ENODEV;
goto error; goto error;
} }
...@@ -1103,7 +1092,7 @@ static int __init fsl_pamu_probe(struct platform_device *pdev) ...@@ -1103,7 +1092,7 @@ static int __init fsl_pamu_probe(struct platform_device *pdev)
p = alloc_pages(GFP_KERNEL | __GFP_ZERO, order); p = alloc_pages(GFP_KERNEL | __GFP_ZERO, order);
if (!p) { if (!p) {
dev_err(&pdev->dev, "unable to allocate PAACT/SPAACT/OMT block\n"); dev_err(dev, "unable to allocate PAACT/SPAACT/OMT block\n");
ret = -ENOMEM; ret = -ENOMEM;
goto error; goto error;
} }
...@@ -1113,7 +1102,7 @@ static int __init fsl_pamu_probe(struct platform_device *pdev) ...@@ -1113,7 +1102,7 @@ static int __init fsl_pamu_probe(struct platform_device *pdev)
/* Make sure the memory is naturally aligned */ /* Make sure the memory is naturally aligned */
if (ppaact_phys & ((PAGE_SIZE << order) - 1)) { if (ppaact_phys & ((PAGE_SIZE << order) - 1)) {
dev_err(&pdev->dev, "PAACT/OMT block is unaligned\n"); dev_err(dev, "PAACT/OMT block is unaligned\n");
ret = -ENOMEM; ret = -ENOMEM;
goto error; goto error;
} }
...@@ -1121,7 +1110,7 @@ static int __init fsl_pamu_probe(struct platform_device *pdev) ...@@ -1121,7 +1110,7 @@ static int __init fsl_pamu_probe(struct platform_device *pdev)
spaact = (void *)ppaact + (PAGE_SIZE << get_order(PAACT_SIZE)); spaact = (void *)ppaact + (PAGE_SIZE << get_order(PAACT_SIZE));
omt = (void *)spaact + (PAGE_SIZE << get_order(SPAACT_SIZE)); omt = (void *)spaact + (PAGE_SIZE << get_order(SPAACT_SIZE));
dev_dbg(&pdev->dev, "ppaact virt=%p phys=%pa\n", ppaact, &ppaact_phys); dev_dbg(dev, "ppaact virt=%p phys=%pa\n", ppaact, &ppaact_phys);
/* Check to see if we need to implement the work-around on this SOC */ /* Check to see if we need to implement the work-around on this SOC */
...@@ -1129,21 +1118,19 @@ static int __init fsl_pamu_probe(struct platform_device *pdev) ...@@ -1129,21 +1118,19 @@ static int __init fsl_pamu_probe(struct platform_device *pdev)
for (i = 0; i < ARRAY_SIZE(port_id_map); i++) { for (i = 0; i < ARRAY_SIZE(port_id_map); i++) {
if (port_id_map[i].svr == (mfspr(SPRN_SVR) & ~SVR_SECURITY)) { if (port_id_map[i].svr == (mfspr(SPRN_SVR) & ~SVR_SECURITY)) {
csd_port_id = port_id_map[i].port_id; csd_port_id = port_id_map[i].port_id;
dev_dbg(&pdev->dev, "found matching SVR %08x\n", dev_dbg(dev, "found matching SVR %08x\n",
port_id_map[i].svr); port_id_map[i].svr);
break; break;
} }
} }
if (csd_port_id) { if (csd_port_id) {
dev_dbg(&pdev->dev, "creating coherency subdomain at address " dev_dbg(dev, "creating coherency subdomain at address %pa, size %zu, port id 0x%08x",
"%pa, size %zu, port id 0x%08x", &ppaact_phys, &ppaact_phys, mem_size, csd_port_id);
mem_size, csd_port_id);
ret = create_csd(ppaact_phys, mem_size, csd_port_id); ret = create_csd(ppaact_phys, mem_size, csd_port_id);
if (ret) { if (ret) {
dev_err(&pdev->dev, "could not create coherence " dev_err(dev, "could not create coherence subdomain\n");
"subdomain\n");
return ret; return ret;
} }
} }
...@@ -1154,7 +1141,7 @@ static int __init fsl_pamu_probe(struct platform_device *pdev) ...@@ -1154,7 +1141,7 @@ static int __init fsl_pamu_probe(struct platform_device *pdev)
spaace_pool = gen_pool_create(ilog2(sizeof(struct paace)), -1); spaace_pool = gen_pool_create(ilog2(sizeof(struct paace)), -1);
if (!spaace_pool) { if (!spaace_pool) {
ret = -ENOMEM; ret = -ENOMEM;
dev_err(&pdev->dev, "PAMU : failed to allocate spaace gen pool\n"); dev_err(dev, "Failed to allocate spaace gen pool\n");
goto error; goto error;
} }
...@@ -1167,7 +1154,7 @@ static int __init fsl_pamu_probe(struct platform_device *pdev) ...@@ -1167,7 +1154,7 @@ static int __init fsl_pamu_probe(struct platform_device *pdev)
for (pamu_reg_off = 0, pamu_counter = 0x80000000; pamu_reg_off < size; for (pamu_reg_off = 0, pamu_counter = 0x80000000; pamu_reg_off < size;
pamu_reg_off += PAMU_OFFSET, pamu_counter >>= 1) { pamu_reg_off += PAMU_OFFSET, pamu_counter >>= 1) {
pamu_reg_base = (unsigned long) pamu_regs + pamu_reg_off; pamu_reg_base = (unsigned long)pamu_regs + pamu_reg_off;
setup_one_pamu(pamu_reg_base, pamu_reg_off, ppaact_phys, setup_one_pamu(pamu_reg_base, pamu_reg_off, ppaact_phys,
spaact_phys, omt_phys); spaact_phys, omt_phys);
/* Disable PAMU bypass for this PAMU */ /* Disable PAMU bypass for this PAMU */
...@@ -1181,7 +1168,7 @@ static int __init fsl_pamu_probe(struct platform_device *pdev) ...@@ -1181,7 +1168,7 @@ static int __init fsl_pamu_probe(struct platform_device *pdev)
iounmap(guts_regs); iounmap(guts_regs);
/* Enable DMA for the LIODNs in the device tree*/ /* Enable DMA for the LIODNs in the device tree */
setup_liodns(); setup_liodns();
......
...@@ -19,13 +19,15 @@ ...@@ -19,13 +19,15 @@
#ifndef __FSL_PAMU_H #ifndef __FSL_PAMU_H
#define __FSL_PAMU_H #define __FSL_PAMU_H
#include <linux/iommu.h>
#include <asm/fsl_pamu_stash.h> #include <asm/fsl_pamu_stash.h>
/* Bit Field macros /* Bit Field macros
* v = bit field variable; m = mask, m##_SHIFT = shift, x = value to load * v = bit field variable; m = mask, m##_SHIFT = shift, x = value to load
*/ */
#define set_bf(v, m, x) (v = ((v) & ~(m)) | (((x) << (m##_SHIFT)) & (m))) #define set_bf(v, m, x) (v = ((v) & ~(m)) | (((x) << m##_SHIFT) & (m)))
#define get_bf(v, m) (((v) & (m)) >> (m##_SHIFT)) #define get_bf(v, m) (((v) & (m)) >> m##_SHIFT)
/* PAMU CCSR space */ /* PAMU CCSR space */
#define PAMU_PGC 0x00000000 /* Allows all peripheral accesses */ #define PAMU_PGC 0x00000000 /* Allows all peripheral accesses */
...@@ -198,8 +200,7 @@ struct pamu_mmap_regs { ...@@ -198,8 +200,7 @@ struct pamu_mmap_regs {
#define PAACE_ATM_NO_XLATE 0x00 #define PAACE_ATM_NO_XLATE 0x00
#define PAACE_ATM_WINDOW_XLATE 0x01 #define PAACE_ATM_WINDOW_XLATE 0x01
#define PAACE_ATM_PAGE_XLATE 0x02 #define PAACE_ATM_PAGE_XLATE 0x02
#define PAACE_ATM_WIN_PG_XLATE \ #define PAACE_ATM_WIN_PG_XLATE (PAACE_ATM_WINDOW_XLATE | PAACE_ATM_PAGE_XLATE)
(PAACE_ATM_WINDOW_XLATE | PAACE_ATM_PAGE_XLATE)
#define PAACE_OTM_NO_XLATE 0x00 #define PAACE_OTM_NO_XLATE 0x00
#define PAACE_OTM_IMMEDIATE 0x01 #define PAACE_OTM_IMMEDIATE 0x01
#define PAACE_OTM_INDEXED 0x02 #define PAACE_OTM_INDEXED 0x02
...@@ -219,7 +220,7 @@ struct pamu_mmap_regs { ...@@ -219,7 +220,7 @@ struct pamu_mmap_regs {
#define PAACE_TCEF_FORMAT0_8B 0x00 #define PAACE_TCEF_FORMAT0_8B 0x00
#define PAACE_TCEF_FORMAT1_RSVD 0x01 #define PAACE_TCEF_FORMAT1_RSVD 0x01
/* /*
* Hard coded value for the PAACT size to accomodate * Hard coded value for the PAACT size to accommodate
* maximum LIODN value generated by u-boot. * maximum LIODN value generated by u-boot.
*/ */
#define PAACE_NUMBER_ENTRIES 0x500 #define PAACE_NUMBER_ENTRIES 0x500
...@@ -332,7 +333,7 @@ struct paace { ...@@ -332,7 +333,7 @@ struct paace {
#define NUM_MOE 128 #define NUM_MOE 128
struct ome { struct ome {
u8 moe[NUM_MOE]; u8 moe[NUM_MOE];
} __attribute__((packed)); } __packed;
#define PAACT_SIZE (sizeof(struct paace) * PAACE_NUMBER_ENTRIES) #define PAACT_SIZE (sizeof(struct paace) * PAACE_NUMBER_ENTRIES)
#define SPAACT_SIZE (sizeof(struct paace) * SPAACE_NUMBER_ENTRIES) #define SPAACT_SIZE (sizeof(struct paace) * SPAACE_NUMBER_ENTRIES)
......
...@@ -19,26 +19,10 @@ ...@@ -19,26 +19,10 @@
#define pr_fmt(fmt) "fsl-pamu-domain: %s: " fmt, __func__ #define pr_fmt(fmt) "fsl-pamu-domain: %s: " fmt, __func__
#include <linux/init.h>
#include <linux/iommu.h>
#include <linux/notifier.h>
#include <linux/slab.h>
#include <linux/module.h>
#include <linux/types.h>
#include <linux/mm.h>
#include <linux/interrupt.h>
#include <linux/device.h>
#include <linux/of_platform.h>
#include <linux/bootmem.h>
#include <linux/err.h>
#include <asm/io.h>
#include <asm/bitops.h>
#include <asm/pci-bridge.h>
#include <sysdev/fsl_pci.h>
#include "fsl_pamu_domain.h" #include "fsl_pamu_domain.h"
#include <sysdev/fsl_pci.h>
/* /*
* Global spinlock that needs to be held while * Global spinlock that needs to be held while
* configuring PAMU. * configuring PAMU.
...@@ -51,12 +35,10 @@ static DEFINE_SPINLOCK(device_domain_lock); ...@@ -51,12 +35,10 @@ static DEFINE_SPINLOCK(device_domain_lock);
static int __init iommu_init_mempool(void) static int __init iommu_init_mempool(void)
{ {
fsl_pamu_domain_cache = kmem_cache_create("fsl_pamu_domain", fsl_pamu_domain_cache = kmem_cache_create("fsl_pamu_domain",
sizeof(struct fsl_dma_domain), sizeof(struct fsl_dma_domain),
0, 0,
SLAB_HWCACHE_ALIGN, SLAB_HWCACHE_ALIGN,
NULL); NULL);
if (!fsl_pamu_domain_cache) { if (!fsl_pamu_domain_cache) {
pr_debug("Couldn't create fsl iommu_domain cache\n"); pr_debug("Couldn't create fsl iommu_domain cache\n");
...@@ -80,8 +62,7 @@ static int __init iommu_init_mempool(void) ...@@ -80,8 +62,7 @@ static int __init iommu_init_mempool(void)
static phys_addr_t get_phys_addr(struct fsl_dma_domain *dma_domain, dma_addr_t iova) static phys_addr_t get_phys_addr(struct fsl_dma_domain *dma_domain, dma_addr_t iova)
{ {
u32 win_cnt = dma_domain->win_cnt; u32 win_cnt = dma_domain->win_cnt;
struct dma_window *win_ptr = struct dma_window *win_ptr = &dma_domain->win_arr[0];
&dma_domain->win_arr[0];
struct iommu_domain_geometry *geom; struct iommu_domain_geometry *geom;
geom = &dma_domain->iommu_domain->geometry; geom = &dma_domain->iommu_domain->geometry;
...@@ -103,22 +84,20 @@ static phys_addr_t get_phys_addr(struct fsl_dma_domain *dma_domain, dma_addr_t i ...@@ -103,22 +84,20 @@ static phys_addr_t get_phys_addr(struct fsl_dma_domain *dma_domain, dma_addr_t i
} }
if (win_ptr->valid) if (win_ptr->valid)
return (win_ptr->paddr + (iova & (win_ptr->size - 1))); return win_ptr->paddr + (iova & (win_ptr->size - 1));
return 0; return 0;
} }
static int map_subwins(int liodn, struct fsl_dma_domain *dma_domain) static int map_subwins(int liodn, struct fsl_dma_domain *dma_domain)
{ {
struct dma_window *sub_win_ptr = struct dma_window *sub_win_ptr = &dma_domain->win_arr[0];
&dma_domain->win_arr[0];
int i, ret; int i, ret;
unsigned long rpn, flags; unsigned long rpn, flags;
for (i = 0; i < dma_domain->win_cnt; i++) { for (i = 0; i < dma_domain->win_cnt; i++) {
if (sub_win_ptr[i].valid) { if (sub_win_ptr[i].valid) {
rpn = sub_win_ptr[i].paddr >> rpn = sub_win_ptr[i].paddr >> PAMU_PAGE_SHIFT;
PAMU_PAGE_SHIFT;
spin_lock_irqsave(&iommu_lock, flags); spin_lock_irqsave(&iommu_lock, flags);
ret = pamu_config_spaace(liodn, dma_domain->win_cnt, i, ret = pamu_config_spaace(liodn, dma_domain->win_cnt, i,
sub_win_ptr[i].size, sub_win_ptr[i].size,
...@@ -130,7 +109,7 @@ static int map_subwins(int liodn, struct fsl_dma_domain *dma_domain) ...@@ -130,7 +109,7 @@ static int map_subwins(int liodn, struct fsl_dma_domain *dma_domain)
sub_win_ptr[i].prot); sub_win_ptr[i].prot);
spin_unlock_irqrestore(&iommu_lock, flags); spin_unlock_irqrestore(&iommu_lock, flags);
if (ret) { if (ret) {
pr_debug("PAMU SPAACE configuration failed for liodn %d\n", pr_debug("SPAACE configuration failed for liodn %d\n",
liodn); liodn);
return ret; return ret;
} }
...@@ -156,8 +135,7 @@ static int map_win(int liodn, struct fsl_dma_domain *dma_domain) ...@@ -156,8 +135,7 @@ static int map_win(int liodn, struct fsl_dma_domain *dma_domain)
0, wnd->prot); 0, wnd->prot);
spin_unlock_irqrestore(&iommu_lock, flags); spin_unlock_irqrestore(&iommu_lock, flags);
if (ret) if (ret)
pr_debug("PAMU PAACE configuration failed for liodn %d\n", pr_debug("PAACE configuration failed for liodn %d\n", liodn);
liodn);
return ret; return ret;
} }
...@@ -169,7 +147,6 @@ static int map_liodn(int liodn, struct fsl_dma_domain *dma_domain) ...@@ -169,7 +147,6 @@ static int map_liodn(int liodn, struct fsl_dma_domain *dma_domain)
return map_subwins(liodn, dma_domain); return map_subwins(liodn, dma_domain);
else else
return map_win(liodn, dma_domain); return map_win(liodn, dma_domain);
} }
/* Update window/subwindow mapping for the LIODN */ /* Update window/subwindow mapping for the LIODN */
...@@ -190,7 +167,8 @@ static int update_liodn(int liodn, struct fsl_dma_domain *dma_domain, u32 wnd_nr ...@@ -190,7 +167,8 @@ static int update_liodn(int liodn, struct fsl_dma_domain *dma_domain, u32 wnd_nr
(wnd_nr > 0) ? 1 : 0, (wnd_nr > 0) ? 1 : 0,
wnd->prot); wnd->prot);
if (ret) if (ret)
pr_debug("Subwindow reconfiguration failed for liodn %d\n", liodn); pr_debug("Subwindow reconfiguration failed for liodn %d\n",
liodn);
} else { } else {
phys_addr_t wnd_addr; phys_addr_t wnd_addr;
...@@ -203,7 +181,8 @@ static int update_liodn(int liodn, struct fsl_dma_domain *dma_domain, u32 wnd_nr ...@@ -203,7 +181,8 @@ static int update_liodn(int liodn, struct fsl_dma_domain *dma_domain, u32 wnd_nr
dma_domain->snoop_id, dma_domain->stash_id, dma_domain->snoop_id, dma_domain->stash_id,
0, wnd->prot); 0, wnd->prot);
if (ret) if (ret)
pr_debug("Window reconfiguration failed for liodn %d\n", liodn); pr_debug("Window reconfiguration failed for liodn %d\n",
liodn);
} }
spin_unlock_irqrestore(&iommu_lock, flags); spin_unlock_irqrestore(&iommu_lock, flags);
...@@ -219,7 +198,8 @@ static int update_liodn_stash(int liodn, struct fsl_dma_domain *dma_domain, ...@@ -219,7 +198,8 @@ static int update_liodn_stash(int liodn, struct fsl_dma_domain *dma_domain,
spin_lock_irqsave(&iommu_lock, flags); spin_lock_irqsave(&iommu_lock, flags);
if (!dma_domain->win_arr) { if (!dma_domain->win_arr) {
pr_debug("Windows not configured, stash destination update failed for liodn %d\n", liodn); pr_debug("Windows not configured, stash destination update failed for liodn %d\n",
liodn);
spin_unlock_irqrestore(&iommu_lock, flags); spin_unlock_irqrestore(&iommu_lock, flags);
return -EINVAL; return -EINVAL;
} }
...@@ -227,7 +207,8 @@ static int update_liodn_stash(int liodn, struct fsl_dma_domain *dma_domain, ...@@ -227,7 +207,8 @@ static int update_liodn_stash(int liodn, struct fsl_dma_domain *dma_domain,
for (i = 0; i < dma_domain->win_cnt; i++) { for (i = 0; i < dma_domain->win_cnt; i++) {
ret = pamu_update_paace_stash(liodn, i, val); ret = pamu_update_paace_stash(liodn, i, val);
if (ret) { if (ret) {
pr_debug("Failed to update SPAACE %d field for liodn %d\n ", i, liodn); pr_debug("Failed to update SPAACE %d field for liodn %d\n ",
i, liodn);
spin_unlock_irqrestore(&iommu_lock, flags); spin_unlock_irqrestore(&iommu_lock, flags);
return ret; return ret;
} }
...@@ -268,7 +249,8 @@ static int pamu_set_liodn(int liodn, struct device *dev, ...@@ -268,7 +249,8 @@ static int pamu_set_liodn(int liodn, struct device *dev,
dma_domain->stash_id, win_cnt, 0); dma_domain->stash_id, win_cnt, 0);
spin_unlock_irqrestore(&iommu_lock, flags); spin_unlock_irqrestore(&iommu_lock, flags);
if (ret) { if (ret) {
pr_debug("PAMU PAACE configuration failed for liodn %d, win_cnt =%d\n", liodn, win_cnt); pr_debug("PAACE configuration failed for liodn %d, win_cnt =%d\n",
liodn, win_cnt);
return ret; return ret;
} }
...@@ -285,7 +267,8 @@ static int pamu_set_liodn(int liodn, struct device *dev, ...@@ -285,7 +267,8 @@ static int pamu_set_liodn(int liodn, struct device *dev,
0, 0); 0, 0);
spin_unlock_irqrestore(&iommu_lock, flags); spin_unlock_irqrestore(&iommu_lock, flags);
if (ret) { if (ret) {
pr_debug("PAMU SPAACE configuration failed for liodn %d\n", liodn); pr_debug("SPAACE configuration failed for liodn %d\n",
liodn);
return ret; return ret;
} }
} }
...@@ -301,13 +284,13 @@ static int check_size(u64 size, dma_addr_t iova) ...@@ -301,13 +284,13 @@ static int check_size(u64 size, dma_addr_t iova)
* to PAMU page size. * to PAMU page size.
*/ */
if ((size & (size - 1)) || size < PAMU_PAGE_SIZE) { if ((size & (size - 1)) || size < PAMU_PAGE_SIZE) {
pr_debug("%s: size too small or not a power of two\n", __func__); pr_debug("Size too small or not a power of two\n");
return -EINVAL; return -EINVAL;
} }
/* iova must be page size aligned*/ /* iova must be page size aligned */
if (iova & (size - 1)) { if (iova & (size - 1)) {
pr_debug("%s: address is not aligned with window size\n", __func__); pr_debug("Address is not aligned with window size\n");
return -EINVAL; return -EINVAL;
} }
...@@ -396,7 +379,6 @@ static void attach_device(struct fsl_dma_domain *dma_domain, int liodn, struct d ...@@ -396,7 +379,6 @@ static void attach_device(struct fsl_dma_domain *dma_domain, int liodn, struct d
if (!dev->archdata.iommu_domain) if (!dev->archdata.iommu_domain)
dev->archdata.iommu_domain = info; dev->archdata.iommu_domain = info;
spin_unlock_irqrestore(&device_domain_lock, flags); spin_unlock_irqrestore(&device_domain_lock, flags);
} }
static phys_addr_t fsl_pamu_iova_to_phys(struct iommu_domain *domain, static phys_addr_t fsl_pamu_iova_to_phys(struct iommu_domain *domain,
...@@ -404,8 +386,8 @@ static phys_addr_t fsl_pamu_iova_to_phys(struct iommu_domain *domain, ...@@ -404,8 +386,8 @@ static phys_addr_t fsl_pamu_iova_to_phys(struct iommu_domain *domain,
{ {
struct fsl_dma_domain *dma_domain = domain->priv; struct fsl_dma_domain *dma_domain = domain->priv;
if ((iova < domain->geometry.aperture_start) || if (iova < domain->geometry.aperture_start ||
iova > (domain->geometry.aperture_end)) iova > domain->geometry.aperture_end)
return 0; return 0;
return get_phys_addr(dma_domain, iova); return get_phys_addr(dma_domain, iova);
...@@ -543,7 +525,6 @@ static void fsl_pamu_window_disable(struct iommu_domain *domain, u32 wnd_nr) ...@@ -543,7 +525,6 @@ static void fsl_pamu_window_disable(struct iommu_domain *domain, u32 wnd_nr)
} }
spin_unlock_irqrestore(&dma_domain->domain_lock, flags); spin_unlock_irqrestore(&dma_domain->domain_lock, flags);
} }
static int fsl_pamu_window_enable(struct iommu_domain *domain, u32 wnd_nr, static int fsl_pamu_window_enable(struct iommu_domain *domain, u32 wnd_nr,
...@@ -576,7 +557,7 @@ static int fsl_pamu_window_enable(struct iommu_domain *domain, u32 wnd_nr, ...@@ -576,7 +557,7 @@ static int fsl_pamu_window_enable(struct iommu_domain *domain, u32 wnd_nr,
win_size = dma_domain->geom_size >> ilog2(dma_domain->win_cnt); win_size = dma_domain->geom_size >> ilog2(dma_domain->win_cnt);
if (size > win_size) { if (size > win_size) {
pr_debug("Invalid window size \n"); pr_debug("Invalid window size\n");
spin_unlock_irqrestore(&dma_domain->domain_lock, flags); spin_unlock_irqrestore(&dma_domain->domain_lock, flags);
return -EINVAL; return -EINVAL;
} }
...@@ -632,7 +613,6 @@ static int handle_attach_device(struct fsl_dma_domain *dma_domain, ...@@ -632,7 +613,6 @@ static int handle_attach_device(struct fsl_dma_domain *dma_domain,
spin_lock_irqsave(&dma_domain->domain_lock, flags); spin_lock_irqsave(&dma_domain->domain_lock, flags);
for (i = 0; i < num; i++) { for (i = 0; i < num; i++) {
/* Ensure that LIODN value is valid */ /* Ensure that LIODN value is valid */
if (liodn[i] >= PAACE_NUMBER_ENTRIES) { if (liodn[i] >= PAACE_NUMBER_ENTRIES) {
pr_debug("Invalid liodn %d, attach device failed for %s\n", pr_debug("Invalid liodn %d, attach device failed for %s\n",
...@@ -649,9 +629,9 @@ static int handle_attach_device(struct fsl_dma_domain *dma_domain, ...@@ -649,9 +629,9 @@ static int handle_attach_device(struct fsl_dma_domain *dma_domain,
*/ */
if (dma_domain->win_arr) { if (dma_domain->win_arr) {
u32 win_cnt = dma_domain->win_cnt > 1 ? dma_domain->win_cnt : 0; u32 win_cnt = dma_domain->win_cnt > 1 ? dma_domain->win_cnt : 0;
ret = pamu_set_liodn(liodn[i], dev, dma_domain, ret = pamu_set_liodn(liodn[i], dev, dma_domain,
&domain->geometry, &domain->geometry, win_cnt);
win_cnt);
if (ret) if (ret)
break; break;
if (dma_domain->mapped) { if (dma_domain->mapped) {
...@@ -698,8 +678,7 @@ static int fsl_pamu_attach_device(struct iommu_domain *domain, ...@@ -698,8 +678,7 @@ static int fsl_pamu_attach_device(struct iommu_domain *domain,
liodn = of_get_property(dev->of_node, "fsl,liodn", &len); liodn = of_get_property(dev->of_node, "fsl,liodn", &len);
if (liodn) { if (liodn) {
liodn_cnt = len / sizeof(u32); liodn_cnt = len / sizeof(u32);
ret = handle_attach_device(dma_domain, dev, ret = handle_attach_device(dma_domain, dev, liodn, liodn_cnt);
liodn, liodn_cnt);
} else { } else {
pr_debug("missing fsl,liodn property at %s\n", pr_debug("missing fsl,liodn property at %s\n",
dev->of_node->full_name); dev->of_node->full_name);
...@@ -803,7 +782,7 @@ static int configure_domain_stash(struct fsl_dma_domain *dma_domain, void *data) ...@@ -803,7 +782,7 @@ static int configure_domain_stash(struct fsl_dma_domain *dma_domain, void *data)
return ret; return ret;
} }
/* Configure domain dma state i.e. enable/disable DMA*/ /* Configure domain dma state i.e. enable/disable DMA */
static int configure_domain_dma_state(struct fsl_dma_domain *dma_domain, bool enable) static int configure_domain_dma_state(struct fsl_dma_domain *dma_domain, bool enable)
{ {
struct device_domain_info *info; struct device_domain_info *info;
...@@ -819,8 +798,7 @@ static int configure_domain_dma_state(struct fsl_dma_domain *dma_domain, bool en ...@@ -819,8 +798,7 @@ static int configure_domain_dma_state(struct fsl_dma_domain *dma_domain, bool en
} }
dma_domain->enabled = enable; dma_domain->enabled = enable;
list_for_each_entry(info, &dma_domain->devices, list_for_each_entry(info, &dma_domain->devices, link) {
link) {
ret = (enable) ? pamu_enable_liodn(info->liodn) : ret = (enable) ? pamu_enable_liodn(info->liodn) :
pamu_disable_liodn(info->liodn); pamu_disable_liodn(info->liodn);
if (ret) if (ret)
...@@ -838,7 +816,6 @@ static int fsl_pamu_set_domain_attr(struct iommu_domain *domain, ...@@ -838,7 +816,6 @@ static int fsl_pamu_set_domain_attr(struct iommu_domain *domain,
struct fsl_dma_domain *dma_domain = domain->priv; struct fsl_dma_domain *dma_domain = domain->priv;
int ret = 0; int ret = 0;
switch (attr_type) { switch (attr_type) {
case DOMAIN_ATTR_GEOMETRY: case DOMAIN_ATTR_GEOMETRY:
ret = configure_domain_geometry(domain, data); ret = configure_domain_geometry(domain, data);
...@@ -853,7 +830,7 @@ static int fsl_pamu_set_domain_attr(struct iommu_domain *domain, ...@@ -853,7 +830,7 @@ static int fsl_pamu_set_domain_attr(struct iommu_domain *domain,
pr_debug("Unsupported attribute type\n"); pr_debug("Unsupported attribute type\n");
ret = -EINVAL; ret = -EINVAL;
break; break;
}; }
return ret; return ret;
} }
...@@ -864,10 +841,9 @@ static int fsl_pamu_get_domain_attr(struct iommu_domain *domain, ...@@ -864,10 +841,9 @@ static int fsl_pamu_get_domain_attr(struct iommu_domain *domain,
struct fsl_dma_domain *dma_domain = domain->priv; struct fsl_dma_domain *dma_domain = domain->priv;
int ret = 0; int ret = 0;
switch (attr_type) { switch (attr_type) {
case DOMAIN_ATTR_FSL_PAMU_STASH: case DOMAIN_ATTR_FSL_PAMU_STASH:
memcpy((struct pamu_stash_attribute *) data, &dma_domain->dma_stash, memcpy(data, &dma_domain->dma_stash,
sizeof(struct pamu_stash_attribute)); sizeof(struct pamu_stash_attribute));
break; break;
case DOMAIN_ATTR_FSL_PAMU_ENABLE: case DOMAIN_ATTR_FSL_PAMU_ENABLE:
...@@ -880,7 +856,7 @@ static int fsl_pamu_get_domain_attr(struct iommu_domain *domain, ...@@ -880,7 +856,7 @@ static int fsl_pamu_get_domain_attr(struct iommu_domain *domain,
pr_debug("Unsupported attribute type\n"); pr_debug("Unsupported attribute type\n");
ret = -EINVAL; ret = -EINVAL;
break; break;
}; }
return ret; return ret;
} }
...@@ -903,11 +879,8 @@ static bool check_pci_ctl_endpt_part(struct pci_controller *pci_ctl) ...@@ -903,11 +879,8 @@ static bool check_pci_ctl_endpt_part(struct pci_controller *pci_ctl)
/* Check the PCI controller version number by readding BRR1 register */ /* Check the PCI controller version number by readding BRR1 register */
version = in_be32(pci_ctl->cfg_addr + (PCI_FSL_BRR1 >> 2)); version = in_be32(pci_ctl->cfg_addr + (PCI_FSL_BRR1 >> 2));
version &= PCI_FSL_BRR1_VER; version &= PCI_FSL_BRR1_VER;
/* If PCI controller version is >= 0x204 we can partition endpoints*/ /* If PCI controller version is >= 0x204 we can partition endpoints */
if (version >= 0x204) return version >= 0x204;
return 1;
return 0;
} }
/* Get iommu group information from peer devices or devices on the parent bus */ /* Get iommu group information from peer devices or devices on the parent bus */
...@@ -968,9 +941,10 @@ static struct iommu_group *get_pci_device_group(struct pci_dev *pdev) ...@@ -968,9 +941,10 @@ static struct iommu_group *get_pci_device_group(struct pci_dev *pdev)
if (pci_ctl->parent->iommu_group) { if (pci_ctl->parent->iommu_group) {
group = get_device_iommu_group(pci_ctl->parent); group = get_device_iommu_group(pci_ctl->parent);
iommu_group_remove_device(pci_ctl->parent); iommu_group_remove_device(pci_ctl->parent);
} else } else {
group = get_shared_pci_device_group(pdev); group = get_shared_pci_device_group(pdev);
} }
}
if (!group) if (!group)
group = ERR_PTR(-ENODEV); group = ERR_PTR(-ENODEV);
...@@ -1055,11 +1029,12 @@ static int fsl_pamu_set_windows(struct iommu_domain *domain, u32 w_count) ...@@ -1055,11 +1029,12 @@ static int fsl_pamu_set_windows(struct iommu_domain *domain, u32 w_count)
} }
ret = pamu_set_domain_geometry(dma_domain, &domain->geometry, ret = pamu_set_domain_geometry(dma_domain, &domain->geometry,
((w_count > 1) ? w_count : 0)); w_count > 1 ? w_count : 0);
if (!ret) { if (!ret) {
kfree(dma_domain->win_arr); kfree(dma_domain->win_arr);
dma_domain->win_arr = kzalloc(sizeof(struct dma_window) * dma_domain->win_arr = kcalloc(w_count,
w_count, GFP_ATOMIC); sizeof(*dma_domain->win_arr),
GFP_ATOMIC);
if (!dma_domain->win_arr) { if (!dma_domain->win_arr) {
spin_unlock_irqrestore(&dma_domain->domain_lock, flags); spin_unlock_irqrestore(&dma_domain->domain_lock, flags);
return -ENOMEM; return -ENOMEM;
...@@ -1095,7 +1070,7 @@ static const struct iommu_ops fsl_pamu_ops = { ...@@ -1095,7 +1070,7 @@ static const struct iommu_ops fsl_pamu_ops = {
.remove_device = fsl_pamu_remove_device, .remove_device = fsl_pamu_remove_device,
}; };
int pamu_domain_init(void) int __init pamu_domain_init(void)
{ {
int ret = 0; int ret = 0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment