finish making SDR code big-endian aware

this is ugly because packed structures are not portable
This commit is contained in:
Duncan Laurie 2004-01-27 20:11:56 +00:00
parent e7c7d7d2e9
commit 0e5cbcd112
2 changed files with 260 additions and 73 deletions

View File

@ -124,35 +124,65 @@ struct sdr_get_rs {
struct sdr_record_compact_sensor { struct sdr_record_compact_sensor {
struct { struct {
unsigned char owner_id; unsigned char owner_id;
unsigned char lun : 2, /* sensor owner lun */ #if WORDS_BIGENDIAN
__reserved : 2, unsigned char channel : 4; /* channel number */
channel : 4; /* channel number */ unsigned char __reserved : 2;
unsigned char lun : 2; /* sensor owner lun */
#else
unsigned char lun : 2; /* sensor owner lun */
unsigned char __reserved : 2;
unsigned char channel : 4; /* channel number */
#endif
unsigned char sensor_num; /* unique sensor number */ unsigned char sensor_num; /* unique sensor number */
} keys; } keys;
struct { struct {
unsigned char id; /* physical entity id */ unsigned char id; /* physical entity id */
unsigned char instance : 7, /* instance number */ #if WORDS_BIGENDIAN
logical : 1; /* physical/logical */ unsigned char logical : 1; /* physical/logical */
unsigned char instance : 7; /* instance number */
#else
unsigned char instance : 7; /* instance number */
unsigned char logical : 1; /* physical/logical */
#endif
} entity; } entity;
struct { struct {
struct { struct {
unsigned char sensor_scan : 1, #if WORDS_BIGENDIAN
event_gen : 1, unsigned char __reserved : 1;
type : 1, unsigned char scanning : 1;
hysteresis : 1, unsigned char events : 1;
thresholds : 1, unsigned char thresholds : 1;
events : 1, unsigned char hysteresis : 1;
scanning : 1, unsigned char type : 1;
__reserved : 1; unsigned char event_gen : 1;
unsigned char sensor_scan : 1;
#else
unsigned char sensor_scan : 1;
unsigned char event_gen : 1;
unsigned char type : 1;
unsigned char hysteresis : 1;
unsigned char thresholds : 1;
unsigned char events : 1;
unsigned char scanning : 1;
unsigned char __reserved : 1;
#endif
} init; } init;
struct { struct {
unsigned char event_msg : 2, #if WORDS_BIGENDIAN
threshold : 2, unsigned char ignore : 1;
hysteresis : 2, unsigned char rearm : 1;
rearm : 1, unsigned char hysteresis : 2;
ignore : 1; unsigned char threshold : 2;
unsigned char event_msg : 2;
#else
unsigned char event_msg : 2;
unsigned char threshold : 2;
unsigned char hysteresis : 2;
unsigned char rearm : 1;
unsigned char ignore : 1;
#endif
} capabilities; } capabilities;
unsigned char type; /* sensor type */ unsigned char type; /* sensor type */
} sensor; } sensor;
@ -174,10 +204,17 @@ struct sdr_record_compact_sensor {
} mask; } mask;
struct { struct {
unsigned char pct : 1, #if WORDS_BIGENDIAN
modifier : 2, unsigned char analog : 2;
rate : 3, unsigned char rate : 3;
analog : 2; unsigned char modifier : 2;
unsigned char pct : 1;
#else
unsigned char pct : 1;
unsigned char modifier : 2;
unsigned char rate : 3;
unsigned char analog : 2;
#endif
struct { struct {
unsigned char base; unsigned char base;
unsigned char modifier; unsigned char modifier;
@ -185,11 +222,22 @@ struct sdr_record_compact_sensor {
} unit; } unit;
struct { struct {
unsigned char count : 4, #if WORDS_BIGENDIAN
mod_type : 2, unsigned char __reserved : 2;
__reserved : 2; unsigned char mod_type : 2;
unsigned char mod_offset : 7, unsigned char count : 4;
entity_inst : 1; #else
unsigned char count : 4;
unsigned char mod_type : 2;
unsigned char __reserved : 2;
#endif
#if WORDS_BIGENDIAN
unsigned char entity_inst : 1;
unsigned char mod_offset : 7;
#else
unsigned char mod_offset : 7;
unsigned char entity_inst : 1;
#endif
} share; } share;
struct { struct {
@ -203,33 +251,54 @@ struct sdr_record_compact_sensor {
unsigned char oem; /* reserved for OEM use */ unsigned char oem; /* reserved for OEM use */
unsigned char id_code; /* sensor ID string type/length code */ unsigned char id_code; /* sensor ID string type/length code */
unsigned char id_string[16]; /* sensor ID string bytes, only if id_code != 0 */ unsigned char id_string[16]; /* sensor ID string bytes, only if id_code != 0 */
} __attribute__ ((packed)); } __attribute__ ((packed));
struct sdr_record_eventonly_sensor { struct sdr_record_eventonly_sensor {
struct { struct {
unsigned char owner_id; unsigned char owner_id;
unsigned char lun : 2, /* sensor owner lun */ #if WORDS_BIGENDIAN
fru_owner : 2, /* fru device owner lun */ unsigned char channel : 4; /* channel number */
channel : 4; /* channel number */ unsigned char fru_owner : 2; /* fru device owner lun */
unsigned char lun : 2; /* sensor owner lun */
#else
unsigned char lun : 2; /* sensor owner lun */
unsigned char fru_owner : 2; /* fru device owner lun */
unsigned char channel : 4; /* channel number */
#endif
unsigned char sensor_num; /* unique sensor number */ unsigned char sensor_num; /* unique sensor number */
} keys; } keys;
struct { struct {
unsigned char id; /* physical entity id */ unsigned char id; /* physical entity id */
unsigned char instance : 7, /* instance number */ #if WORDS_BIGENDIAN
logical : 1; /* physical/logical */ unsigned char logical : 1; /* physical/logical */
unsigned char instance : 7; /* instance number */
#else
unsigned char instance : 7; /* instance number */
unsigned char logical : 1; /* physical/logical */
#endif
} entity; } entity;
unsigned char sensor_type; /* sensor type */ unsigned char sensor_type; /* sensor type */
unsigned char event_type; /* event/reading type code */ unsigned char event_type; /* event/reading type code */
struct { struct {
unsigned char count : 4, #if WORDS_BIGENDIAN
mod_type : 2, unsigned char __reserved : 2;
__reserved : 2; unsigned char mod_type : 2;
unsigned char mod_offset : 7, unsigned char count : 4;
entity_inst : 1; #else
unsigned char count : 4;
unsigned char mod_type : 2;
unsigned char __reserved : 2;
#endif
#if WORDS_BIGENDIAN
unsigned char entity_inst : 1;
unsigned char mod_offset : 7;
#else
unsigned char mod_offset : 7;
unsigned char entity_inst : 1;
#endif
} share; } share;
unsigned char __reserved; unsigned char __reserved;
@ -242,35 +311,65 @@ struct sdr_record_eventonly_sensor {
struct sdr_record_full_sensor { struct sdr_record_full_sensor {
struct { struct {
unsigned char owner_id; unsigned char owner_id;
unsigned char lun : 2, /* sensor owner lun */ #if WORDS_BIGENDIAN
__reserved : 2, unsigned char channel : 4; /* channel number */
channel : 4; /* channel number */ unsigned char __reserved : 2;
unsigned char lun : 2; /* sensor owner lun */
#else
unsigned char lun : 2; /* sensor owner lun */
unsigned char __reserved : 2;
unsigned char channel : 4; /* channel number */
#endif
unsigned char sensor_num; /* unique sensor number */ unsigned char sensor_num; /* unique sensor number */
} keys; } keys;
struct { struct {
unsigned char id; /* physical entity id */ unsigned char id; /* physical entity id */
unsigned char instance : 7, /* instance number */ #if WORDS_BIGENDIAN
logical : 1; /* physical/logical */ unsigned char logical : 1; /* physical/logical */
unsigned char instance : 7; /* instance number */
#else
unsigned char instance : 7; /* instance number */
unsigned char logical : 1; /* physical/logical */
#endif
} entity; } entity;
struct { struct {
struct { struct {
unsigned char sensor_scan : 1, #if WORDS_BIGENDIAN
event_gen : 1, unsigned char __reserved : 1;
type : 1, unsigned char scanning : 1;
hysteresis : 1, unsigned char events : 1;
thresholds : 1, unsigned char thresholds : 1;
events : 1, unsigned char hysteresis : 1;
scanning : 1, unsigned char type : 1;
__reserved : 1; unsigned char event_gen : 1;
unsigned char sensor_scan : 1;
#else
unsigned char sensor_scan : 1;
unsigned char event_gen : 1;
unsigned char type : 1;
unsigned char hysteresis : 1;
unsigned char thresholds : 1;
unsigned char events : 1;
unsigned char scanning : 1;
unsigned char __reserved : 1;
#endif
} init; } init;
struct { struct {
unsigned char event_msg : 2, #if WORDS_BIGENDIAN
threshold : 2, unsigned char ignore : 1;
hysteresis : 2, unsigned char rearm : 1;
rearm : 1, unsigned char hysteresis : 2;
ignore : 1; unsigned char threshold : 2;
unsigned char event_msg : 2;
#else
unsigned char event_msg : 2;
unsigned char threshold : 2;
unsigned char hysteresis : 2;
unsigned char rearm : 1;
unsigned char ignore : 1;
#endif
} capabilities; } capabilities;
unsigned char type; unsigned char type;
} sensor; } sensor;
@ -292,10 +391,17 @@ struct sdr_record_full_sensor {
} mask; } mask;
struct { struct {
unsigned char pct : 1, #if WORDS_BIGENDIAN
modifier : 2, unsigned char analog : 2;
rate : 3, unsigned char rate : 3;
analog : 2; unsigned char modifier : 2;
unsigned char pct : 1;
#else
unsigned char pct : 1;
unsigned char modifier : 2;
unsigned char rate : 3;
unsigned char analog : 2;
#endif
struct { struct {
unsigned char base; unsigned char base;
unsigned char modifier; unsigned char modifier;
@ -307,10 +413,17 @@ struct sdr_record_full_sensor {
uint32_t bacc; /* accuracy, B, Bexp, Rexp */ uint32_t bacc; /* accuracy, B, Bexp, Rexp */
struct { struct {
unsigned char nominal_read : 1, /* nominal reading field specified */ #if WORDS_BIGENDIAN
normal_max : 1, /* normal max field specified */ unsigned char __reserved : 5;
normal_min : 1, /* normal min field specified */ unsigned char normal_min : 1; /* normal min field specified */
__reserved : 5; unsigned char normal_max : 1; /* normal max field specified */
unsigned char nominal_read : 1; /* nominal reading field specified */
#else
unsigned char nominal_read : 1; /* nominal reading field specified */
unsigned char normal_max : 1; /* normal max field specified */
unsigned char normal_min : 1; /* normal min field specified */
unsigned char __reserved : 5;
#endif
} analog_flag; } analog_flag;
unsigned char nominal_read; /* nominal reading, raw value */ unsigned char nominal_read; /* nominal reading, raw value */
@ -343,10 +456,34 @@ struct sdr_record_full_sensor {
struct sdr_record_fru_device_locator { struct sdr_record_fru_device_locator {
struct { struct {
unsigned char __reserved1 : 1, dev_access_addr : 6; #if WORDS_BIGENDIAN
unsigned char __reserved2 : 1;
unsigned char dev_access_addr : 6;
unsigned char __reserved1 : 1;
#else
unsigned char __reserved1 : 1;
unsigned char dev_access_addr : 6;
unsigned char __reserved2 : 1;
#endif
unsigned char fru_device_id; unsigned char fru_device_id;
unsigned char private_bus : 3, access_lun : 2, __reserved3 : 2, logical_dev : 1; #if WORDS_BIGENDIAN
unsigned char __reserved4 : 4, channel_num : 4; unsigned char logical_dev : 1;
unsigned char __reserved3 : 2;
unsigned char access_lun : 2;
unsigned char private_bus : 3;
#else
unsigned char private_bus : 3;
unsigned char access_lun : 2;
unsigned char __reserved3 : 2;
unsigned char logical_dev : 1;
#endif
#if WORDS_BIGENDIAN
unsigned char channel_num : 4;
unsigned char __reserved4 : 4;
#else
unsigned char __reserved4 : 4;
unsigned char channel_num : 4;
#endif
} keys; } keys;
unsigned char __reserved; unsigned char __reserved;
@ -360,9 +497,29 @@ struct sdr_record_fru_device_locator {
} __attribute__ ((packed)); } __attribute__ ((packed));
struct sdr_record_mc_locator { struct sdr_record_mc_locator {
unsigned char __reserved1 : 1, dev_slave_addr : 7; #if WORDS_BIGENDIAN
unsigned char channel_num : 4, __reserved2 : 4; unsigned char dev_slave_addr : 7;
unsigned char global_init : 4, __reserved3 : 1, pwr_state_notif : 3; unsigned char __reserved1 : 1;
#else
unsigned char __reserved1 : 1;
unsigned char dev_slave_addr : 7;
#endif
#if WORDS_BIGENDIAN
unsigned char __reserved2 : 4;
unsigned char channel_num : 4;
#else
unsigned char channel_num : 4;
unsigned char __reserved2 : 4;
#endif
#if WORDS_BIGENDIAN
unsigned char pwr_state_notif : 3;
unsigned char __reserved3 : 1;
unsigned char global_init : 4;
#else
unsigned char global_init : 4;
unsigned char __reserved3 : 1;
unsigned char pwr_state_notif : 3;
#endif
unsigned char dev_support; unsigned char dev_support;
unsigned char __reserved4[3]; unsigned char __reserved4[3];
struct { struct {
@ -375,10 +532,32 @@ struct sdr_record_mc_locator {
} __attribute__ ((packed)); } __attribute__ ((packed));
struct sdr_record_fru_locator { struct sdr_record_fru_locator {
unsigned char __reserved1 : 1, dev_slave_addr : 7; #if WORDS_BIGENDIAN
unsigned char dev_slave_addr : 7;
unsigned char __reserved1 : 1;
#else
unsigned char __reserved1 : 1;
unsigned char dev_slave_addr : 7;
#endif
unsigned char device_id; unsigned char device_id;
unsigned char logical : 1, __reserved2 : 2, lun : 2, bus : 3; #if WORDS_BIGENDIAN
unsigned char channel_num : 4, __reserved3 : 4; unsigned char bus : 3;
unsigned char lun : 2;
unsigned char __reserved2 : 2;
unsigned char logical : 1;
#else
unsigned char logical : 1;
unsigned char __reserved2 : 2;
unsigned char lun : 2;
unsigned char bus : 3;
#endif
#if WORDS_BIGENDIAN
unsigned char __reserved3 : 4;
unsigned char channel_num : 4;
#else
unsigned char channel_num : 4;
unsigned char __reserved3 : 4;
#endif
unsigned char __reserved4; unsigned char __reserved4;
unsigned char dev_type; unsigned char dev_type;
unsigned char dev_type_modifier; unsigned char dev_type_modifier;

View File

@ -42,6 +42,10 @@
#include <ipmitool/ipmi_sel.h> #include <ipmitool/ipmi_sel.h>
#include <ipmitool/ipmi_entity.h> #include <ipmitool/ipmi_entity.h>
#if HAVE_CONFIG_H
# include <config.h>
#endif
extern int verbose; extern int verbose;
/* convert unsigned value to 2's complement signed */ /* convert unsigned value to 2's complement signed */
@ -367,7 +371,11 @@ ipmi_sdr_print_sensor_full(struct ipmi_intf * intf,
printf("Sensor Reading : "); printf("Sensor Reading : ");
if (validread) { if (validread) {
#if WORDS_BIGENDIAN
unsigned raw_tol = sensor->mtol & 0x3f;
#else
unsigned raw_tol = (sensor->mtol & 0x3f00) >> 8; unsigned raw_tol = (sensor->mtol & 0x3f00) >> 8;
#endif
float tol = sdr_convert_sensor_reading(sensor, raw_tol * 2); float tol = sdr_convert_sensor_reading(sensor, raw_tol * 2);
printf("%.*f (+/- %.*f) %s\n", printf("%.*f (+/- %.*f) %s\n",
(val==(int)val) ? 0 : 3, (val==(int)val) ? 0 : 3,