gralloc: disable adreno lib usage in absence of kgsl node
Change-Id: Ia5f788a3095c76432f8b916c81ac20d90f41348a
diff --git a/gralloc/gr_adreno_info.cpp b/gralloc/gr_adreno_info.cpp
index 9e195d5..f1d9b0d 100644
--- a/gralloc/gr_adreno_info.cpp
+++ b/gralloc/gr_adreno_info.cpp
@@ -27,12 +27,17 @@
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * Changes from Qualcomm Innovation Center are provided under the following license:
+ * Copyright (c) 2023, Qualcomm Innovation Center, Inc. All rights reserved.
+ * SPDX-License-Identifier: BSD-3-Clause-Clear
*/
#include <log/log.h>
#include <cutils/properties.h>
#include <dlfcn.h>
#include <mutex>
+#include <fstream>
#include "gr_adreno_info.h"
#include "gr_utils.h"
@@ -41,10 +46,12 @@
using std::lock_guard;
using std::mutex;
+using std::fstream;
namespace gralloc {
AdrenoMemInfo *AdrenoMemInfo::s_instance = nullptr;
+char kgsl_path[] = "/dev/kgsl-3d0";
AdrenoMemInfo *AdrenoMemInfo::GetInstance() {
static mutex s_lock;
@@ -57,6 +64,18 @@
}
AdrenoMemInfo::AdrenoMemInfo() {
+ char property[PROPERTY_VALUE_MAX];
+ property_get(DISABLE_UBWC_PROP, property, "0");
+ if (!(strncmp(property, "1", PROPERTY_VALUE_MAX)) ||
+ !(strncmp(property, "true", PROPERTY_VALUE_MAX))) {
+ gfx_ubwc_disable_ = true;
+ }
+
+ fstream fs(kgsl_path, fstream::in);
+ if (!fs.is_open()) {
+ return;
+ }
+
libadreno_utils_ = ::dlopen("libadreno_utils.so", RTLD_NOW);
if (libadreno_utils_) {
*reinterpret_cast<void **>(&LINK_adreno_compute_aligned_width_and_height) =
@@ -80,12 +99,6 @@
} else {
ALOGE(" Failed to load libadreno_utils.so");
}
- char property[PROPERTY_VALUE_MAX];
- property_get(DISABLE_UBWC_PROP, property, "0");
- if (!(strncmp(property, "1", PROPERTY_VALUE_MAX)) ||
- !(strncmp(property, "true", PROPERTY_VALUE_MAX))) {
- gfx_ubwc_disable_ = true;
- }
}
AdrenoMemInfo::~AdrenoMemInfo() {
diff --git a/gralloc/gr_buf_mgr.cpp b/gralloc/gr_buf_mgr.cpp
index 2f11185..4c839a1 100644
--- a/gralloc/gr_buf_mgr.cpp
+++ b/gralloc/gr_buf_mgr.cpp
@@ -18,7 +18,7 @@
*/
/*
* Changes from Qualcomm Innovation Center are provided under the following license:
- * Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved.
+ * Copyright (c) 2022-2023, Qualcomm Innovation Center, Inc. All rights reserved.
* SPDX-License-Identifier: BSD-3-Clause-Clear
*/
@@ -281,7 +281,9 @@
void BufferManager::SetGrallocDebugProperties(gralloc::GrallocProperties props) {
allocator_->SetProperties(props);
- AdrenoMemInfo::GetInstance()->AdrenoSetProperties(props);
+ if (AdrenoMemInfo::GetInstance()) {
+ AdrenoMemInfo::GetInstance()->AdrenoSetProperties(props);
+ }
}
Error BufferManager::FreeBuffer(std::shared_ptr<Buffer> buf) {
diff --git a/gralloc/gr_utils.cpp b/gralloc/gr_utils.cpp
index 39722a9..9621d71 100644
--- a/gralloc/gr_utils.cpp
+++ b/gralloc/gr_utils.cpp
@@ -1388,6 +1388,9 @@
}
AdrenoMemInfo *adreno_mem_info = AdrenoMemInfo::GetInstance();
+ if (!adreno_mem_info) {
+ return -ENOTSUP;
+ }
graphics_metadata->size = adreno_mem_info->AdrenoGetMetadataBlobSize();
uint64_t adreno_usage = info.usage;
// If gralloc disables UBWC based on any of the checks,