Markus Armbruster | 9db1c0f | 2012-07-10 11:12:31 +0200 | [diff] [blame] | 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 | |
| 11 | #ifndef HW_BLOCK_COMMON_H |
| 12 | #define HW_BLOCK_COMMON_H |
| 13 | |
| 14 | #include "qemu-common.h" |
| 15 | |
Markus Armbruster | 31e404f | 2012-07-11 15:08:36 +0200 | [diff] [blame] | 16 | /* Configuration */ |
| 17 | |
| 18 | typedef struct BlockConf { |
| 19 | BlockDriverState *bs; |
| 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 | /* geometry, not all devices use this */ |
| 27 | uint32_t cyls, heads, secs; |
| 28 | } BlockConf; |
| 29 | |
| 30 | static 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.bs), \ |
| 45 | DEFINE_PROP_BLOCKSIZE("logical_block_size", _state, \ |
| 46 | _conf.logical_block_size, 512), \ |
| 47 | DEFINE_PROP_BLOCKSIZE("physical_block_size", _state, \ |
| 48 | _conf.physical_block_size, 512), \ |
| 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_INT32("bootindex", _state, _conf.bootindex, -1), \ |
| 52 | DEFINE_PROP_UINT32("discard_granularity", _state, \ |
| 53 | _conf.discard_granularity, 0) |
| 54 | |
| 55 | #define DEFINE_BLOCK_CHS_PROPERTIES(_state, _conf) \ |
| 56 | DEFINE_PROP_UINT32("cyls", _state, _conf.cyls, 0), \ |
| 57 | DEFINE_PROP_UINT32("heads", _state, _conf.heads, 0), \ |
| 58 | DEFINE_PROP_UINT32("secs", _state, _conf.secs, 0) |
| 59 | |
Markus Armbruster | 911525d | 2012-07-11 15:08:37 +0200 | [diff] [blame] | 60 | /* Configuration helpers */ |
| 61 | |
| 62 | void blkconf_serial(BlockConf *conf, char **serial); |
Markus Armbruster | b7eb0c9 | 2012-07-11 15:08:39 +0200 | [diff] [blame] | 63 | int blkconf_geometry(BlockConf *conf, int *trans, |
| 64 | unsigned cyls_max, unsigned heads_max, unsigned secs_max); |
Markus Armbruster | 31e404f | 2012-07-11 15:08:36 +0200 | [diff] [blame] | 65 | |
Markus Armbruster | 9db1c0f | 2012-07-10 11:12:31 +0200 | [diff] [blame] | 66 | /* Hard disk geometry */ |
| 67 | |
Markus Armbruster | 2b58495 | 2012-07-10 11:12:50 +0200 | [diff] [blame] | 68 | #define BIOS_ATA_TRANSLATION_AUTO 0 |
| 69 | #define BIOS_ATA_TRANSLATION_NONE 1 |
| 70 | #define BIOS_ATA_TRANSLATION_LBA 2 |
| 71 | #define BIOS_ATA_TRANSLATION_LARGE 3 |
| 72 | #define BIOS_ATA_TRANSLATION_RECHS 4 |
| 73 | |
Markus Armbruster | 9db1c0f | 2012-07-10 11:12:31 +0200 | [diff] [blame] | 74 | void hd_geometry_guess(BlockDriverState *bs, |
Markus Armbruster | 1f24d7b | 2012-07-10 11:12:41 +0200 | [diff] [blame] | 75 | uint32_t *pcyls, uint32_t *pheads, uint32_t *psecs, |
Markus Armbruster | e2f3dc2 | 2012-07-10 11:12:37 +0200 | [diff] [blame] | 76 | int *ptrans); |
Markus Armbruster | 2adc99b | 2012-07-10 11:12:53 +0200 | [diff] [blame] | 77 | int hd_bios_chs_auto_trans(uint32_t cyls, uint32_t heads, uint32_t secs); |
Markus Armbruster | 9db1c0f | 2012-07-10 11:12:31 +0200 | [diff] [blame] | 78 | |
| 79 | #endif |