1/* SPDX-License-Identifier: GPL-2.0 */
2/*
3 * Support for Intel Camera Imaging ISP subsystem.
4 * Copyright (c) 2015, Intel Corporation.
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms and conditions of the GNU General Public License,
8 * version 2, as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
13 * more details.
14 */
15
16#ifndef __IA_CSS_ENV_H
17#define __IA_CSS_ENV_H
18
19#include <type_support.h>
20#include <linux/stdarg.h> /* va_list */
21#include <linux/bits.h>
22#include "ia_css_types.h"
23#include "ia_css_acc_types.h"
24
25/* @file
26 * This file contains prototypes for functions that need to be provided to the
27 * CSS-API host-code by the environment in which the CSS-API code runs.
28 */
29
30/* Memory allocation attributes, for use in ia_css_css_mem_env. */
31enum ia_css_mem_attr {
32	IA_CSS_MEM_ATTR_CACHED     = BIT(0),
33	IA_CSS_MEM_ATTR_ZEROED     = BIT(1),
34	IA_CSS_MEM_ATTR_PAGEALIGN  = BIT(2),
35	IA_CSS_MEM_ATTR_CONTIGUOUS = BIT(3),
36};
37
38/* Environment with function pointers for local IA memory allocation.
39 *  This provides the CSS code with environment specific functionality
40 *  for memory allocation of small local buffers such as local data structures.
41 *  This is never expected to allocate more than one page of memory (4K bytes).
42 */
43struct ia_css_cpu_mem_env {
44	void (*flush)(struct ia_css_acc_fw *fw);
45	/** Flush function to flush the cache for given accelerator. */
46};
47
48/* Environment with function pointers to access the CSS hardware. This includes
49 *  registers and local memories.
50 */
51struct ia_css_hw_access_env {
52	void (*store_8)(hrt_address addr, uint8_t data);
53	/** Store an 8 bit value into an address in the CSS HW address space.
54	     The address must be an 8 bit aligned address. */
55	void (*store_16)(hrt_address addr, uint16_t data);
56	/** Store a 16 bit value into an address in the CSS HW address space.
57	     The address must be a 16 bit aligned address. */
58	void (*store_32)(hrt_address addr, uint32_t data);
59	/** Store a 32 bit value into an address in the CSS HW address space.
60	     The address must be a 32 bit aligned address. */
61	uint8_t (*load_8)(hrt_address addr);
62	/** Load an 8 bit value from an address in the CSS HW address
63	     space. The address must be an 8 bit aligned address. */
64	uint16_t (*load_16)(hrt_address addr);
65	/** Load a 16 bit value from an address in the CSS HW address
66	     space. The address must be a 16 bit aligned address. */
67	uint32_t (*load_32)(hrt_address addr);
68	/** Load a 32 bit value from an address in the CSS HW address
69	     space. The address must be a 32 bit aligned address. */
70	void (*store)(hrt_address addr, const void *data, uint32_t bytes);
71	/** Store a number of bytes into a byte-aligned address in the CSS HW address space. */
72	void (*load)(hrt_address addr, void *data, uint32_t bytes);
73	/** Load a number of bytes from a byte-aligned address in the CSS HW address space. */
74};
75
76/* Environment with function pointers to print error and debug messages.
77 */
78struct ia_css_print_env {
79	int  __printf(1, 0) (*debug_print)(const char *fmt, va_list args);
80	/** Print a debug message. */
81	int  __printf(1, 0) (*error_print)(const char *fmt, va_list args);
82	/** Print an error message.*/
83};
84
85/* Environment structure. This includes function pointers to access several
86 *  features provided by the environment in which the CSS API is used.
87 *  This is used to run the camera IP in multiple platforms such as Linux,
88 *  Windows and several simulation environments.
89 */
90struct ia_css_env {
91	struct ia_css_cpu_mem_env   cpu_mem_env;   /** local flush. */
92	struct ia_css_hw_access_env hw_access_env; /** CSS HW access functions */
93	struct ia_css_print_env     print_env;     /** Message printing env. */
94};
95
96#endif /* __IA_CSS_ENV_H */
97