aboutsummaryrefslogtreecommitdiffstats
path: root/core/fs/pxe/isr.c
blob: e92e731cb7a4bb6a732a35b738ead64691085df8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/*
 * core/fs/pxe/isr.c
 *
 * Stub invoked on return from real mode including from an interrupt.
 * Interrupts are locked out on entry.
 */

#include "core.h"
#include "thread.h"
#include "pxe.h"
#include <string.h>

extern uint8_t pxe_irq_pending;
static DECLARE_INIT_SEMAPHORE(pxe_receive_thread_sem, 0);

static void pm_return(void)
{
    static uint32_t last_jiffies = 0;
    uint32_t now = jiffies();
    
    __schedule_lock++;

    if (now != last_jiffies) {
	last_jiffies = now;
	__thread_process_timeouts();
    }

    if (pxe_irq_pending) {
	pxe_irq_pending = 0;
	if (pxe_receive_thread_sem.count <= 0)
	  sem_up(&pxe_receive_thread_sem);
    }

    __schedule_lock--;

    if (__need_schedule)
	__schedule();
}

void undiif_input(t_PXENV_UNDI_ISR *);

static void pxe_receive_thread(void *dummy)
{
    static __lowmem t_PXENV_UNDI_ISR isr;
    uint16_t func;
    bool done;

    (void)dummy;

    for (;;) {
	sem_down(&pxe_receive_thread_sem, 0);
	func = PXENV_UNDI_ISR_IN_PROCESS; /* First time */

	done = false;
	while (!done) {
	    memset(&isr, 0, sizeof isr);
	    isr.FuncFlag = func;
	    func = PXENV_UNDI_ISR_IN_GET_NEXT; /* Next time */

	    pxe_call(PXENV_UNDI_ISR, &isr);

	    switch (isr.FuncFlag) {
	    case PXENV_UNDI_ISR_OUT_DONE:
		done = true;
		break;

	    case PXENV_UNDI_ISR_OUT_TRANSMIT:
		/* Transmit complete - nothing for us to do */
		break;

	    case PXENV_UNDI_ISR_OUT_RECEIVE:
		undiif_input(&isr);
		break;
		
	    case PXENV_UNDI_ISR_OUT_BUSY:
		/* ISR busy, this should not happen */
		done = true;
		break;
		
	    default:
		/* Invalid return code, this should not happen */
		done = true;
		break;
	    }
	}
    }
}


void pxe_init_isr(void)
{
    start_idle_thread();
    start_thread("pxe receive", 16384, 0, pxe_receive_thread, NULL);
    core_pm_hook = pm_return;
}