template <typename PhysIterType>

class FidlRequest

Defined at line 69 of file ../../src/devices/usb/lib/usb/include/usb/internal/request-fidl.h

FidlRequest is a wrapper around a fuchsia_hardware_usb_request::Request implementing common

functionality. Especially, FidlRequest keeps track of VMOs that were pinned upon PhysMap() and

unpins them upon destruction.

Public Methods

void FidlRequest<PhysIterType> ()

Defined at line 74 of file ../../src/devices/usb/lib/usb/include/usb/internal/request-fidl.h

void FidlRequest<PhysIterType> (EndpointType ep_type)

Defined at line 75 of file ../../src/devices/usb/lib/usb/include/usb/internal/request-fidl.h

void FidlRequest<PhysIterType> (fuchsia_hardware_usb_request::Request request)

Defined at line 93 of file ../../src/devices/usb/lib/usb/include/usb/internal/request-fidl.h

void FidlRequest<PhysIterType> (FidlRequest<PhysIterType> && request)

Disallow copy and assign, allow move.

Defined at line 97 of file ../../src/devices/usb/lib/usb/include/usb/internal/request-fidl.h

FidlRequest<PhysIterType> & operator= (FidlRequest<PhysIterType> && request)

Defined at line 98 of file ../../src/devices/usb/lib/usb/include/usb/internal/request-fidl.h

void FidlRequest<PhysIterType> (const FidlRequest<PhysIterType> & )

Defined at line 99 of file ../../src/devices/usb/lib/usb/include/usb/internal/request-fidl.h

FidlRequest<PhysIterType> & operator= (const FidlRequest<PhysIterType> & )

Defined at line 100 of file ../../src/devices/usb/lib/usb/include/usb/internal/request-fidl.h

void ~FidlRequest<PhysIterType> ()

Defined at line 102 of file ../../src/devices/usb/lib/usb/include/usb/internal/request-fidl.h

FidlRequest<PhysIterType> & set_control (fuchsia_hardware_usb_descriptor::UsbSetup setup)

Defined at line 104 of file ../../src/devices/usb/lib/usb/include/usb/internal/request-fidl.h

FidlRequest<PhysIterType> & set_bulk ()

Defined at line 109 of file ../../src/devices/usb/lib/usb/include/usb/internal/request-fidl.h

FidlRequest<PhysIterType> & set_isochronous (uint64_t frame_id)

Defined at line 114 of file ../../src/devices/usb/lib/usb/include/usb/internal/request-fidl.h

FidlRequest<PhysIterType> & set_interrupt ()

Defined at line 119 of file ../../src/devices/usb/lib/usb/include/usb/internal/request-fidl.h

FidlRequest<PhysIterType> & add_vmo_id (uint64_t vmo_id, size_t size, size_t offset)

Defined at line 125 of file ../../src/devices/usb/lib/usb/include/usb/internal/request-fidl.h

FidlRequest<PhysIterType> & add_data (std::vector<uint8_t> data, size_t size, size_t offset)

Defined at line 137 of file ../../src/devices/usb/lib/usb/include/usb/internal/request-fidl.h

FidlRequest<PhysIterType> & clear_buffers ()

Defined at line 149 of file ../../src/devices/usb/lib/usb/include/usb/internal/request-fidl.h

FidlRequest<PhysIterType> & reset_buffers (const get_mapped_func_t & get_mapped)

Defined at line 159 of file ../../src/devices/usb/lib/usb/include/usb/internal/request-fidl.h

std::vector<size_t> CopyTo (size_t offset, const void * buffer, size_t size, const get_mapped_func_t & get_mapped)

CopyTo: tries to copy `size` bytes from `buffer` to contiguous `request` buffers from

`offset`. Returns the number of bytes copied for each buffer.

Cache management is the responsibility of the user. See `CachedCopyTo` below for a

version of this method that performs cache management on the user's behalf.

Defined at line 183 of file ../../src/devices/usb/lib/usb/include/usb/internal/request-fidl.h

std::vector<size_t> CopyTo (size_t offset, std::span<const uint8_t> buffer, const get_mapped_func_t & get_mapped)

Defined at line 255 of file ../../src/devices/usb/lib/usb/include/usb/internal/request-fidl.h

std::vector<size_t> CopyFrom (size_t offset, void * buffer, size_t size, const get_mapped_func_t & get_mapped)

CopyFrom: tries to copy `size` bytes from `request` (starting from `offset`) to `buffer`.

Returns the number of bytes copied for each buffer.

Cache management is the responsibility of the user. See `CachedCopyFrom` below for a

version of this method that performs cache management on the user's behalf.

Defined at line 265 of file ../../src/devices/usb/lib/usb/include/usb/internal/request-fidl.h

std::vector<size_t> CopyFrom (size_t offset, std::span<uint8_t> buffer, const get_mapped_func_t & get_mapped)

Defined at line 312 of file ../../src/devices/usb/lib/usb/include/usb/internal/request-fidl.h

zx_status_t CacheFlushInvalidate (get_mapped_func_t get_mapped)

About CacheFlush and CacheFlushInvalidate: CacheFlush or CacheFlush invalidate MUST always be

called after data is written to the VMO and before the data is processed on schedule (see

comment in endpoint.fidl on `RequestQueue`).

CacheFlush should be called for operations where data is to be written out, but not read in

and CacheFlushInvalidate should be called for operations where data needs to be read in.

CacheFlush and CacheFlushInvalidate flush and invalidate cache for all buffer regions of a

request.

Defined at line 324 of file ../../src/devices/usb/lib/usb/include/usb/internal/request-fidl.h

zx_status_t CacheFlushInvalidate (get_mapped_func_t get_mapped, size_t offset, size_t size)

Defined at line 329 of file ../../src/devices/usb/lib/usb/include/usb/internal/request-fidl.h

zx_status_t CacheFlush (get_mapped_func_t get_mapped)

Defined at line 334 of file ../../src/devices/usb/lib/usb/include/usb/internal/request-fidl.h

zx_status_t CacheFlush (get_mapped_func_t get_mapped, size_t offset, size_t size)

Defined at line 338 of file ../../src/devices/usb/lib/usb/include/usb/internal/request-fidl.h

zx::result<std::vector<size_t>> CachedCopyTo (size_t offset, const void * buffer, size_t size, const get_mapped_func_t & get_mapped)

Similar to `CopyTo`, copies `size` bytes from `buffer` to contiguous request buffers starting

at `offset`. To ensure cache coherency, this method flushes the cache after copying.

Only the range `[offset, offset + size)` is flushed.

For multi-part writes into a request buffer (such as copying a header followed by payload

data), use `CopyTo` for intermediate writes and only call `CachedCopyTo` on the last

write (or use an explicit `CacheFlush` at the end) to avoid flushing cache lines multiple

times.

Parameters:

* offset: Byte offset into the request buffers to start writing.

* buffer: Source buffer to read data from.

* size: Number of bytes to copy.

* get_mapped: Callback to resolve virtual mapping information for buffer tags.

Returns a vector of byte counts copied to each request buffer on success, or an error status

if `CacheFlush` fails, mapping resolution fails, or `offset` is out of bounds

(`ZX_ERR_OUT_OF_RANGE`).

Defined at line 360 of file ../../src/devices/usb/lib/usb/include/usb/internal/request-fidl.h

zx::result<std::vector<size_t>> CachedCopyFrom (size_t offset, void * buffer, size_t size, const get_mapped_func_t & get_mapped)

Similar to `CopyFrom`, copies `size` bytes from contiguous request buffers starting at

`offset` into `buffer`. To ensure cache coherency, this method invalidates the cache before

copying.

Only the range `[offset, offset + size)` is invalidated.

For multi-part reads from a request buffer (such as reading a header followed by payload

data), call `CachedCopyFrom` on the first read (or use an explicit `CacheFlushInvalidate`

before reading) and use `CopyFrom` for subsequent reads to avoid invalidating cache lines

multiple times.

Parameters:

* offset: Byte offset into the request buffers to start reading.

* buffer: Destination buffer to write data into.

* size: Number of bytes to copy.

* get_mapped: Callback to resolve virtual mapping information for buffer tags.

Returns a vector of byte counts copied from each request buffer on success, or an error status

if `CacheFlushInvalidate` fails, mapping resolution fails, or `offset` is out of bounds

(`ZX_ERR_OUT_OF_RANGE`).

Defined at line 396 of file ../../src/devices/usb/lib/usb/include/usb/internal/request-fidl.h

zx::result<std::vector<size_t>> CachedCopyTo (size_t offset, std::span<const uint8_t> buffer, const get_mapped_func_t & get_mapped)

Defined at line 411 of file ../../src/devices/usb/lib/usb/include/usb/internal/request-fidl.h

zx::result<std::vector<size_t>> CachedCopyFrom (size_t offset, std::span<uint8_t> buffer, const get_mapped_func_t & get_mapped)

Defined at line 416 of file ../../src/devices/usb/lib/usb/include/usb/internal/request-fidl.h

zx_status_t CacheHelper (const fuchsia_hardware_usb_request::BufferRegion & buffer, size_t offset_in_region, size_t flush_size, uint32_t options, const get_mapped_func_t & get_mapped)

CacheHelper flushes and invalidates cache for a slice of a specified buffer region.

Defined at line 422 of file ../../src/devices/usb/lib/usb/include/usb/internal/request-fidl.h

zx_status_t CacheRangeHelper (size_t offset, size_t size, uint32_t options, const get_mapped_func_t & get_mapped)

CacheRangeHelper iterates across scatter-gather `BufferRegion` segments in the request and

performs cache maintenance (flushing or invalidation) strictly on the byte slice

`[offset, offset + size)`.

The method tracks `cur_offset` across multiple contiguous buffer regions:

- If `cur_offset >= *d.size()`, the target slice starts in a subsequent region, so we subtract

the region's size from `cur_offset` and continue.

- Once inside the target range, we compute `flush_size` as the minimum of remaining `todo`

bytes

and remaining bytes in the current region (`*d.size() - cur_offset`).

- After flushing the slice in the current region via `CacheHelper`, `cur_offset` is reset to 0

for any subsequent regions until all `todo` bytes are processed.

Defined at line 457 of file ../../src/devices/usb/lib/usb/include/usb/internal/request-fidl.h

zx_status_t PhysMap (const zx::bti & bti)

Pins VMOs if needed. For

- fuchsia_hardware_usb_request::Buffer::Tag::kVmoId -- Uses preregistered VMO. Does nothing.

- fuchsia_hardware_usb_request::Buffer::Tag::kVmo -- Pins VMO.

- fuchsia_hardware_usb_request::Buffer::Tag::kData -- Creates, maps, pins, VMO. Copies data

to VMO. (Unmapped and unpinned on

Unpin()).

Defined at line 496 of file ../../src/devices/usb/lib/usb/include/usb/internal/request-fidl.h

zx_status_t Unpin ()

Unpins VMOs pinned by PhysMap.

Defined at line 574 of file ../../src/devices/usb/lib/usb/include/usb/internal/request-fidl.h

fuchsia_hardware_usb_request::Request * operator-> ()

Defined at line 600 of file ../../src/devices/usb/lib/usb/include/usb/internal/request-fidl.h

const fuchsia_hardware_usb_request::Request * operator-> ()

Defined at line 601 of file ../../src/devices/usb/lib/usb/include/usb/internal/request-fidl.h

PhysIterType phys_iter (size_t idx, size_t max_length)

Gets a PhysIterType for the buffer at request.data()->at(idx). PhysIterTypes return a

std::pair

<zx

_paddr_t, size_t> on iteration. For template specialization, see the public

headers outside the internal namespace.

const fuchsia_hardware_usb_request::Request & request ()

Defined at line 602 of file ../../src/devices/usb/lib/usb/include/usb/internal/request-fidl.h

fuchsia_hardware_usb_request::Request take_request ()

Ensures any removal of `request` is intentional and `Unpin` is called.

Defined at line 604 of file ../../src/devices/usb/lib/usb/include/usb/internal/request-fidl.h

size_t length ()

Returns the total length of all data in the request. Saves to a variable for future use.

Defined at line 609 of file ../../src/devices/usb/lib/usb/include/usb/internal/request-fidl.h

size_t capacity (const get_mapped_func_t & get_mapped)

Returns the total capacity of all buffers in the request.

Defined at line 622 of file ../../src/devices/usb/lib/usb/include/usb/internal/request-fidl.h