1
2
3
4
5
6
7
8
9
10
11#ifndef HW_BLOCK_COMMON_H
12#define HW_BLOCK_COMMON_H
13
14#include "qemu-common.h"
15
16
17
18typedef struct BlockConf {
19 BlockBackend *blk;
20 uint16_t physical_block_size;
21 uint16_t logical_block_size;
22 uint16_t min_io_size;
23 uint32_t opt_io_size;
24 int32_t bootindex;
25 uint32_t discard_granularity;
26
27 uint32_t cyls, heads, secs;
28} BlockConf;
29
30static inline unsigned int get_physical_block_exp(BlockConf *conf)
31{
32 unsigned int exp = 0, size;
33
34 for (size = conf->physical_block_size;
35 size > conf->logical_block_size;
36 size >>= 1) {
37 exp++;
38 }
39
40 return exp;
41}
42
43#define DEFINE_BLOCK_PROPERTIES(_state, _conf) \
44 DEFINE_PROP_DRIVE("drive", _state, _conf.blk), \
45 DEFINE_PROP_BLOCKSIZE("logical_block_size", _state, \
46 _conf.logical_block_size), \
47 DEFINE_PROP_BLOCKSIZE("physical_block_size", _state, \
48 _conf.physical_block_size), \
49 DEFINE_PROP_UINT16("min_io_size", _state, _conf.min_io_size, 0), \
50 DEFINE_PROP_UINT32("opt_io_size", _state, _conf.opt_io_size, 0), \
51 DEFINE_PROP_UINT32("discard_granularity", _state, \
52 _conf.discard_granularity, -1)
53
54#define DEFINE_BLOCK_CHS_PROPERTIES(_state, _conf) \
55 DEFINE_PROP_UINT32("cyls", _state, _conf.cyls, 0), \
56 DEFINE_PROP_UINT32("heads", _state, _conf.heads, 0), \
57 DEFINE_PROP_UINT32("secs", _state, _conf.secs, 0)
58
59
60
61void blkconf_serial(BlockConf *conf, char **serial);
62void blkconf_geometry(BlockConf *conf, int *trans,
63 unsigned cyls_max, unsigned heads_max, unsigned secs_max,
64 Error **errp);
65void blkconf_blocksizes(BlockConf *conf);
66
67
68
69void hd_geometry_guess(BlockBackend *blk,
70 uint32_t *pcyls, uint32_t *pheads, uint32_t *psecs,
71 int *ptrans);
72int hd_bios_chs_auto_trans(uint32_t cyls, uint32_t heads, uint32_t secs);
73
74#endif
75