2  * Support for Intel Camera Imaging ISP subsystem.
 
   3  * Copyright (c) 2015-2017, Intel Corporation.
 
   5  * This program is free software; you can redistribute it and/or modify it
 
   6  * under the terms and conditions of the GNU General Public License,
 
   7  * version 2, as published by the Free Software Foundation.
 
   9  * This program is distributed in the hope it will be useful, but WITHOUT
 
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
 
  15 #ifndef __MEMORY_ACCESS_H_INCLUDED__
 
  16 #define __MEMORY_ACCESS_H_INCLUDED__
 
  20  * Define the public interface for virtual memory
 
  21  * access functions. Access types are limited to
 
  22  * those defined in <stdint.h>
 
  24  * The address representation is private to the system
 
  25  * and represented as "hrt_vaddress" rather than a
 
  26  * pointer, as the memory allocation cannot be accessed
 
  27  * by dereferencing but reaquires load and store access
 
  30  * The page table selection or virtual memory context;
 
  31  * The page table base index; Is implicit. This page
 
  32  * table base index must be set by the implementation
 
  33  * of the access function
 
  35  * "store" is a transfer to the system
 
  36  * "load" is a transfer from the system
 
  38  * Allocation properties can be specified by setting
 
  39  * attributes (see below) in case of multiple physical
 
  40  * memories the memory ID is encoded on the attribute
 
  42  * Allocations in the same physical memory, but in a
 
  43  * different (set of) page tables can be shared through
 
  44  * a page table information mapping function
 
  47 #include <type_support.h>
 
  48 #include "platform_support.h"   /* for __func__ */
 
  51  * User provided file that defines the (sub)system address types:
 
  52  *      - hrt_vaddress  a type that can hold the (sub)system virtual address range
 
  54 #include "system_types.h"
 
  57  * The MMU base address is a physical address, thus the same type is used
 
  58  * as for the device base address
 
  60 #include "device_access.h"
 
  66  * Bit masks for specialised allocation functions
 
  67  * the default is "uncached", "not contiguous",
 
  68  * "not page aligned" and "not cleared"
 
  70  * Forcing alignment (usually) returns a pointer
 
  71  * at an alignment boundary that is offset from
 
  72  * the allocated pointer. Without storing this
 
  73  * pointer/offset, we cannot free it. The memory
 
  74  * manager is responsible for the bookkeeping, e.g.
 
  75  * the allocation function creates a sentinel
 
  76  * within the allocation referencable from the
 
  77  * returned pointer/address.
 
  79 #define MMGR_ATTRIBUTE_MASK             0x000f
 
  80 #define MMGR_ATTRIBUTE_CACHED           0x0001
 
  81 #define MMGR_ATTRIBUTE_CONTIGUOUS       0x0002
 
  82 #define MMGR_ATTRIBUTE_PAGEALIGN        0x0004
 
  83 #define MMGR_ATTRIBUTE_CLEARED          0x0008
 
  84 #define MMGR_ATTRIBUTE_UNUSED           0xfff0
 
  86 /* #define MMGR_ATTRIBUTE_DEFAULT       (MMGR_ATTRIBUTE_CACHED) */
 
  87 #define MMGR_ATTRIBUTE_DEFAULT  0
 
  89 extern const hrt_vaddress       mmgr_NULL;
 
  90 extern const hrt_vaddress       mmgr_EXCEPTION;
 
  92 /*! Return the address of an allocation in memory
 
  94  \param size[in]                Size in bytes of the allocation
 
  95  \param caller_func[in]         Caller function name
 
  96  \param caller_line[in]         Caller function line number
 
 100 extern hrt_vaddress mmgr_malloc(const size_t size);
 
 102 /*! Return the address of a zero initialised allocation in memory
 
 104  \param N[in]                   Horizontal dimension of array
 
 105  \param size[in]                Vertical dimension of array  Total size is N*size
 
 109 extern hrt_vaddress mmgr_calloc(const size_t N, const size_t size);
 
 111 /*! Return the address of an allocation in memory
 
 113  \param size[in]                Size in bytes of the allocation
 
 114  \param attribute[in]           Bit vector specifying the properties
 
 115                                 of the allocation including zero initialisation
 
 120 extern hrt_vaddress mmgr_alloc_attr(const size_t size, const uint16_t attribute);
 
 122 /*! Return the address of a mapped existing allocation in memory
 
 124  \param ptr[in]                 Pointer to an allocation in a different
 
 125                                 virtual memory page table, but the same
 
 127  \param size[in]                Size of the memory of the pointer
 
 128  \param attribute[in]           Bit vector specifying the properties
 
 130  \param context                 Pointer of a context provided by
 
 131                                 client/driver for additonal parameters
 
 132                                 needed by the implementation
 
 134         This interface is tentative, limited to the desired function
 
 135         the actual interface may require furhter parameters
 
 139 extern hrt_vaddress mmgr_mmap(
 
 140         const void __user *ptr,
 
 145 /*! Zero initialise an allocation in memory
 
 147  \param vaddr[in]               Address of an allocation
 
 148  \param size[in]                Size in bytes of the area to be cleared
 
 152 extern void mmgr_clear(hrt_vaddress vaddr, const size_t size);
 
 154 /*! Read an array of bytes from a virtual memory address
 
 156  \param vaddr[in]               Address of an allocation
 
 157  \param data[out]               pointer to the destination array
 
 158  \param size[in]                number of bytes to read
 
 162 extern void mmgr_load(const hrt_vaddress vaddr, void *data, const size_t size);
 
 164 /*! Write an array of bytes to device registers or memory in the device
 
 166  \param vaddr[in]               Address of an allocation
 
 167  \param data[in]                pointer to the source array
 
 168  \param size[in]                number of bytes to write
 
 172 extern void mmgr_store(const hrt_vaddress vaddr, const void *data, const size_t size);
 
 174 #endif /* __MEMORY_ACCESS_H_INCLUDED__ */