Commit 35b5df41 authored by Stephen Rothwell's avatar Stephen Rothwell Committed by Linus Torvalds

[PATCH] ppc64: iSeries more MF cleanup

This patch starts the improvement of the style of the MF code:
	- remove a union that is used where casts suffice
	- add a helper function (signal_ce_msg_simple) and use it
	- replace some painful code that converts a byte array to
	  a couple of u32's and then shifts and masks the bytes back out.
Signed-off-by: default avatarStephen Rothwell <sfr@canb.auug.org.au>
Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent df15a53b
...@@ -48,13 +48,8 @@ ...@@ -48,13 +48,8 @@
* This is the structure layout for the Machine Facilites LPAR event * This is the structure layout for the Machine Facilites LPAR event
* flows. * flows.
*/ */
union safe_cast {
u64 ptr_as_u64;
void *ptr;
};
struct VspCmdData { struct VspCmdData {
union safe_cast token; u64 token;
u16 cmd; u16 cmd;
HvLpIndex lp_index; HvLpIndex lp_index;
u8 result_code; u8 result_code;
...@@ -215,12 +210,8 @@ static int signal_event(struct pending_event *ev) ...@@ -215,12 +210,8 @@ static int signal_event(struct pending_event *ev)
if (ev1 == ev) if (ev1 == ev)
rc = -EIO; rc = -EIO;
else if (ev1->hdlr != NULL) { else if (ev1->hdlr != NULL)
union safe_cast mySafeCast; (*ev1->hdlr)((void *)ev1->event.hp_lp_event.xCorrelationToken, -EIO);
mySafeCast.ptr_as_u64 = ev1->event.hp_lp_event.xCorrelationToken;
(*ev1->hdlr)(mySafeCast.ptr, -EIO);
}
spin_lock_irqsave(&pending_event_spinlock, flags); spin_lock_irqsave(&pending_event_spinlock, flags);
free_pending_event(ev1); free_pending_event(ev1);
...@@ -287,7 +278,7 @@ static int signal_vsp_instruction(struct VspCmdData *vspCmd) ...@@ -287,7 +278,7 @@ static int signal_vsp_instruction(struct VspCmdData *vspCmd)
ev->event.hp_lp_event.xSubtype = 6; ev->event.hp_lp_event.xSubtype = 6;
ev->event.hp_lp_event.x.xSubtypeData = ev->event.hp_lp_event.x.xSubtypeData =
subtype_data('M', 'F', 'V', 'I'); subtype_data('M', 'F', 'V', 'I');
ev->event.data.vsp_cmd.token.ptr = &response; ev->event.data.vsp_cmd.token = (u64)&response;
ev->event.data.vsp_cmd.cmd = vspCmd->cmd; ev->event.data.vsp_cmd.cmd = vspCmd->cmd;
ev->event.data.vsp_cmd.lp_index = HvLpConfig_getLpIndex(); ev->event.data.vsp_cmd.lp_index = HvLpConfig_getLpIndex();
ev->event.data.vsp_cmd.result_code = 0xFF; ev->event.data.vsp_cmd.result_code = 0xFF;
...@@ -321,6 +312,18 @@ static int signal_ce_msg(char *ce_msg, struct CeMsgCompleteData *completion) ...@@ -321,6 +312,18 @@ static int signal_ce_msg(char *ce_msg, struct CeMsgCompleteData *completion)
return signal_event(ev); return signal_event(ev);
} }
/*
* Send a 12-byte CE message (with no data) to the primary partition VSP object
*/
static int signal_ce_msg_simple(u8 ce_op, struct CeMsgCompleteData *completion)
{
u8 ce_msg[12];
memset(ce_msg, 0, sizeof(ce_msg));
ce_msg[3] = ce_op;
return signal_ce_msg(ce_msg, completion);
}
/* /*
* Send a 12-byte CE message and DMA data to the primary partition VSP object * Send a 12-byte CE message and DMA data to the primary partition VSP object
*/ */
...@@ -385,7 +388,7 @@ static void intReceived(struct IoMFLpEvent *event) ...@@ -385,7 +388,7 @@ static void intReceived(struct IoMFLpEvent *event)
if ((event->data.ce_msg.ce_msg[5] & 0x20) != 0) { if ((event->data.ce_msg.ce_msg[5] & 0x20) != 0) {
printk(KERN_INFO "mf.c: Commencing partition shutdown\n"); printk(KERN_INFO "mf.c: Commencing partition shutdown\n");
if (shutdown() == 0) if (shutdown() == 0)
signal_ce_msg("\x00\x00\x00\xDB\x00\x00\x00\x00\x00\x00\x00\x00", NULL); signal_ce_msg_simple(0xDB, NULL);
} }
break; break;
case 0xC0: /* get time */ case 0xC0: /* get time */
...@@ -464,16 +467,13 @@ static void ackReceived(struct IoMFLpEvent *event) ...@@ -464,16 +467,13 @@ static void ackReceived(struct IoMFLpEvent *event)
case 4: /* allocate */ case 4: /* allocate */
case 5: /* deallocate */ case 5: /* deallocate */
if (pending_event_head->hdlr != NULL) { if (pending_event_head->hdlr != NULL) {
union safe_cast mySafeCast; (*pending_event_head->hdlr)((void *)event->hp_lp_event.xCorrelationToken, event->data.alloc.count);
mySafeCast.ptr_as_u64 = event->hp_lp_event.xCorrelationToken;
(*pending_event_head->hdlr)(mySafeCast.ptr, event->data.alloc.count);
} }
freeIt = 1; freeIt = 1;
break; break;
case 6: case 6:
{ {
struct VspRspData *rsp = (struct VspRspData *)event->data.vsp_cmd.token.ptr; struct VspRspData *rsp = (struct VspRspData *)event->data.vsp_cmd.token;
if (rsp != NULL) { if (rsp != NULL) {
if (rsp->response != NULL) if (rsp->response != NULL)
...@@ -543,11 +543,8 @@ void mf_allocate_lp_events(HvLpIndex targetLp, HvLpEvent_Type type, ...@@ -543,11 +543,8 @@ void mf_allocate_lp_events(HvLpIndex targetLp, HvLpEvent_Type type,
if (ev == NULL) { if (ev == NULL) {
rc = -ENOMEM; rc = -ENOMEM;
} else { } else {
union safe_cast mine;
mine.ptr = userToken;
ev->event.hp_lp_event.xSubtype = 4; ev->event.hp_lp_event.xSubtype = 4;
ev->event.hp_lp_event.xCorrelationToken = mine.ptr_as_u64; ev->event.hp_lp_event.xCorrelationToken = (u64)userToken;
ev->event.hp_lp_event.x.xSubtypeData = ev->event.hp_lp_event.x.xSubtypeData =
subtype_data('M', 'F', 'M', 'A'); subtype_data('M', 'F', 'M', 'A');
ev->event.data.alloc.target_lp = targetLp; ev->event.data.alloc.target_lp = targetLp;
...@@ -575,11 +572,8 @@ void mf_deallocate_lp_events(HvLpIndex targetLp, HvLpEvent_Type type, ...@@ -575,11 +572,8 @@ void mf_deallocate_lp_events(HvLpIndex targetLp, HvLpEvent_Type type,
if (ev == NULL) if (ev == NULL)
rc = -ENOMEM; rc = -ENOMEM;
else { else {
union safe_cast mine;
mine.ptr = userToken;
ev->event.hp_lp_event.xSubtype = 5; ev->event.hp_lp_event.xSubtype = 5;
ev->event.hp_lp_event.xCorrelationToken = mine.ptr_as_u64; ev->event.hp_lp_event.xCorrelationToken = (u64)userToken;
ev->event.hp_lp_event.x.xSubtypeData = ev->event.hp_lp_event.x.xSubtypeData =
subtype_data('M', 'F', 'M', 'D'); subtype_data('M', 'F', 'M', 'D');
ev->event.data.alloc.target_lp = targetLp; ev->event.data.alloc.target_lp = targetLp;
...@@ -600,8 +594,9 @@ EXPORT_SYMBOL(mf_deallocate_lp_events); ...@@ -600,8 +594,9 @@ EXPORT_SYMBOL(mf_deallocate_lp_events);
void mf_power_off(void) void mf_power_off(void)
{ {
printk(KERN_INFO "mf.c: Down it goes...\n"); printk(KERN_INFO "mf.c: Down it goes...\n");
signal_ce_msg("\x00\x00\x00\x4D\x00\x00\x00\x00\x00\x00\x00\x00", NULL); signal_ce_msg_simple(0x4d, NULL);
for (;;); for (;;)
;
} }
/* /*
...@@ -611,8 +606,9 @@ void mf_power_off(void) ...@@ -611,8 +606,9 @@ void mf_power_off(void)
void mf_reboot(void) void mf_reboot(void)
{ {
printk(KERN_INFO "mf.c: Preparing to bounce...\n"); printk(KERN_INFO "mf.c: Preparing to bounce...\n");
signal_ce_msg("\x00\x00\x00\x4E\x00\x00\x00\x00\x00\x00\x00\x00", NULL); signal_ce_msg_simple(0x4e, NULL);
for (;;); for (;;)
;
} }
/* /*
...@@ -659,7 +655,7 @@ void mf_display_progress(u16 value) ...@@ -659,7 +655,7 @@ void mf_display_progress(u16 value)
*/ */
void mf_clear_src(void) void mf_clear_src(void)
{ {
signal_ce_msg("\x00\x00\x00\x4B\x00\x00\x00\x00\x00\x00\x00\x00", NULL); signal_ce_msg_simple(0x4b, NULL);
} }
/* /*
...@@ -678,7 +674,7 @@ void mf_init(void) ...@@ -678,7 +674,7 @@ void mf_init(void)
HvLpEvent_registerHandler(HvLpEvent_Type_MachineFac, &hvHandler); HvLpEvent_registerHandler(HvLpEvent_Type_MachineFac, &hvHandler);
/* virtual continue ack */ /* virtual continue ack */
signal_ce_msg("\x00\x00\x00\x57\x00\x00\x00\x00\x00\x00\x00\x00", NULL); signal_ce_msg_simple(0x57, NULL);
/* initialization complete */ /* initialization complete */
printk(KERN_NOTICE "mf.c: iSeries Linux LPAR Machine Facilities initialized\n"); printk(KERN_NOTICE "mf.c: iSeries Linux LPAR Machine Facilities initialized\n");
...@@ -935,8 +931,7 @@ int mf_get_rtc(struct rtc_time *tm) ...@@ -935,8 +931,7 @@ int mf_get_rtc(struct rtc_time *tm)
init_completion(&rtcData.com); init_completion(&rtcData.com);
ceComplete.handler = &getRtcTimeComplete; ceComplete.handler = &getRtcTimeComplete;
ceComplete.token = (void *)&rtcData; ceComplete.token = (void *)&rtcData;
rc = signal_ce_msg("\x00\x00\x00\x40\x00\x00\x00\x00\x00\x00\x00\x00", rc = signal_ce_msg_simple(0x40, &ce_complete);
&ceComplete);
if (rc == 0) { if (rc == 0) {
wait_for_completion(&rtcData.com); wait_for_completion(&rtcData.com);
...@@ -953,14 +948,13 @@ int mf_get_rtc(struct rtc_time *tm) ...@@ -953,14 +948,13 @@ int mf_get_rtc(struct rtc_time *tm)
mf_set_rtc(tm); mf_set_rtc(tm);
} }
{ {
u32 dataWord1 = *((u32 *)(rtcData.xCeMsg.ce_msg+4)); u8 *ce_msg = rtcData.xCeMsg.ce_msg;
u32 dataWord2 = *((u32 *)(rtcData.xCeMsg.ce_msg+8)); u8 year = ce_msg[5];
u8 year = (dataWord1 >> 16) & 0x000000FF; u8 sec = ce_msg[6];
u8 sec = (dataWord1 >> 8) & 0x000000FF; u8 min = ce_msg[7];
u8 min = dataWord1 & 0x000000FF; u8 hour = ce_msg[8];
u8 hour = (dataWord2 >> 24) & 0x000000FF; u8 day = ce_msg[10];
u8 day = (dataWord2 >> 8) & 0x000000FF; u8 mon = ce_msg[11];
u8 mon = dataWord2 & 0x000000FF;
BCD_TO_BIN(sec); BCD_TO_BIN(sec);
BCD_TO_BIN(min); BCD_TO_BIN(min);
...@@ -997,7 +991,7 @@ int mf_get_rtc(struct rtc_time *tm) ...@@ -997,7 +991,7 @@ int mf_get_rtc(struct rtc_time *tm)
return rc; return rc;
} }
int mf_set_rtc(struct rtc_time * tm) int mf_set_rtc(struct rtc_time *tm)
{ {
char ceTime[12] = "\x00\x00\x00\x41\x00\x00\x00\x00\x00\x00\x00\x00"; char ceTime[12] = "\x00\x00\x00\x41\x00\x00\x00\x00\x00\x00\x00\x00";
u8 day, mon, hour, min, sec, y1, y2; u8 day, mon, hour, min, sec, y1, y2;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment