]>
Commit | Line | Data |
---|---|---|
9db1c0f7 MA |
1 | /* |
2 | * Common code for block device models | |
3 | * | |
4 | * Copyright (C) 2012 Red Hat, Inc. | |
5 | * Copyright (c) 2003-2008 Fabrice Bellard | |
6 | * | |
7 | * This work is licensed under the terms of the GNU GPL, version 2 or | |
8 | * later. See the COPYING file in the top-level directory. | |
9 | */ | |
10 | ||
121d0712 MA |
11 | #ifndef HW_BLOCK_H |
12 | #define HW_BLOCK_H | |
9db1c0f7 MA |
13 | |
14 | #include "qemu-common.h" | |
9af23989 | 15 | #include "qapi/qapi-types-block-core.h" |
9db1c0f7 | 16 | |
31e404f4 MA |
17 | /* Configuration */ |
18 | ||
19 | typedef struct BlockConf { | |
4be74634 | 20 | BlockBackend *blk; |
31e404f4 MA |
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 | /* geometry, not all devices use this */ | |
28 | uint32_t cyls, heads, secs; | |
f6166a06 | 29 | OnOffAuto wce; |
dabd18f6 | 30 | bool share_rw; |
8c398252 KW |
31 | BlockdevOnError rerror; |
32 | BlockdevOnError werror; | |
31e404f4 MA |
33 | } BlockConf; |
34 | ||
35 | static inline unsigned int get_physical_block_exp(BlockConf *conf) | |
36 | { | |
37 | unsigned int exp = 0, size; | |
38 | ||
39 | for (size = conf->physical_block_size; | |
40 | size > conf->logical_block_size; | |
41 | size >>= 1) { | |
42 | exp++; | |
43 | } | |
44 | ||
45 | return exp; | |
46 | } | |
47 | ||
48 | #define DEFINE_BLOCK_PROPERTIES(_state, _conf) \ | |
4be74634 | 49 | DEFINE_PROP_DRIVE("drive", _state, _conf.blk), \ |
31e404f4 | 50 | DEFINE_PROP_BLOCKSIZE("logical_block_size", _state, \ |
0eb28a42 | 51 | _conf.logical_block_size), \ |
31e404f4 | 52 | DEFINE_PROP_BLOCKSIZE("physical_block_size", _state, \ |
0eb28a42 | 53 | _conf.physical_block_size), \ |
31e404f4 MA |
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), \ | |
31e404f4 | 56 | DEFINE_PROP_UINT32("discard_granularity", _state, \ |
f6166a06 | 57 | _conf.discard_granularity, -1), \ |
dabd18f6 KW |
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) | |
31e404f4 MA |
61 | |
62 | #define DEFINE_BLOCK_CHS_PROPERTIES(_state, _conf) \ | |
63 | DEFINE_PROP_UINT32("cyls", _state, _conf.cyls, 0), \ | |
64 | DEFINE_PROP_UINT32("heads", _state, _conf.heads, 0), \ | |
65 | DEFINE_PROP_UINT32("secs", _state, _conf.secs, 0) | |
66 | ||
8c398252 KW |
67 | #define DEFINE_BLOCK_ERROR_PROPERTIES(_state, _conf) \ |
68 | DEFINE_PROP_BLOCKDEV_ON_ERROR("rerror", _state, _conf.rerror, \ | |
69 | BLOCKDEV_ON_ERROR_AUTO), \ | |
70 | DEFINE_PROP_BLOCKDEV_ON_ERROR("werror", _state, _conf.werror, \ | |
71 | BLOCKDEV_ON_ERROR_AUTO) | |
72 | ||
911525db MA |
73 | /* Configuration helpers */ |
74 | ||
75 | void blkconf_serial(BlockConf *conf, char **serial); | |
9d3b1551 | 76 | bool blkconf_geometry(BlockConf *conf, int *trans, |
5ff5efb4 FZ |
77 | unsigned cyls_max, unsigned heads_max, unsigned secs_max, |
78 | Error **errp); | |
0eb28a42 | 79 | void blkconf_blocksizes(BlockConf *conf); |
9d3b1551 | 80 | bool blkconf_apply_backend_options(BlockConf *conf, bool readonly, |
a17c17a2 | 81 | bool resizable, Error **errp); |
31e404f4 | 82 | |
9db1c0f7 MA |
83 | /* Hard disk geometry */ |
84 | ||
4be74634 | 85 | void hd_geometry_guess(BlockBackend *blk, |
1f24d7b4 | 86 | uint32_t *pcyls, uint32_t *pheads, uint32_t *psecs, |
e2f3dc2b | 87 | int *ptrans); |
2adc99b2 | 88 | int hd_bios_chs_auto_trans(uint32_t cyls, uint32_t heads, uint32_t secs); |
9db1c0f7 MA |
89 | |
90 | #endif |