1  /* SPDX-License-Identifier: GPL-2.0 */
2  /**
3  Support for Intel Camera Imaging ISP subsystem.
4  Copyright (c) 2010 - 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 __DEVICE_ACCESS_H_INCLUDED__
17  #define __DEVICE_ACCESS_H_INCLUDED__
18  
19  /*!
20   * \brief
21   * Define the public interface for physical system
22   * access functions to SRAM and registers. Access
23   * types are limited to those defined in <stdint.h>
24   * All accesses are aligned
25   *
26   * The address representation is private to the system
27   * and represented as/stored in "hrt_address".
28   *
29   * The system global address can differ by an offset;
30   * The device base address. This offset must be added
31   * by the implementation of the access function
32   *
33   * "store" is a transfer to the device
34   * "load" is a transfer from the device
35   */
36  
37  #include <type_support.h>
38  
39  /*
40   * User provided file that defines the system address types:
41   *	- hrt_address	a type that can hold the (sub)system address range
42   */
43  #include "system_local.h"
44  /*
45   * We cannot assume that the global system address size is the size of
46   * a pointer because a (say) 64-bit host can be simulated in a 32-bit
47   * environment. Only if the host environment is modelled as on the target
48   * we could use a pointer. Even then, prototyping may need to be done
49   * before the target environment is available. AS we cannot wait for that
50   * we are stuck with integer addresses
51   */
52  
53  /*typedef	char *sys_address;*/
54  typedef	hrt_address		sys_address;
55  
56  /*! Set the (sub)system base address
57  
58   \param	base_addr[in]		The offset on which the (sub)system is located
59  							in the global address map
60  
61   \return none,
62   */
63  void device_set_base_address(
64      const sys_address		base_addr);
65  
66  /*! Get the (sub)system base address
67  
68   \return base_address,
69   */
70  sys_address device_get_base_address(void);
71  
72  /*! Read an 8-bit value from a device register or memory in the device
73  
74   \param	addr[in]			Local address
75  
76   \return device[addr]
77   */
78  uint8_t ia_css_device_load_uint8(
79      const hrt_address		addr);
80  
81  /*! Read a 16-bit value from a device register or memory in the device
82  
83   \param	addr[in]			Local address
84  
85   \return device[addr]
86   */
87  uint16_t ia_css_device_load_uint16(
88      const hrt_address		addr);
89  
90  /*! Read a 32-bit value from a device register or memory in the device
91  
92   \param	addr[in]			Local address
93  
94   \return device[addr]
95   */
96  uint32_t ia_css_device_load_uint32(
97      const hrt_address		addr);
98  
99  /*! Read a 64-bit value from a device register or memory in the device
100  
101   \param	addr[in]			Local address
102  
103   \return device[addr]
104   */
105  uint64_t ia_css_device_load_uint64(
106      const hrt_address		addr);
107  
108  /*! Write an 8-bit value to a device register or memory in the device
109  
110   \param	addr[in]			Local address
111   \param	data[in]			value
112  
113   \return none, device[addr] = value
114   */
115  void ia_css_device_store_uint8(
116      const hrt_address		addr,
117      const uint8_t			data);
118  
119  /*! Write a 16-bit value to a device register or memory in the device
120  
121   \param	addr[in]			Local address
122   \param	data[in]			value
123  
124   \return none, device[addr] = value
125   */
126  void ia_css_device_store_uint16(
127      const hrt_address		addr,
128      const uint16_t			data);
129  
130  /*! Write a 32-bit value to a device register or memory in the device
131  
132   \param	addr[in]			Local address
133   \param	data[in]			value
134  
135   \return none, device[addr] = value
136   */
137  void ia_css_device_store_uint32(
138      const hrt_address		addr,
139      const uint32_t			data);
140  
141  /*! Write a 64-bit value to a device register or memory in the device
142  
143   \param	addr[in]			Local address
144   \param	data[in]			value
145  
146   \return none, device[addr] = value
147   */
148  void ia_css_device_store_uint64(
149      const hrt_address		addr,
150      const uint64_t			data);
151  
152  /*! Read an array of bytes from device registers or memory in the device
153  
154   \param	addr[in]			Local address
155   \param	data[out]			pointer to the destination array
156   \param	size[in]			number of bytes to read
157  
158   \return none
159   */
160  void ia_css_device_load(
161      const hrt_address		addr,
162      void					*data,
163      const size_t			size);
164  
165  /*! Write an array of bytes to device registers or memory in the device
166  
167   \param	addr[in]			Local address
168   \param	data[in]			pointer to the source array
169   \param	size[in]			number of bytes to write
170  
171   \return none
172   */
173  void ia_css_device_store(
174      const hrt_address		addr,
175      const void				*data,
176      const size_t			size);
177  
178  #endif /* __DEVICE_ACCESS_H_INCLUDED__ */
179