summaryrefslogtreecommitdiff
path: root/gralloc_module_ump.cpp (plain)
blob: af114915308bbb004a22e0a13a0e66bab850e361
1/*
2 * Copyright (C) 2013 ARM Limited. All rights reserved.
3 *
4 * Copyright (C) 2008 The Android Open Source Project
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * You may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18
19#include <errno.h>
20#include <pthread.h>
21
22#include <cutils/log.h>
23#include <cutils/atomic.h>
24#include <hardware/hardware.h>
25#include <hardware/gralloc.h>
26
27#include "gralloc_priv.h"
28#include "alloc_device.h"
29#include "framebuffer_device.h"
30
31#include <ump/ump_ref_drv.h>
32static int s_ump_is_open = 0;
33
34int gralloc_backend_register(private_handle_t* hnd)
35{
36 int retval = -EINVAL;
37
38 switch (hnd->flags & (private_handle_t::PRIV_FLAGS_USES_UMP |
39 private_handle_t::PRIV_FLAGS_USES_ION))
40 {
41 case private_handle_t::PRIV_FLAGS_USES_UMP:
42 if (!s_ump_is_open)
43 {
44 ump_result res = ump_open(); // MJOLL-4012: UMP implementation needs a ump_close() for each ump_open
45 if (res != UMP_OK)
46 {
47 AERR("Failed to open UMP library with res=%d", res);
48 }
49 s_ump_is_open = 1;
50 }
51
52 if (s_ump_is_open)
53 {
54 hnd->ump_mem_handle = ump_handle_create_from_secure_id(hnd->ump_id);
55 if (UMP_INVALID_MEMORY_HANDLE != (ump_handle)hnd->ump_mem_handle)
56 {
57 hnd->base = ump_mapped_pointer_get(hnd->ump_mem_handle);
58 if (0 != hnd->base)
59 {
60 hnd->lockState = private_handle_t::LOCK_STATE_MAPPED;
61 hnd->writeOwner = 0;
62 hnd->lockState = 0;
63
64 return 0;
65 }
66 else
67 {
68 AERR("Failed to map UMP handle %p", hnd->ump_mem_handle );
69 }
70
71 ump_reference_release((ump_handle)hnd->ump_mem_handle);
72 }
73 else
74 {
75 AERR("Failed to create UMP handle %p", hnd->ump_mem_handle );
76 }
77 }
78 break;
79 case private_handle_t::PRIV_FLAGS_USES_ION:
80 AERR("Gralloc does not support DMA_BUF. Unable to map memory for handle %p", hnd );
81 break;
82 }
83
84 return retval;
85}
86
87void gralloc_backend_unregister(private_handle_t* hnd)
88{
89 switch (hnd->flags & (private_handle_t::PRIV_FLAGS_USES_UMP |
90 private_handle_t::PRIV_FLAGS_USES_ION))
91 {
92 case private_handle_t::PRIV_FLAGS_USES_UMP:
93 ump_mapped_pointer_release((ump_handle)hnd->ump_mem_handle);
94 hnd->base = 0;
95 ump_reference_release((ump_handle)hnd->ump_mem_handle);
96 hnd->ump_mem_handle = UMP_INVALID_MEMORY_HANDLE;
97 break;
98 case private_handle_t::PRIV_FLAGS_USES_ION:
99 AERR( "Can't unregister DMA_BUF buffer for hnd %p. Not supported", hnd );
100 break;
101 }
102}
103
104void gralloc_backend_sync(private_handle_t* hnd)
105{
106 switch (hnd->flags & (private_handle_t::PRIV_FLAGS_USES_UMP |
107 private_handle_t::PRIV_FLAGS_USES_ION))
108 {
109 case private_handle_t::PRIV_FLAGS_USES_UMP:
110 ump_cpu_msync_now((ump_handle)hnd->ump_mem_handle, UMP_MSYNC_CLEAN_AND_INVALIDATE, (void*)hnd->base, hnd->size);
111 break;
112 case private_handle_t::PRIV_FLAGS_USES_ION:
113 AERR( "Buffer %p is DMA_BUF type but it is not supported", hnd );
114 break;
115 }
116}
117