Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) /* Copyright 2008 - 2016 Freescale Semiconductor, Inc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * Redistribution and use in source and binary forms, with or without
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  * modification, are permitted provided that the following conditions are met:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  *     * Redistributions of source code must retain the above copyright
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *	 notice, this list of conditions and the following disclaimer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  *     * Redistributions in binary form must reproduce the above copyright
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  *	 notice, this list of conditions and the following disclaimer in the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  *	 documentation and/or other materials provided with the distribution.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  *     * Neither the name of Freescale Semiconductor nor the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11)  *	 names of its contributors may be used to endorse or promote products
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12)  *	 derived from this software without specific prior written permission.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14)  * ALTERNATIVELY, this software may be distributed under the terms of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15)  * GNU General Public License ("GPL") as published by the Free Software
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16)  * Foundation, either version 2 of that License or (at your option) any
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17)  * later version.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19)  * THIS SOFTWARE IS PROVIDED BY Freescale Semiconductor ``AS IS'' AND ANY
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20)  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21)  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22)  * DISCLAIMED. IN NO EVENT SHALL Freescale Semiconductor BE LIABLE FOR ANY
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23)  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24)  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25)  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26)  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27)  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28)  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) #ifndef __FSL_BMAN_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) #define __FSL_BMAN_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) /* wrapper for 48-bit buffers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) struct bm_buffer {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 	union {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 		struct {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 			__be16 bpid; /* hi 8-bits reserved */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 			__be16 hi; /* High 16-bits of 48-bit address */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 			__be32 lo; /* Low 32-bits of 48-bit address */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 		};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 		__be64 data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) } __aligned(8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46)  * Restore the 48 bit address previously stored in BMan
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47)  * hardware pools as a dma_addr_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) static inline dma_addr_t bm_buf_addr(const struct bm_buffer *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	return be64_to_cpu(buf->data) & 0xffffffffffffLLU;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) static inline u64 bm_buffer_get64(const struct bm_buffer *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	return be64_to_cpu(buf->data) & 0xffffffffffffLLU;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) static inline void bm_buffer_set64(struct bm_buffer *buf, u64 addr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	buf->hi = cpu_to_be16(upper_32_bits(addr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	buf->lo = cpu_to_be32(lower_32_bits(addr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) static inline u8 bm_buffer_get_bpid(const struct bm_buffer *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	return be16_to_cpu(buf->bpid) & 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) static inline void bm_buffer_set_bpid(struct bm_buffer *buf, int bpid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	buf->bpid = cpu_to_be16(bpid & 0xff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) /* Managed portal, high-level i/face */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) /* Portal and Buffer Pools */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) struct bman_portal;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) struct bman_pool;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) #define BM_POOL_MAX		64 /* max # of buffer pools */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84)  * bman_new_pool - Allocates a Buffer Pool object
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86)  * Creates a pool object, and returns a reference to it or NULL on error.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) struct bman_pool *bman_new_pool(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91)  * bman_free_pool - Deallocates a Buffer Pool object
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92)  * @pool: the pool object to release
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) void bman_free_pool(struct bman_pool *pool);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97)  * bman_get_bpid - Returns a pool object's BPID.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98)  * @pool: the pool object
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100)  * The returned value is the index of the encapsulated buffer pool,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101)  * in the range of [0, @BM_POOL_MAX-1].
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) int bman_get_bpid(const struct bman_pool *pool);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106)  * bman_release - Release buffer(s) to the buffer pool
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107)  * @pool: the buffer pool object to release to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108)  * @bufs: an array of buffers to release
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109)  * @num: the number of buffers in @bufs (1-8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111)  * Adds the given buffers to RCR entries. If the RCR ring is unresponsive,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112)  * the function will return -ETIMEDOUT. Otherwise, it returns zero.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) int bman_release(struct bman_pool *pool, const struct bm_buffer *bufs, u8 num);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117)  * bman_acquire - Acquire buffer(s) from a buffer pool
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118)  * @pool: the buffer pool object to acquire from
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119)  * @bufs: array for storing the acquired buffers
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120)  * @num: the number of buffers desired (@bufs is at least this big)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122)  * Issues an "Acquire" command via the portal's management command interface.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123)  * The return value will be the number of buffers obtained from the pool, or a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124)  * negative error code if a h/w error or pool starvation was encountered. In
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125)  * the latter case, the content of @bufs is undefined.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) int bman_acquire(struct bman_pool *pool, struct bm_buffer *bufs, u8 num);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130)  * bman_is_probed - Check if bman is probed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132)  * Returns 1 if the bman driver successfully probed, -1 if the bman driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133)  * failed to probe or 0 if the bman driver did not probed yet.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) int bman_is_probed(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137)  * bman_portals_probed - Check if all cpu bound bman portals are probed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139)  * Returns 1 if all the required cpu bound bman portals successfully probed,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140)  * -1 if probe errors appeared or 0 if the bman portals did not yet finished
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141)  * probing.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) int bman_portals_probed(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) #endif	/* __FSL_BMAN_H */