Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
adam.huang
Libcedrus
Commits
c1fb5e8f
Commit
c1fb5e8f
authored
Feb 16, 2016
by
Jens Kuske
Browse files
Add UMP memory support
parent
b029ad23
Changes
4
Show whitespace changes
Inline
Side-by-side
Makefile
View file @
c1fb5e8f
...
@@ -10,6 +10,12 @@ prefix ?= /usr/local
...
@@ -10,6 +10,12 @@ prefix ?= /usr/local
libdir
?=
$(prefix)
/lib
libdir
?=
$(prefix)
/lib
includedir
?=
$(prefix)
/include
includedir
?=
$(prefix)
/include
ifeq
($(USE_UMP),1)
SRC
+=
cedrus_mem_ump.c
CFLAGS
+=
-DUSE_UMP
LIBS
+=
-lUMP
endif
DEP_CFLAGS
=
-MD
-MP
-MQ
$@
DEP_CFLAGS
=
-MD
-MP
-MQ
$@
LIB_CFLAGS
=
-fpic
-fvisibility
=
hidden
LIB_CFLAGS
=
-fpic
-fvisibility
=
hidden
LIB_LDFLAGS
=
-shared
-Wl
,-soname,
$(TARGET)
LIB_LDFLAGS
=
-shared
-Wl
,-soname,
$(TARGET)
...
...
cedrus.c
View file @
c1fb5e8f
...
@@ -62,6 +62,11 @@ EXPORT struct cedrus *cedrus_open(void)
...
@@ -62,6 +62,11 @@ EXPORT struct cedrus *cedrus_open(void)
if
(
ve
.
regs
==
MAP_FAILED
)
if
(
ve
.
regs
==
MAP_FAILED
)
goto
close
;
goto
close
;
#ifdef USE_UMP
ve
.
allocator
=
cedrus_allocator_ump_new
();
if
(
!
ve
.
allocator
)
#endif
{
ve
.
allocator
=
cedrus_allocator_ve_new
(
ve
.
fd
,
&
info
);
ve
.
allocator
=
cedrus_allocator_ve_new
(
ve
.
fd
,
&
info
);
if
(
!
ve
.
allocator
)
if
(
!
ve
.
allocator
)
{
{
...
@@ -69,6 +74,7 @@ EXPORT struct cedrus *cedrus_open(void)
...
@@ -69,6 +74,7 @@ EXPORT struct cedrus *cedrus_open(void)
if
(
!
ve
.
allocator
)
if
(
!
ve
.
allocator
)
goto
unmap
;
goto
unmap
;
}
}
}
ioctl
(
ve
.
fd
,
IOCTL_ENGINE_REQ
,
0
);
ioctl
(
ve
.
fd
,
IOCTL_ENGINE_REQ
,
0
);
...
...
cedrus_mem.h
View file @
c1fb5e8f
...
@@ -42,6 +42,9 @@ struct cedrus_allocator
...
@@ -42,6 +42,9 @@ struct cedrus_allocator
struct
cedrus_allocator
*
cedrus_allocator_ve_new
(
int
ve_fd
,
const
struct
cedarv_env_infomation
*
ve_info
);
struct
cedrus_allocator
*
cedrus_allocator_ve_new
(
int
ve_fd
,
const
struct
cedarv_env_infomation
*
ve_info
);
struct
cedrus_allocator
*
cedrus_allocator_ion_new
(
void
);
struct
cedrus_allocator
*
cedrus_allocator_ion_new
(
void
);
#ifdef USE_UMP
struct
cedrus_allocator
*
cedrus_allocator_ump_new
(
void
);
#endif
uint32_t
phys2bus
(
uint32_t
phys
);
uint32_t
phys2bus
(
uint32_t
phys
);
uint32_t
bus2phys
(
uint32_t
bus
);
uint32_t
bus2phys
(
uint32_t
bus
);
...
...
cedrus_mem_ump.c
0 → 100644
View file @
c1fb5e8f
/*
* Copyright (c) 2016 Jens Kuske <jenskuske@gmail.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
#include <fcntl.h>
#include <stddef.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include <sys/mman.h>
#include <ump/ump.h>
#include <ump/ump_ref_drv.h>
#include "cedrus_mem.h"
struct
ump_mem
{
struct
cedrus_mem
pub
;
ump_handle
handle
;
};
static
struct
cedrus_mem
*
cedrus_allocator_ump_mem_alloc
(
struct
cedrus_allocator
*
allocator
,
size_t
size
)
{
(
void
)
allocator
;
struct
ump_mem
*
mem
=
calloc
(
1
,
sizeof
(
*
mem
));
if
(
!
mem
)
return
NULL
;
mem
->
pub
.
size
=
size
;
mem
->
handle
=
ump_ref_drv_allocate
(
size
,
UMP_REF_DRV_CONSTRAINT_PHYSICALLY_LINEAR
);
if
(
mem
->
handle
==
UMP_INVALID_MEMORY_HANDLE
)
goto
err
;
mem
->
pub
.
virt
=
ump_mapped_pointer_get
(
mem
->
handle
);
if
(
!
mem
->
pub
.
virt
)
goto
err_release
;
mem
->
pub
.
phys
=
bus2phys
((
uint32_t
)
ump_phys_address_get
(
mem
->
handle
));
if
(
!
mem
->
pub
.
phys
)
goto
err_release
;
return
&
mem
->
pub
;
err_release:
ump_reference_release
(
mem
->
handle
);
err:
free
(
mem
);
return
NULL
;
}
static
void
cedrus_allocator_ump_mem_free
(
struct
cedrus_allocator
*
allocator
,
struct
cedrus_mem
*
mem_pub
)
{
(
void
)
allocator
;
struct
ump_mem
*
mem
=
(
struct
ump_mem
*
)
mem_pub
;
ump_reference_release
(
mem
->
handle
);
free
(
mem
);
}
static
void
cedrus_allocator_ump_mem_flush
(
struct
cedrus_allocator
*
allocator
,
struct
cedrus_mem
*
mem_pub
)
{
(
void
)
allocator
;
struct
ump_mem
*
mem
=
(
struct
ump_mem
*
)
mem_pub
;
ump_cpu_msync_now
(
mem
->
handle
,
UMP_MSYNC_CLEAN_AND_INVALIDATE
,
0
,
mem
->
pub
.
size
);
}
static
void
cedrus_allocator_ump_free
(
struct
cedrus_allocator
*
allocator
)
{
ump_close
();
free
(
allocator
);
}
struct
cedrus_allocator
*
cedrus_allocator_ump_new
(
void
)
{
struct
cedrus_allocator
*
allocator
=
calloc
(
1
,
sizeof
(
*
allocator
));
if
(
!
allocator
)
return
NULL
;
if
(
ump_open
()
!=
UMP_OK
)
{
free
(
allocator
);
return
NULL
;
}
allocator
->
mem_alloc
=
cedrus_allocator_ump_mem_alloc
;
allocator
->
mem_free
=
cedrus_allocator_ump_mem_free
;
allocator
->
mem_flush
=
cedrus_allocator_ump_mem_flush
;
allocator
->
free
=
cedrus_allocator_ump_free
;
return
allocator
;
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment