2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* ItLpQueue.c
|
|
|
|
* Copyright (C) 2001 Mike Corrigan IBM Corporation
|
2005-06-30 13:16:28 +08:00
|
|
|
*
|
2005-04-17 06:20:36 +08:00
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/stddef.h>
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/sched.h>
|
2005-06-30 13:08:27 +08:00
|
|
|
#include <linux/bootmem.h>
|
2005-06-30 13:08:44 +08:00
|
|
|
#include <linux/seq_file.h>
|
|
|
|
#include <linux/proc_fs.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <asm/system.h>
|
|
|
|
#include <asm/paca.h>
|
|
|
|
#include <asm/iSeries/ItLpQueue.h>
|
|
|
|
#include <asm/iSeries/HvLpEvent.h>
|
|
|
|
#include <asm/iSeries/HvCallEvent.h>
|
|
|
|
|
2005-06-30 13:12:21 +08:00
|
|
|
/*
|
|
|
|
* The LpQueue is used to pass event data from the hypervisor to
|
|
|
|
* the partition. This is where I/O interrupt events are communicated.
|
|
|
|
*
|
|
|
|
* It is written to by the hypervisor so cannot end up in the BSS.
|
|
|
|
*/
|
2005-06-30 13:15:32 +08:00
|
|
|
struct hvlpevent_queue hvlpevent_queue __attribute__((__section__(".data")));
|
2005-06-30 13:12:21 +08:00
|
|
|
|
2005-06-30 13:16:09 +08:00
|
|
|
DEFINE_PER_CPU(unsigned long[HvLpEvent_Type_NumTypes], hvlpevent_counts);
|
|
|
|
|
|
|
|
static char *event_types[HvLpEvent_Type_NumTypes] = {
|
2005-06-30 13:16:18 +08:00
|
|
|
"Hypervisor",
|
|
|
|
"Machine Facilities",
|
|
|
|
"Session Manager",
|
|
|
|
"SPD I/O",
|
|
|
|
"Virtual Bus",
|
|
|
|
"PCI I/O",
|
|
|
|
"RIO I/O",
|
|
|
|
"Virtual Lan",
|
|
|
|
"Virtual I/O"
|
2005-06-30 13:08:44 +08:00
|
|
|
};
|
|
|
|
|
2005-06-30 13:07:57 +08:00
|
|
|
static __inline__ int set_inUse(void)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
int t;
|
2005-06-30 13:15:32 +08:00
|
|
|
u32 * inUseP = &hvlpevent_queue.xInUseWord;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
__asm__ __volatile__("\n\
|
|
|
|
1: lwarx %0,0,%2 \n\
|
|
|
|
cmpwi 0,%0,0 \n\
|
|
|
|
li %0,0 \n\
|
|
|
|
bne- 2f \n\
|
|
|
|
addi %0,%0,1 \n\
|
|
|
|
stwcx. %0,0,%2 \n\
|
|
|
|
bne- 1b \n\
|
|
|
|
2: eieio"
|
2005-06-30 13:15:32 +08:00
|
|
|
: "=&r" (t), "=m" (hvlpevent_queue.xInUseWord)
|
|
|
|
: "r" (inUseP), "m" (hvlpevent_queue.xInUseWord)
|
2005-04-17 06:20:36 +08:00
|
|
|
: "cc");
|
|
|
|
|
|
|
|
return t;
|
|
|
|
}
|
|
|
|
|
2005-06-30 13:07:57 +08:00
|
|
|
static __inline__ void clear_inUse(void)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2005-06-30 13:15:32 +08:00
|
|
|
hvlpevent_queue.xInUseWord = 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Array of LpEvent handler functions */
|
|
|
|
extern LpEventHandler lpEventHandler[HvLpEvent_Type_NumTypes];
|
|
|
|
unsigned long ItLpQueueInProcess = 0;
|
|
|
|
|
2005-06-30 13:15:42 +08:00
|
|
|
static struct HvLpEvent * get_next_hvlpevent(void)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2005-06-30 13:16:28 +08:00
|
|
|
struct HvLpEvent * nextLpEvent =
|
2005-06-30 13:15:32 +08:00
|
|
|
(struct HvLpEvent *)hvlpevent_queue.xSlicCurEventPtr;
|
2005-06-30 13:16:28 +08:00
|
|
|
if (nextLpEvent->xFlags.xValid) {
|
2005-04-17 06:20:36 +08:00
|
|
|
/* rmb() needed only for weakly consistent machines (regatta) */
|
|
|
|
rmb();
|
|
|
|
/* Set pointer to next potential event */
|
2005-06-30 13:15:32 +08:00
|
|
|
hvlpevent_queue.xSlicCurEventPtr += ((nextLpEvent->xSizeMinus1 +
|
2005-06-30 13:16:28 +08:00
|
|
|
LpEventAlign) /
|
|
|
|
LpEventAlign) *
|
2005-04-17 06:20:36 +08:00
|
|
|
LpEventAlign;
|
|
|
|
/* Wrap to beginning if no room at end */
|
2005-06-30 13:15:32 +08:00
|
|
|
if (hvlpevent_queue.xSlicCurEventPtr > hvlpevent_queue.xSlicLastValidEventPtr)
|
|
|
|
hvlpevent_queue.xSlicCurEventPtr = hvlpevent_queue.xSlicEventStackPtr;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2005-06-30 13:16:28 +08:00
|
|
|
else
|
2005-04-17 06:20:36 +08:00
|
|
|
nextLpEvent = NULL;
|
|
|
|
|
|
|
|
return nextLpEvent;
|
|
|
|
}
|
|
|
|
|
2005-06-30 13:07:33 +08:00
|
|
|
static unsigned long spread_lpevents = NR_CPUS;
|
2005-06-30 13:07:09 +08:00
|
|
|
|
2005-06-30 13:15:42 +08:00
|
|
|
int hvlpevent_is_pending(void)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2005-06-30 13:07:09 +08:00
|
|
|
struct HvLpEvent *next_event;
|
|
|
|
|
|
|
|
if (smp_processor_id() >= spread_lpevents)
|
|
|
|
return 0;
|
|
|
|
|
2005-06-30 13:15:32 +08:00
|
|
|
next_event = (struct HvLpEvent *)hvlpevent_queue.xSlicCurEventPtr;
|
|
|
|
return next_event->xFlags.xValid | hvlpevent_queue.xPlicOverflowIntPending;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2005-06-30 13:16:28 +08:00
|
|
|
static void hvlpevent_clear_valid(struct HvLpEvent * event)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
/* Clear the valid bit of the event
|
|
|
|
* Also clear bits within this event that might
|
|
|
|
* look like valid bits (on 64-byte boundaries)
|
2005-06-30 13:16:28 +08:00
|
|
|
*/
|
|
|
|
unsigned extra = ((event->xSizeMinus1 + LpEventAlign) /
|
|
|
|
LpEventAlign) - 1;
|
|
|
|
switch (extra) {
|
|
|
|
case 3:
|
2005-04-17 06:20:36 +08:00
|
|
|
((struct HvLpEvent*)((char*)event+3*LpEventAlign))->xFlags.xValid=0;
|
2005-06-30 13:16:28 +08:00
|
|
|
case 2:
|
2005-04-17 06:20:36 +08:00
|
|
|
((struct HvLpEvent*)((char*)event+2*LpEventAlign))->xFlags.xValid=0;
|
2005-06-30 13:16:28 +08:00
|
|
|
case 1:
|
2005-04-17 06:20:36 +08:00
|
|
|
((struct HvLpEvent*)((char*)event+1*LpEventAlign))->xFlags.xValid=0;
|
2005-06-30 13:16:28 +08:00
|
|
|
case 0:
|
|
|
|
;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
mb();
|
|
|
|
event->xFlags.xValid = 0;
|
|
|
|
}
|
|
|
|
|
2005-06-30 13:15:53 +08:00
|
|
|
void process_hvlpevents(struct pt_regs *regs)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
struct HvLpEvent * nextLpEvent;
|
|
|
|
|
|
|
|
/* If we have recursed, just return */
|
2005-06-30 13:07:57 +08:00
|
|
|
if ( !set_inUse() )
|
2005-06-30 13:15:53 +08:00
|
|
|
return;
|
2005-06-30 13:16:28 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
if (ItLpQueueInProcess == 0)
|
|
|
|
ItLpQueueInProcess = 1;
|
|
|
|
else
|
|
|
|
BUG();
|
|
|
|
|
|
|
|
for (;;) {
|
2005-06-30 13:15:42 +08:00
|
|
|
nextLpEvent = get_next_hvlpevent();
|
2005-06-30 13:16:28 +08:00
|
|
|
if (nextLpEvent) {
|
|
|
|
/* Call appropriate handler here, passing
|
2005-04-17 06:20:36 +08:00
|
|
|
* a pointer to the LpEvent. The handler
|
|
|
|
* must make a copy of the LpEvent if it
|
|
|
|
* needs it in a bottom half. (perhaps for
|
|
|
|
* an ACK)
|
2005-06-30 13:16:28 +08:00
|
|
|
*
|
|
|
|
* Handlers are responsible for ACK processing
|
2005-04-17 06:20:36 +08:00
|
|
|
*
|
|
|
|
* The Hypervisor guarantees that LpEvents will
|
|
|
|
* only be delivered with types that we have
|
|
|
|
* registered for, so no type check is necessary
|
|
|
|
* here!
|
2005-06-30 13:16:28 +08:00
|
|
|
*/
|
|
|
|
if (nextLpEvent->xType < HvLpEvent_Type_NumTypes)
|
2005-06-30 13:16:09 +08:00
|
|
|
__get_cpu_var(hvlpevent_counts)[nextLpEvent->xType]++;
|
2005-06-30 13:16:28 +08:00
|
|
|
if (nextLpEvent->xType < HvLpEvent_Type_NumTypes &&
|
|
|
|
lpEventHandler[nextLpEvent->xType])
|
2005-04-17 06:20:36 +08:00
|
|
|
lpEventHandler[nextLpEvent->xType](nextLpEvent, regs);
|
|
|
|
else
|
|
|
|
printk(KERN_INFO "Unexpected Lp Event type=%d\n", nextLpEvent->xType );
|
2005-06-30 13:16:28 +08:00
|
|
|
|
|
|
|
hvlpevent_clear_valid(nextLpEvent);
|
|
|
|
} else if (hvlpevent_queue.xPlicOverflowIntPending)
|
2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* No more valid events. If overflow events are
|
|
|
|
* pending process them
|
|
|
|
*/
|
2005-06-30 13:16:28 +08:00
|
|
|
HvCallEvent_getOverflowLpEvents(hvlpevent_queue.xIndex);
|
2005-04-17 06:20:36 +08:00
|
|
|
else
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
ItLpQueueInProcess = 0;
|
|
|
|
mb();
|
2005-06-30 13:07:57 +08:00
|
|
|
clear_inUse();
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2005-06-30 13:07:33 +08:00
|
|
|
|
|
|
|
static int set_spread_lpevents(char *str)
|
|
|
|
{
|
|
|
|
unsigned long val = simple_strtoul(str, NULL, 0);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The parameter is the number of processors to share in processing
|
|
|
|
* lp events.
|
|
|
|
*/
|
|
|
|
if (( val > 0) && (val <= NR_CPUS)) {
|
|
|
|
spread_lpevents = val;
|
|
|
|
printk("lpevent processing spread over %ld processors\n", val);
|
|
|
|
} else {
|
|
|
|
printk("invalid spread_lpevents %ld\n", val);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
__setup("spread_lpevents=", set_spread_lpevents);
|
|
|
|
|
2005-06-30 13:08:27 +08:00
|
|
|
void setup_hvlpevent_queue(void)
|
|
|
|
{
|
|
|
|
void *eventStack;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Allocate a page for the Event Stack. The Hypervisor needs the
|
|
|
|
* absolute real address, so we subtract out the KERNELBASE and add
|
|
|
|
* in the absolute real address of the kernel load area.
|
|
|
|
*/
|
|
|
|
eventStack = alloc_bootmem_pages(LpEventStackSize);
|
|
|
|
memset(eventStack, 0, LpEventStackSize);
|
|
|
|
|
|
|
|
/* Invoke the hypervisor to initialize the event stack */
|
|
|
|
HvCallEvent_setLpEventStack(0, eventStack, LpEventStackSize);
|
|
|
|
|
2005-06-30 13:15:32 +08:00
|
|
|
hvlpevent_queue.xSlicEventStackPtr = (char *)eventStack;
|
|
|
|
hvlpevent_queue.xSlicCurEventPtr = (char *)eventStack;
|
|
|
|
hvlpevent_queue.xSlicLastValidEventPtr = (char *)eventStack +
|
2005-06-30 13:08:27 +08:00
|
|
|
(LpEventStackSize - LpEventMaxSize);
|
2005-06-30 13:15:32 +08:00
|
|
|
hvlpevent_queue.xIndex = 0;
|
2005-06-30 13:08:27 +08:00
|
|
|
}
|
2005-06-30 13:08:44 +08:00
|
|
|
|
|
|
|
static int proc_lpevents_show(struct seq_file *m, void *v)
|
|
|
|
{
|
2005-06-30 13:16:09 +08:00
|
|
|
int cpu, i;
|
|
|
|
unsigned long sum;
|
|
|
|
static unsigned long cpu_totals[NR_CPUS];
|
|
|
|
|
|
|
|
/* FIXME: do we care that there's no locking here? */
|
|
|
|
sum = 0;
|
|
|
|
for_each_online_cpu(cpu) {
|
|
|
|
cpu_totals[cpu] = 0;
|
|
|
|
for (i = 0; i < HvLpEvent_Type_NumTypes; i++) {
|
|
|
|
cpu_totals[cpu] += per_cpu(hvlpevent_counts, cpu)[i];
|
|
|
|
}
|
|
|
|
sum += cpu_totals[cpu];
|
|
|
|
}
|
2005-06-30 13:08:44 +08:00
|
|
|
|
|
|
|
seq_printf(m, "LpEventQueue 0\n");
|
2005-06-30 13:16:09 +08:00
|
|
|
seq_printf(m, " events processed:\t%lu\n", sum);
|
2005-06-30 13:08:44 +08:00
|
|
|
|
2005-06-30 13:16:09 +08:00
|
|
|
for (i = 0; i < HvLpEvent_Type_NumTypes; ++i) {
|
|
|
|
sum = 0;
|
|
|
|
for_each_online_cpu(cpu) {
|
|
|
|
sum += per_cpu(hvlpevent_counts, cpu)[i];
|
|
|
|
}
|
|
|
|
|
2005-06-30 13:16:18 +08:00
|
|
|
seq_printf(m, " %-20s %10lu\n", event_types[i], sum);
|
2005-06-30 13:16:09 +08:00
|
|
|
}
|
2005-06-30 13:08:44 +08:00
|
|
|
|
|
|
|
seq_printf(m, "\n events processed by processor:\n");
|
|
|
|
|
2005-06-30 13:16:09 +08:00
|
|
|
for_each_online_cpu(cpu) {
|
|
|
|
seq_printf(m, " CPU%02d %10lu\n", cpu, cpu_totals[cpu]);
|
|
|
|
}
|
2005-06-30 13:08:44 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int proc_lpevents_open(struct inode *inode, struct file *file)
|
|
|
|
{
|
|
|
|
return single_open(file, proc_lpevents_show, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct file_operations proc_lpevents_operations = {
|
|
|
|
.open = proc_lpevents_open,
|
|
|
|
.read = seq_read,
|
|
|
|
.llseek = seq_lseek,
|
|
|
|
.release = single_release,
|
|
|
|
};
|
|
|
|
|
|
|
|
static int __init proc_lpevents_init(void)
|
|
|
|
{
|
|
|
|
struct proc_dir_entry *e;
|
|
|
|
|
|
|
|
e = create_proc_entry("iSeries/lpevents", S_IFREG|S_IRUGO, NULL);
|
|
|
|
if (e)
|
|
|
|
e->proc_fops = &proc_lpevents_operations;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
__initcall(proc_lpevents_init);
|
|
|
|
|