summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2023-07-07 05:23:35 +0000
committerAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2023-07-07 05:23:35 +0000
commitd1126a646b29c66c20eb197d19660e45bab471a5 (patch)
tree9ea1bb6ed81be8b87ddd0777540f98719d6293b2
parent76fdbe8bb68d08ea45b0db81aaba3f702eeda2ba (diff)
parent6867a1bd0b6eb85560333bf7d621c13dd18b7453 (diff)
downloadlibdmabufheap-android14-mainline-uwb-release.tar.gz
Change-Id: I152931e7fbb212ebe77839a410ea6abad78f4609
-rw-r--r--Android.bp1
-rw-r--r--BufferAllocator.cpp20
-rw-r--r--OWNERS4
-rw-r--r--PREUPLOAD.cfg5
-rw-r--r--include/BufferAllocator/BufferAllocator.h12
-rw-r--r--tests/TEST_MAPPING2
6 files changed, 39 insertions, 5 deletions
diff --git a/Android.bp b/Android.bp
index 021c265..b0b01fe 100644
--- a/Android.bp
+++ b/Android.bp
@@ -52,7 +52,6 @@ cc_library {
static_libs: [
"libbase",
"libion",
- "libutils",
],
shared_libs: [
"liblog",
diff --git a/BufferAllocator.cpp b/BufferAllocator.cpp
index 6dc3f68..a360cfd 100644
--- a/BufferAllocator.cpp
+++ b/BufferAllocator.cpp
@@ -28,6 +28,7 @@
#include <sys/types.h>
#include <unistd.h>
+#include <mutex>
#include <shared_mutex>
#include <string>
#include <unordered_set>
@@ -224,9 +225,24 @@ int BufferAllocator::DmabufAlloc(const std::string& heap_name, size_t len) {
return ret;
}
+ if (heap_data.fd >= 0) {
+ if (DmabufSetName(heap_data.fd, heap_name))
+ PLOG(WARNING) << "Unable to name DMA buffer for: " << heap_name;
+ }
+
return heap_data.fd;
}
+int BufferAllocator::DmabufSetName(unsigned int dmabuf_fd, const std::string& name) {
+ /* dma_buf_set_name truncates instead of returning an error */
+ if (name.length() > DMA_BUF_NAME_LEN) {
+ errno = ENAMETOOLONG;
+ return -1;
+ }
+
+ return TEMP_FAILURE_RETRY(ioctl(dmabuf_fd, DMA_BUF_SET_NAME_B, name.c_str()));
+}
+
int BufferAllocator::IonAlloc(const std::string& heap_name, size_t len,
unsigned int heap_flags, size_t legacy_align) {
IonHeapConfig heap_config;
@@ -324,7 +340,7 @@ int BufferAllocator::DoSync(unsigned int dmabuf_fd, bool start, SyncType sync_ty
int BufferAllocator::CpuSyncStart(unsigned int dmabuf_fd, SyncType sync_type,
const CustomCpuSyncLegacyIon& legacy_ion_cpu_sync_custom,
void *legacy_ion_custom_data) {
- int ret = DoSync(dmabuf_fd, true /* start */, sync_type, legacy_ion_cpu_sync_custom,
+ int ret = DoSync(dmabuf_fd, true, sync_type, legacy_ion_cpu_sync_custom,
legacy_ion_custom_data);
if (ret) PLOG(ERROR) << "CpuSyncStart() failure";
@@ -334,7 +350,7 @@ int BufferAllocator::CpuSyncStart(unsigned int dmabuf_fd, SyncType sync_type,
int BufferAllocator::CpuSyncEnd(unsigned int dmabuf_fd, SyncType sync_type,
const CustomCpuSyncLegacyIon& legacy_ion_cpu_sync_custom,
void* legacy_ion_custom_data) {
- int ret = DoSync(dmabuf_fd, false /* start */, sync_type, legacy_ion_cpu_sync_custom,
+ int ret = DoSync(dmabuf_fd, false, sync_type, legacy_ion_cpu_sync_custom,
legacy_ion_custom_data);
if (ret) PLOG(ERROR) << "CpuSyncEnd() failure";
diff --git a/OWNERS b/OWNERS
new file mode 100644
index 0000000..6999309
--- /dev/null
+++ b/OWNERS
@@ -0,0 +1,4 @@
+# Bug component: 356484
+tjmercier@google.com
+surenb@google.com
+kaleshsingh@google.com \ No newline at end of file
diff --git a/PREUPLOAD.cfg b/PREUPLOAD.cfg
new file mode 100644
index 0000000..c8dbf77
--- /dev/null
+++ b/PREUPLOAD.cfg
@@ -0,0 +1,5 @@
+[Builtin Hooks]
+clang_format = true
+
+[Builtin Hooks Options]
+clang_format = --commit ${PREUPLOAD_COMMIT} --style file --extensions c,h,cc,cpp
diff --git a/include/BufferAllocator/BufferAllocator.h b/include/BufferAllocator/BufferAllocator.h
index edc3143..95ffdf5 100644
--- a/include/BufferAllocator/BufferAllocator.h
+++ b/include/BufferAllocator/BufferAllocator.h
@@ -118,7 +118,7 @@ class BufferAllocator {
* For a legacy ion interface, syncs a shared dmabuf fd with memory either using
* ION_IOC_SYNC ioctl or using callback @legacy_ion_cpu_sync if specified. For
* non-legacy ION and dmabuf heap interfaces, DMA_BUF_IOCTL_SYNC is used.
- * @fd: dmabuf fd. When the legacy version of ion is in use and a callback
+ * @dmabuf_fd: dmabuf fd. When the legacy version of ion is in use and a callback
* function is supplied, this is passed as the second argument to legacy_ion_cpu_sync.
* @sync_type: specifies if the sync is for read, write or read/write.
* @legacy_ion_cpu_sync: optional callback for legacy ion interfaces. If
@@ -173,6 +173,16 @@ class BufferAllocator {
*/
static bool CheckIonSupport();
+ /**
+ * Set the name of a dma buffer.
+ *
+ * @dmabuf_fd: dmabuf file descriptor.
+ * @name: The name for the dmabuf. Length should not exceed DMA_BUF_NAME_LEN.
+ *
+ * @return Returns 0 on success, otherwise -1 and sets errno.
+ */
+ static int DmabufSetName(unsigned int dmabuf_fd, const std::string& name);
+
private:
int OpenDmabufHeap(const std::string& name);
void QueryIonHeaps();
diff --git a/tests/TEST_MAPPING b/tests/TEST_MAPPING
index 5bdb1d3..fe05283 100644
--- a/tests/TEST_MAPPING
+++ b/tests/TEST_MAPPING
@@ -4,7 +4,7 @@
"name": "dmabufheap-unit-tests"
}
],
- "hwasan-postsubmit": [
+ "hwasan-presubmit": [
{
"name": "dmabufheap-unit-tests"
}