1 // Copyright 2018 The Fuchsia Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #pragma once
6 
7 #include <stddef.h>
8 #include <stdint.h>
9 
10 #include <ddk/protocol/block.h>
11 #include <zircon/listnode.h>
12 #include <zircon/types.h>
13 
14 namespace zxcrypt {
15 
16 // |extra_op_t| is the extra information placed in the tail end of |block_op_t|s queued against a
17 // |zxcrypt::Device|.
18 //
19 // TODO(aarongreen): This struct should be promoted into a class, with:
20 //  * methods to access the relevant fields
21 //  * DLL node state for a fbl::DoublyLinkedList
22 //  * Methods to encapsulate the setting/clearing/reading into the data field.
23 static_assert(sizeof(uintptr_t) <= sizeof(uint64_t), "uintptr_t > uint64_t");
24 struct extra_op_t {
25     // Used to link deferred block requests
26     list_node_t node;
27 
28     // Memory region to use for cryptographic transformations.
29     uint8_t* data;
30 
31     // The remaining are used to save fields of the original block request which may be altered
32     zx_handle_t vmo;
33     uint32_t length;
34     uint64_t offset_dev;
35     uint64_t offset_vmo;
36     block_impl_queue_callback completion_cb;
37     void* cookie;
38 
39     // Resets this structure to an initial state.
40     zx_status_t Init(block_op_t* block, block_impl_queue_callback completion_cb, void* cookie,
41                      size_t reserved_blocks);
42 };
43 
44 // Translates |block_op_t|s to |extra_op_t|s and vice versa.
45 extra_op_t* BlockToExtra(block_op_t* block, size_t op_size);
46 block_op_t* ExtraToBlock(extra_op_t* extra, size_t op_size);
47 
48 } // namespace zxcrypt
49