hw/misc/mps2-fpgaio: Make number of LEDs configurable by board
[qemu/ar7.git] / include / hw / block / block.h
blobc172cbe65f15813077d62ddfab14ea83d05b832b
1 /*
2 * Common code for block device models
4 * Copyright (C) 2012 Red Hat, Inc.
5 * Copyright (c) 2003-2008 Fabrice Bellard
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 */
11 #ifndef HW_BLOCK_H
12 #define HW_BLOCK_H
14 #include "exec/hwaddr.h"
15 #include "qapi/qapi-types-block-core.h"
16 #include "hw/qdev-properties-system.h"
18 /* Configuration */
20 typedef struct BlockConf {
21 BlockBackend *blk;
22 uint32_t physical_block_size;
23 uint32_t logical_block_size;
24 uint32_t min_io_size;
25 uint32_t opt_io_size;
26 int32_t bootindex;
27 uint32_t discard_granularity;
28 /* geometry, not all devices use this */
29 uint32_t cyls, heads, secs;
30 uint32_t lcyls, lheads, lsecs;
31 OnOffAuto wce;
32 bool share_rw;
33 BlockdevOnError rerror;
34 BlockdevOnError werror;
35 } BlockConf;
37 static inline unsigned int get_physical_block_exp(BlockConf *conf)
39 unsigned int exp = 0, size;
41 for (size = conf->physical_block_size;
42 size > conf->logical_block_size;
43 size >>= 1) {
44 exp++;
47 return exp;
50 #define DEFINE_BLOCK_PROPERTIES_BASE(_state, _conf) \
51 DEFINE_PROP_BLOCKSIZE("logical_block_size", _state, \
52 _conf.logical_block_size), \
53 DEFINE_PROP_BLOCKSIZE("physical_block_size", _state, \
54 _conf.physical_block_size), \
55 DEFINE_PROP_SIZE32("min_io_size", _state, _conf.min_io_size, 0), \
56 DEFINE_PROP_SIZE32("opt_io_size", _state, _conf.opt_io_size, 0), \
57 DEFINE_PROP_SIZE32("discard_granularity", _state, \
58 _conf.discard_granularity, -1), \
59 DEFINE_PROP_ON_OFF_AUTO("write-cache", _state, _conf.wce, \
60 ON_OFF_AUTO_AUTO), \
61 DEFINE_PROP_BOOL("share-rw", _state, _conf.share_rw, false)
63 #define DEFINE_BLOCK_PROPERTIES(_state, _conf) \
64 DEFINE_PROP_DRIVE("drive", _state, _conf.blk), \
65 DEFINE_BLOCK_PROPERTIES_BASE(_state, _conf)
67 #define DEFINE_BLOCK_CHS_PROPERTIES(_state, _conf) \
68 DEFINE_PROP_UINT32("cyls", _state, _conf.cyls, 0), \
69 DEFINE_PROP_UINT32("heads", _state, _conf.heads, 0), \
70 DEFINE_PROP_UINT32("secs", _state, _conf.secs, 0), \
71 DEFINE_PROP_UINT32("lcyls", _state, _conf.lcyls, 0), \
72 DEFINE_PROP_UINT32("lheads", _state, _conf.lheads, 0), \
73 DEFINE_PROP_UINT32("lsecs", _state, _conf.lsecs, 0)
75 #define DEFINE_BLOCK_ERROR_PROPERTIES(_state, _conf) \
76 DEFINE_PROP_BLOCKDEV_ON_ERROR("rerror", _state, _conf.rerror, \
77 BLOCKDEV_ON_ERROR_AUTO), \
78 DEFINE_PROP_BLOCKDEV_ON_ERROR("werror", _state, _conf.werror, \
79 BLOCKDEV_ON_ERROR_AUTO)
81 /* Backend access helpers */
83 bool blk_check_size_and_read_all(BlockBackend *blk, void *buf, hwaddr size,
84 Error **errp);
86 /* Configuration helpers */
88 bool blkconf_geometry(BlockConf *conf, int *trans,
89 unsigned cyls_max, unsigned heads_max, unsigned secs_max,
90 Error **errp);
91 bool blkconf_blocksizes(BlockConf *conf, Error **errp);
92 bool blkconf_apply_backend_options(BlockConf *conf, bool readonly,
93 bool resizable, Error **errp);
95 /* Hard disk geometry */
97 void hd_geometry_guess(BlockBackend *blk,
98 uint32_t *pcyls, uint32_t *pheads, uint32_t *psecs,
99 int *ptrans);
100 int hd_bios_chs_auto_trans(uint32_t cyls, uint32_t heads, uint32_t secs);
102 #endif