L4Re Operating System Framework – Interface and Usage Documentation
Loading...
Searching...
No Matches
device.h
1/*
2 * Copyright (C) 2018-2020 Kernkonzept GmbH.
3 * Author(s): Sarah Hoffmann <sarah.hoffmann@kernkonzept.com>
4 *
5 * This file is distributed under the terms of the GNU General Public
6 * License, version 2. Please see the COPYING-GPL-2 file for details.
7 */
8#pragma once
9
10#include <l4/cxx/ref_ptr>
11#include <l4/cxx/string>
12#include <l4/re/dataspace>
13#include <l4/re/dma_space>
14
15#include <l4/libblock-device/errand.h>
16#include <l4/libblock-device/types.h>
17#include <l4/libblock-device/request_queue.h>
18
19namespace Block_device {
20
21struct Device : public cxx::Ref_obj
22{
23 virtual ~Device() = 0;
24
26 virtual bool is_read_only() const = 0;
28 virtual bool match_hid(cxx::String const &hid) const = 0;
30 virtual l4_uint64_t capacity() const = 0;
32 virtual l4_size_t sector_size() const = 0;
34 virtual l4_size_t max_size() const = 0;
36 virtual unsigned max_segments() const = 0;
37
46 virtual Request_queue *request_queue() = 0;
47
49 virtual void reset() = 0;
50
52 virtual int dma_map(Block_device::Mem_region *region, l4_addr_t offset,
55
57 virtual int dma_unmap(L4Re::Dma_space::Dma_addr phys, l4_size_t num_sectors,
59
74 virtual int inout_data(l4_uint64_t sector,
75 Block_device::Inout_block const &blocks,
76 Block_device::Inout_callback const &cb,
78
89 virtual int flush(Block_device::Inout_callback const &cb) = 0;
90
92 virtual void start_device_scan(Block_device::Errand::Callback const &callback) = 0;
93};
94
95inline Device::~Device() = default;
96
97template <typename DEV>
98class Device_with_request_queue : public DEV
99{
100public:
101 Request_queue *request_queue() override
102 { return &_request_queue; }
103
104private:
105 Simple_request_queue _request_queue;
106};
107
112{
113 struct Discard_info
114 {
115 unsigned max_discard_sectors = 0;
116 unsigned max_discard_seg = 0;
117 unsigned discard_sector_alignment = 1;
118 unsigned max_write_zeroes_sectors = 0;
119 unsigned max_write_zeroes_seg = 0;
120 bool write_zeroes_may_unmap = false;
121 };
122
123 virtual Discard_info discard_info() const = 0;
124
126 virtual int discard(l4_uint64_t offset,
127 Block_device::Inout_block const &blocks,
128 Block_device::Inout_callback const &cb, bool discard) = 0;
129
130protected:
131 ~Device_discard_feature() = default;
132};
133
134} // name space
l4_uint64_t Dma_addr
Data type for DMA addresses.
Definition dma_space:70
Direction
Direction of the DMA transfers.
Definition dma_space:76
Region of driver memory, that shall be managed locally.
Definition l4virtio:434
Allocation free string class with explicit length field.
Definition string:42
Dataspace interface.
unsigned int l4_size_t
Unsigned size type.
Definition l4int.h:35
unsigned long l4_addr_t
Address type.
Definition l4int.h:45
unsigned long long l4_uint64_t
Unsigned 64bit value.
Definition l4int.h:42
Partial interface for devices that offer discard functionality.
Definition device.h:112
virtual int discard(l4_uint64_t offset, Block_device::Inout_block const &blocks, Block_device::Inout_callback const &cb, bool discard)=0
Issues one or more WRITE_ZEROES or DISCARD commands.
Description of an inout block to be sent to the device.
Definition types.h:68