Commit 86df6ff2 authored by Mauro Carvalho Chehab's avatar Mauro Carvalho Chehab
Browse files

media: atomisp: reduce abstraction at ia_css_memory_access



Yet another memory abstraction layer. Getting rid of this
may be a little trickier, but let's reduce it to a minimal.

Signed-off-by: default avatarMauro Carvalho Chehab <mchehab+huawei@kernel.org>
parent 4fba2916
Loading
Loading
Loading
Loading
+0 −3
Original line number Diff line number Diff line
@@ -28,9 +28,6 @@
#include "hmm/hmm_pool.h"
#include "ia_css_types.h"

#define HMM_CACHED true
#define HMM_UNCACHED false

int hmm_pool_register(unsigned int pool_size, enum hmm_pool_type pool_type);
void hmm_pool_unregister(enum hmm_pool_type pool_type);

+2 −59
Original line number Diff line number Diff line
@@ -76,37 +76,12 @@
 * within the allocation referencable from the
 * returned pointer/address.
 */
#define MMGR_ATTRIBUTE_MASK		0x000f
#define MMGR_ATTRIBUTE_CACHED		0x0001
#define MMGR_ATTRIBUTE_CONTIGUOUS	0x0002
#define MMGR_ATTRIBUTE_PAGEALIGN	0x0004
#define MMGR_ATTRIBUTE_CLEARED		0x0008
#define MMGR_ATTRIBUTE_UNUSED		0xfff0

/* #define MMGR_ATTRIBUTE_DEFAULT	(MMGR_ATTRIBUTE_CACHED) */
#define MMGR_ATTRIBUTE_DEFAULT	0

extern const hrt_vaddress	mmgr_NULL;
extern const hrt_vaddress	mmgr_EXCEPTION;

/*! Return the address of an allocation in memory

 \param	size[in]		Size in bytes of the allocation
 \param	caller_func[in]		Caller function name
 \param	caller_line[in]		Caller function line number

 \return vaddress
 */
hrt_vaddress mmgr_malloc(const size_t size);

/*! Return the address of a zero initialised allocation in memory

 \param	N[in]			Horizontal dimension of array
 \param	size[in]		Vertical dimension of array  Total size is N*size

 \return vaddress
 */
hrt_vaddress mmgr_calloc(const size_t N, const size_t size);
#define mmgr_NULL		((hrt_vaddress)0)
#define mmgr_EXCEPTION		((hrt_vaddress)-1)

/*! Return the address of an allocation in memory

@@ -119,38 +94,6 @@ hrt_vaddress mmgr_calloc(const size_t N, const size_t size);

hrt_vaddress mmgr_alloc_attr(const size_t size, const uint16_t attribute);

/*! Return the address of a mapped existing allocation in memory

 \param	ptr[in]			Pointer to an allocation in a different
				virtual memory page table, but the same
				physical memory
 \param size[in]		Size of the memory of the pointer
 \param	attribute[in]		Bit vector specifying the properties
				of the allocation
 \param context			Pointer of a context provided by
				client/driver for additional parameters
				needed by the implementation
 \Note
	This interface is tentative, limited to the desired function
	the actual interface may require furhter parameters

 \return vaddress
 */
hrt_vaddress mmgr_mmap(
    const void __user *ptr,
    const size_t size,
    u16 attribute,
    unsigned int pgnr);

/*! Zero initialise an allocation in memory

 \param	vaddr[in]		Address of an allocation
 \param	size[in]		Size in bytes of the area to be cleared

 \return none
 */
void mmgr_clear(hrt_vaddress vaddr, const size_t	size);

/*! Read an array of bytes from a virtual memory address

 \param	vaddr[in]		Address of an allocation
+1 −1
Original line number Diff line number Diff line
@@ -193,7 +193,7 @@ int hmm_init(void)
	 * at the beginning, to avoid hmm_alloc return 0 in the
	 * further allocation.
	 */
	dummy_ptr = hmm_alloc(1, HMM_BO_PRIVATE, 0, NULL, HMM_UNCACHED);
	dummy_ptr = hmm_alloc(1, HMM_BO_PRIVATE, 0, NULL, false);

	if (!ret) {
		ret = sysfs_create_group(&atomisp_dev->kobj,
+2 −43
Original line number Diff line number Diff line
@@ -20,46 +20,24 @@

#include "atomisp_internal.h"

const hrt_vaddress mmgr_NULL = (hrt_vaddress)0;
const hrt_vaddress mmgr_EXCEPTION = (hrt_vaddress)-1;

hrt_vaddress
mmgr_malloc(const size_t size)
{
	return mmgr_alloc_attr(size, 0);
}

hrt_vaddress mmgr_alloc_attr(const size_t size, const uint16_t attrs)
{
	u16 masked_attrs = attrs & MMGR_ATTRIBUTE_MASK;
	ia_css_ptr data;

	WARN_ON(attrs & MMGR_ATTRIBUTE_CONTIGUOUS);

	data = hmm_alloc(size, HMM_BO_PRIVATE, 0, NULL,
			 masked_attrs & MMGR_ATTRIBUTE_CACHED);
			 attrs & MMGR_ATTRIBUTE_CACHED);

	if (!data)
		return 0;

	if (masked_attrs & MMGR_ATTRIBUTE_CLEARED)
	if (attrs & MMGR_ATTRIBUTE_CLEARED)
		hmm_set(data, 0, size);

	return (ia_css_ptr)data;
}

hrt_vaddress
mmgr_calloc(const size_t N, const size_t size)
{
	return mmgr_alloc_attr(size * N, MMGR_ATTRIBUTE_CLEARED);
}

void mmgr_clear(hrt_vaddress vaddr, const size_t size)
{
	if (vaddr)
		hmm_set(vaddr, 0, size);
}

void mmgr_load(const hrt_vaddress vaddr, void *data, const size_t size)
{
	if (vaddr && data)
@@ -72,22 +50,3 @@ mmgr_store(const hrt_vaddress vaddr, const void *data, const size_t size)
	if (vaddr && data)
		hmm_store(vaddr, data, size);
}

hrt_vaddress
mmgr_mmap(const void __user *ptr, const size_t size,
	  u16 attribute, unsigned int pgnr)
{
	if (pgnr < ((PAGE_ALIGN(size)) >> PAGE_SHIFT)) {
		dev_err(atomisp_dev,
			"user space memory size is less than the expected size..\n");
		return -ENOMEM;
	} else if (pgnr > ((PAGE_ALIGN(size)) >> PAGE_SHIFT)) {
		dev_err(atomisp_dev,
			"user space memory size is large than the expected size..\n");
		return -ENOMEM;
	}

	return hmm_alloc(size, HMM_BO_USER, 0, ptr,
			 attribute & MMGR_ATTRIBUTE_CACHED);

}
+1 −1
Original line number Diff line number Diff line
@@ -329,7 +329,7 @@ ia_css_isp_dvs_statistics_allocate(
			    HIVE_ISP_DDR_WORD_BYTES);

	me->size = hor_size + ver_size;
	me->data_ptr = mmgr_malloc(me->size);
	me->data_ptr = mmgr_alloc_attr(me->size, 0);
	if (me->data_ptr == mmgr_NULL)
		goto err;
	me->hor_size = hor_size;
Loading