1 /*
2  * Copyright (C) 2023 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17 
18 #include <uefi/types.h>
19 
20 #ifndef __BLOCK_IO_PROTOCOL_H__
21 #define __BLOCK_IO_PROTOCOL_H__
22 
23 typedef struct EfiBlockIoMedia EfiBlockIoMedia;
24 typedef struct EfiBlockIoProtocol EfiBlockIoProtocol;
25 
26 struct EfiBlockIoProtocol {
27   uint64_t revision;
28   EfiBlockIoMedia *media;
29   EfiStatus (*reset)(EfiBlockIoProtocol *self, bool extended_verification);
30   EfiStatus (*read_blocks)(EfiBlockIoProtocol *self, uint32_t media_id,
31                            uint64_t lba, size_t buffer_size, void *buffer);
32   EfiStatus (*write_blocks)(EfiBlockIoProtocol *self, uint32_t media_id,
33                             uint64_t lba, size_t buffer_size,
34                             const void *buffer);
35   EfiStatus (*flush_blocks)(EfiBlockIoProtocol *self);
36 };
37 
38 struct EfiBlockIoMedia {
39   // present in rev1
40   uint32_t media_id;
41   bool removable_media;
42   bool media_present;
43   bool logical_partition;
44   bool read_only;
45   bool write_caching;
46   uint32_t block_size;
47   uint32_t io_align;
48   uint64_t last_block;
49 
50   // present in rev2
51   uint64_t lowest_aligned_lba;
52   uint32_t logical_blocks_per_physical_block;
53 
54   // present in rev3
55   uint32_t optimal_transfer_length_granularity;
56 };
57 
58 struct EfiBlockIoInterface {
59   EfiBlockIoProtocol protocol;
60   void *dev;
61   EfiBlockIoMedia media;
62   void *io_stack;
63 };
64 
65 #endif //__BLOCK_IO_PROTOCOL_H__
66