2017-01-12 02:37:35 +01:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (C) 2017 The Android Open Source Project
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2019-06-19 23:14:57 +02:00
|
|
|
#include <linux/usb/functionfs.h>
|
|
|
|
|
2022-07-13 02:37:54 +02:00
|
|
|
#include <liburing.h>
|
2017-01-12 02:37:35 +01:00
|
|
|
#include <atomic>
|
|
|
|
#include <condition_variable>
|
2022-07-13 02:37:54 +02:00
|
|
|
#include <memory>
|
2017-01-12 02:37:35 +01:00
|
|
|
#include <mutex>
|
2018-05-08 00:14:47 +02:00
|
|
|
#include <vector>
|
2017-01-12 02:37:35 +01:00
|
|
|
|
2018-08-22 00:44:49 +02:00
|
|
|
#include <android-base/unique_fd.h>
|
2017-07-18 23:07:57 +02:00
|
|
|
#include <asyncio/AsyncIO.h>
|
|
|
|
|
|
|
|
struct aio_block {
|
|
|
|
std::vector<struct iocb> iocb;
|
|
|
|
std::vector<struct iocb*> iocbs;
|
|
|
|
std::vector<struct io_event> events;
|
|
|
|
aio_context_t ctx;
|
|
|
|
int num_submitted;
|
|
|
|
int fd;
|
|
|
|
};
|
|
|
|
|
2022-07-13 02:37:54 +02:00
|
|
|
int getMaxPacketSize(int ffs_fd);
|
|
|
|
|
|
|
|
enum class AIOType { SYNC_IO, AIO, IO_URING };
|
2017-01-12 02:37:35 +01:00
|
|
|
|
2022-07-13 02:37:54 +02:00
|
|
|
struct usb_handle {
|
2017-01-12 02:37:35 +01:00
|
|
|
std::condition_variable notify;
|
|
|
|
std::mutex lock;
|
|
|
|
bool open_new_connection = true;
|
|
|
|
|
|
|
|
int (*write)(usb_handle* h, const void* data, int len);
|
2019-05-20 10:55:55 +02:00
|
|
|
int (*read)(usb_handle* h, void* data, int len, bool allow_partial);
|
2017-01-12 02:37:35 +01:00
|
|
|
void (*close)(usb_handle* h);
|
|
|
|
|
|
|
|
// FunctionFS
|
2018-08-22 00:44:49 +02:00
|
|
|
android::base::unique_fd control;
|
|
|
|
android::base::unique_fd bulk_out; // "out" from the host's perspective => source for adbd
|
|
|
|
android::base::unique_fd bulk_in; // "in" from the host's perspective => sink for adbd
|
2017-01-04 21:34:38 +01:00
|
|
|
|
2018-08-22 00:44:49 +02:00
|
|
|
// Access to these blocks is very not thread safe. Have one block for each of the
|
2017-07-18 23:07:57 +02:00
|
|
|
// read and write threads.
|
|
|
|
struct aio_block read_aiob;
|
|
|
|
struct aio_block write_aiob;
|
2018-05-21 23:22:43 +02:00
|
|
|
|
2022-07-13 02:37:54 +02:00
|
|
|
io_uring ring;
|
2018-05-21 23:22:43 +02:00
|
|
|
size_t io_size;
|
2022-07-13 02:37:54 +02:00
|
|
|
AIOType aio_type;
|
2017-01-12 02:37:35 +01:00
|
|
|
};
|
|
|
|
|
2022-07-13 02:37:54 +02:00
|
|
|
std::unique_ptr<usb_handle> create_usb_handle(unsigned num_bufs, unsigned io_size);
|