1
2
3
4
5
6
7
8
9
10
11#ifndef HW_BLOCK_H
12#define HW_BLOCK_H
13
14#include "exec/hwaddr.h"
15#include "qapi/qapi-types-block-core.h"
16
17
18
19typedef struct BlockConf {
20 BlockBackend *blk;
21 uint16_t physical_block_size;
22 uint16_t logical_block_size;
23 uint16_t min_io_size;
24 uint32_t opt_io_size;
25 int32_t bootindex;
26 uint32_t discard_granularity;
27
28 uint32_t cyls, heads, secs;
29 uint32_t lcyls, lheads, lsecs;
30 OnOffAuto wce;
31 bool share_rw;
32 BlockdevOnError rerror;
33 BlockdevOnError werror;
34} BlockConf;
35
36static inline unsigned int get_physical_block_exp(BlockConf *conf)
37{
38 unsigned int exp = 0, size;
39
40 for (size = conf->physical_block_size;
41 size > conf->logical_block_size;
42 size >>= 1) {
43 exp++;
44 }
45
46 return exp;
47}
48
49#define DEFINE_BLOCK_PROPERTIES_BASE(_state, _conf) \
50 DEFINE_PROP_BLOCKSIZE("logical_block_size", _state, \
51 _conf.logical_block_size), \
52 DEFINE_PROP_BLOCKSIZE("physical_block_size", _state, \
53 _conf.physical_block_size), \
54 DEFINE_PROP_UINT16("min_io_size", _state, _conf.min_io_size, 0), \
55 DEFINE_PROP_UINT32("opt_io_size", _state, _conf.opt_io_size, 0), \
56 DEFINE_PROP_UINT32("discard_granularity", _state, \
57 _conf.discard_granularity, -1), \
58 DEFINE_PROP_ON_OFF_AUTO("write-cache", _state, _conf.wce, \
59 ON_OFF_AUTO_AUTO), \
60 DEFINE_PROP_BOOL("share-rw", _state, _conf.share_rw, false)
61
62#define DEFINE_BLOCK_PROPERTIES(_state, _conf) \
63 DEFINE_PROP_DRIVE("drive", _state, _conf.blk), \
64 DEFINE_BLOCK_PROPERTIES_BASE(_state, _conf)
65
66#define DEFINE_BLOCK_CHS_PROPERTIES(_state, _conf) \
67 DEFINE_PROP_UINT32("cyls", _state, _conf.cyls, 0), \
68 DEFINE_PROP_UINT32("heads", _state, _conf.heads, 0), \
69 DEFINE_PROP_UINT32("secs", _state, _conf.secs, 0), \
70 DEFINE_PROP_UINT32("lcyls", _state, _conf.lcyls, 0), \
71 DEFINE_PROP_UINT32("lheads", _state, _conf.lheads, 0), \
72 DEFINE_PROP_UINT32("lsecs", _state, _conf.lsecs, 0)
73
74#define DEFINE_BLOCK_ERROR_PROPERTIES(_state, _conf) \
75 DEFINE_PROP_BLOCKDEV_ON_ERROR("rerror", _state, _conf.rerror, \
76 BLOCKDEV_ON_ERROR_AUTO), \
77 DEFINE_PROP_BLOCKDEV_ON_ERROR("werror", _state, _conf.werror, \
78 BLOCKDEV_ON_ERROR_AUTO)
79
80
81
82bool blk_check_size_and_read_all(BlockBackend *blk, void *buf, hwaddr size,
83 Error **errp);
84
85
86
87bool blkconf_geometry(BlockConf *conf, int *trans,
88 unsigned cyls_max, unsigned heads_max, unsigned secs_max,
89 Error **errp);
90void blkconf_blocksizes(BlockConf *conf);
91bool blkconf_apply_backend_options(BlockConf *conf, bool readonly,
92 bool resizable, Error **errp);
93
94
95
96void hd_geometry_guess(BlockBackend *blk,
97 uint32_t *pcyls, uint32_t *pheads, uint32_t *psecs,
98 int *ptrans);
99int hd_bios_chs_auto_trans(uint32_t cyls, uint32_t heads, uint32_t secs);
100
101#endif
102