18c2ecf20Sopenharmony_ci/* Copyright 2008 - 2016 Freescale Semiconductor, Inc.
28c2ecf20Sopenharmony_ci *
38c2ecf20Sopenharmony_ci * Redistribution and use in source and binary forms, with or without
48c2ecf20Sopenharmony_ci * modification, are permitted provided that the following conditions are met:
58c2ecf20Sopenharmony_ci *     * Redistributions of source code must retain the above copyright
68c2ecf20Sopenharmony_ci *	 notice, this list of conditions and the following disclaimer.
78c2ecf20Sopenharmony_ci *     * Redistributions in binary form must reproduce the above copyright
88c2ecf20Sopenharmony_ci *	 notice, this list of conditions and the following disclaimer in the
98c2ecf20Sopenharmony_ci *	 documentation and/or other materials provided with the distribution.
108c2ecf20Sopenharmony_ci *     * Neither the name of Freescale Semiconductor nor the
118c2ecf20Sopenharmony_ci *	 names of its contributors may be used to endorse or promote products
128c2ecf20Sopenharmony_ci *	 derived from this software without specific prior written permission.
138c2ecf20Sopenharmony_ci *
148c2ecf20Sopenharmony_ci * ALTERNATIVELY, this software may be distributed under the terms of the
158c2ecf20Sopenharmony_ci * GNU General Public License ("GPL") as published by the Free Software
168c2ecf20Sopenharmony_ci * Foundation, either version 2 of that License or (at your option) any
178c2ecf20Sopenharmony_ci * later version.
188c2ecf20Sopenharmony_ci *
198c2ecf20Sopenharmony_ci * THIS SOFTWARE IS PROVIDED BY Freescale Semiconductor ``AS IS'' AND ANY
208c2ecf20Sopenharmony_ci * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
218c2ecf20Sopenharmony_ci * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
228c2ecf20Sopenharmony_ci * DISCLAIMED. IN NO EVENT SHALL Freescale Semiconductor BE LIABLE FOR ANY
238c2ecf20Sopenharmony_ci * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
248c2ecf20Sopenharmony_ci * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
258c2ecf20Sopenharmony_ci * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
268c2ecf20Sopenharmony_ci * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
278c2ecf20Sopenharmony_ci * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
288c2ecf20Sopenharmony_ci * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
298c2ecf20Sopenharmony_ci */
308c2ecf20Sopenharmony_ci
318c2ecf20Sopenharmony_ci#ifndef __DPAA_SYS_H
328c2ecf20Sopenharmony_ci#define __DPAA_SYS_H
338c2ecf20Sopenharmony_ci
348c2ecf20Sopenharmony_ci#include <linux/cpu.h>
358c2ecf20Sopenharmony_ci#include <linux/slab.h>
368c2ecf20Sopenharmony_ci#include <linux/module.h>
378c2ecf20Sopenharmony_ci#include <linux/interrupt.h>
388c2ecf20Sopenharmony_ci#include <linux/kthread.h>
398c2ecf20Sopenharmony_ci#include <linux/sched/signal.h>
408c2ecf20Sopenharmony_ci#include <linux/vmalloc.h>
418c2ecf20Sopenharmony_ci#include <linux/platform_device.h>
428c2ecf20Sopenharmony_ci#include <linux/of.h>
438c2ecf20Sopenharmony_ci#include <linux/of_reserved_mem.h>
448c2ecf20Sopenharmony_ci#include <linux/prefetch.h>
458c2ecf20Sopenharmony_ci#include <linux/genalloc.h>
468c2ecf20Sopenharmony_ci#include <asm/cacheflush.h>
478c2ecf20Sopenharmony_ci#include <linux/io.h>
488c2ecf20Sopenharmony_ci#include <linux/delay.h>
498c2ecf20Sopenharmony_ci
508c2ecf20Sopenharmony_ci/* For 2-element tables related to cache-inhibited and cache-enabled mappings */
518c2ecf20Sopenharmony_ci#define DPAA_PORTAL_CE 0
528c2ecf20Sopenharmony_ci#define DPAA_PORTAL_CI 1
538c2ecf20Sopenharmony_ci
548c2ecf20Sopenharmony_cistatic inline void dpaa_flush(void *p)
558c2ecf20Sopenharmony_ci{
568c2ecf20Sopenharmony_ci	/*
578c2ecf20Sopenharmony_ci	 * Only PPC needs to flush the cache currently - on ARM the mapping
588c2ecf20Sopenharmony_ci	 * is non cacheable
598c2ecf20Sopenharmony_ci	 */
608c2ecf20Sopenharmony_ci#ifdef CONFIG_PPC
618c2ecf20Sopenharmony_ci	flush_dcache_range((unsigned long)p, (unsigned long)p+64);
628c2ecf20Sopenharmony_ci#endif
638c2ecf20Sopenharmony_ci}
648c2ecf20Sopenharmony_ci
658c2ecf20Sopenharmony_ci#define dpaa_invalidate(p) dpaa_flush(p)
668c2ecf20Sopenharmony_ci
678c2ecf20Sopenharmony_ci#define dpaa_zero(p) memset(p, 0, 64)
688c2ecf20Sopenharmony_ci
698c2ecf20Sopenharmony_cistatic inline void dpaa_touch_ro(void *p)
708c2ecf20Sopenharmony_ci{
718c2ecf20Sopenharmony_ci#if (L1_CACHE_BYTES == 32)
728c2ecf20Sopenharmony_ci	prefetch(p+32);
738c2ecf20Sopenharmony_ci#endif
748c2ecf20Sopenharmony_ci	prefetch(p);
758c2ecf20Sopenharmony_ci}
768c2ecf20Sopenharmony_ci
778c2ecf20Sopenharmony_ci/* Commonly used combo */
788c2ecf20Sopenharmony_cistatic inline void dpaa_invalidate_touch_ro(void *p)
798c2ecf20Sopenharmony_ci{
808c2ecf20Sopenharmony_ci	dpaa_invalidate(p);
818c2ecf20Sopenharmony_ci	dpaa_touch_ro(p);
828c2ecf20Sopenharmony_ci}
838c2ecf20Sopenharmony_ci
848c2ecf20Sopenharmony_ci
858c2ecf20Sopenharmony_ci#ifdef CONFIG_FSL_DPAA_CHECKING
868c2ecf20Sopenharmony_ci#define DPAA_ASSERT(x) WARN_ON(!(x))
878c2ecf20Sopenharmony_ci#else
888c2ecf20Sopenharmony_ci#define DPAA_ASSERT(x)
898c2ecf20Sopenharmony_ci#endif
908c2ecf20Sopenharmony_ci
918c2ecf20Sopenharmony_ci/* cyclic helper for rings */
928c2ecf20Sopenharmony_cistatic inline u8 dpaa_cyc_diff(u8 ringsize, u8 first, u8 last)
938c2ecf20Sopenharmony_ci{
948c2ecf20Sopenharmony_ci	/* 'first' is included, 'last' is excluded */
958c2ecf20Sopenharmony_ci	if (first <= last)
968c2ecf20Sopenharmony_ci		return last - first;
978c2ecf20Sopenharmony_ci	return ringsize + last - first;
988c2ecf20Sopenharmony_ci}
998c2ecf20Sopenharmony_ci
1008c2ecf20Sopenharmony_ci/* Offset applied to genalloc pools due to zero being an error return */
1018c2ecf20Sopenharmony_ci#define DPAA_GENALLOC_OFF	0x80000000
1028c2ecf20Sopenharmony_ci
1038c2ecf20Sopenharmony_ci/* Initialize the devices private memory region */
1048c2ecf20Sopenharmony_ciint qbman_init_private_mem(struct device *dev, int idx, dma_addr_t *addr,
1058c2ecf20Sopenharmony_ci				size_t *size);
1068c2ecf20Sopenharmony_ci
1078c2ecf20Sopenharmony_ci/* memremap() attributes for different platforms */
1088c2ecf20Sopenharmony_ci#ifdef CONFIG_PPC
1098c2ecf20Sopenharmony_ci#define QBMAN_MEMREMAP_ATTR	MEMREMAP_WB
1108c2ecf20Sopenharmony_ci#else
1118c2ecf20Sopenharmony_ci#define QBMAN_MEMREMAP_ATTR	MEMREMAP_WC
1128c2ecf20Sopenharmony_ci#endif
1138c2ecf20Sopenharmony_ci
1148c2ecf20Sopenharmony_cistatic inline int dpaa_set_portal_irq_affinity(struct device *dev,
1158c2ecf20Sopenharmony_ci					       int irq, int cpu)
1168c2ecf20Sopenharmony_ci{
1178c2ecf20Sopenharmony_ci	int ret = 0;
1188c2ecf20Sopenharmony_ci
1198c2ecf20Sopenharmony_ci	if (!irq_can_set_affinity(irq)) {
1208c2ecf20Sopenharmony_ci		dev_err(dev, "unable to set IRQ affinity\n");
1218c2ecf20Sopenharmony_ci		return -EINVAL;
1228c2ecf20Sopenharmony_ci	}
1238c2ecf20Sopenharmony_ci
1248c2ecf20Sopenharmony_ci	if (cpu == -1 || !cpu_online(cpu))
1258c2ecf20Sopenharmony_ci		cpu = cpumask_any(cpu_online_mask);
1268c2ecf20Sopenharmony_ci
1278c2ecf20Sopenharmony_ci	ret = irq_set_affinity(irq, cpumask_of(cpu));
1288c2ecf20Sopenharmony_ci	if (ret)
1298c2ecf20Sopenharmony_ci		dev_err(dev, "irq_set_affinity() on CPU %d failed\n", cpu);
1308c2ecf20Sopenharmony_ci
1318c2ecf20Sopenharmony_ci	return ret;
1328c2ecf20Sopenharmony_ci}
1338c2ecf20Sopenharmony_ci
1348c2ecf20Sopenharmony_ci#endif	/* __DPAA_SYS_H */
135