summaryrefslogtreecommitdiffstats
path: root/src/ssx/pgp/pgp_irq_init.c
blob: 67197665b0c54db66506bce05b8ba47b4409e84c (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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
// $Id: pgp_irq_init.c,v 1.2 2014/02/03 01:30:35 daviddu Exp $
// $Source: /afs/awd/projects/eclipz/KnowledgeBase/.cvsroot/eclipz/chips/p8/working/procedures/ssx/pgp/pgp_irq_init.c,v $
//-----------------------------------------------------------------------------
// *! (C) Copyright International Business Machines Corp. 2013
// *! All Rights Reserved -- Property of IBM
// *! *** IBM Confidential ***
//-----------------------------------------------------------------------------

/// \file pgp_irq_init.c
/// \brief PGP IRQ initialization code for SSX
///
///  The entry points in this file are initialization rotines that could be
///  eliminated/deallocated by the application to free up storage if they are
///  no longer needed after initialization.

#include "ssx.h"

/// Define the polarity and trigger condition for an interrupt.
///
/// It is up to the application to take care of any side effects that may
/// occur from programming or reprogramming the interrupt controller.  For
/// example, changing edge/level sensitivity or active level may set or clear
/// interrupt status in the controller.
///
/// Note that SSX allows this API to be called from any context, and changes
/// to the interrupt controller are made from an SSX_CRITICAL critical
/// section.
///
/// Return values other then SSX_OK (0) are errors; see \ref ssx_errors
///
/// \retval 0 Successful completion
///
/// \retval -SSX_INVALID_ARGUMENT_IRQ_SETUP One or more arguments are invalid, 
/// including an invalid \a irq, or invalid \a polarity or \a trigger parameters.

int
ssx_irq_setup(SsxIrqId irq,
              int      polarity,
              int      trigger)
{
    SsxMachineContext ctx;
    uint32_t oitr, oeipr;

    if (SSX_ERROR_CHECK_API) {
        SSX_ERROR_IF(!PGP_IRQ_VALID(irq) ||
                     !((polarity == SSX_IRQ_POLARITY_ACTIVE_HIGH) ||
                       (polarity == SSX_IRQ_POLARITY_ACTIVE_LOW)) ||
                     !((trigger == SSX_IRQ_TRIGGER_LEVEL_SENSITIVE) ||
                       (trigger == SSX_IRQ_TRIGGER_EDGE_SENSITIVE)),
                     SSX_INVALID_ARGUMENT_IRQ_SETUP);
    }

    ssx_critical_section_enter(SSX_CRITICAL, &ctx);

    oeipr = in32(OCB_OIEPR(irq));
    if (polarity == SSX_IRQ_POLARITY_ACTIVE_HIGH) {
        out32(OCB_OIEPR(irq), oeipr | PGP_IRQ_MASK32(irq));
    } else {
        out32(OCB_OIEPR(irq), oeipr & ~PGP_IRQ_MASK32(irq));
    }

    oitr = in32(OCB_OITR(irq));
    if (trigger == SSX_IRQ_TRIGGER_EDGE_SENSITIVE) {
        out32(OCB_OITR(irq), oitr | PGP_IRQ_MASK32(irq));
    } else {
        out32(OCB_OITR(irq), oitr & ~PGP_IRQ_MASK32(irq));
    }

    ssx_critical_section_exit(&ctx);

    return SSX_OK;
}


/// (Re)define the IRQ handler and priority for an interrupt.
/// Return values other then SSX_OK (0) are errors; see \ref ssx_errors
///
/// Note that SSX allows this API to be called from any context, and changes
/// to the interrupt controller are made from an SSX_CRITICAL critical
/// section.
///
/// \retval 0 Successful completion
///
/// \retval -SSX_INVALID_ARGUMENT_IRQ_HANDLER One or more arguments are 
/// invalid, including an invalid \a irq, a  null (0) \a handler, 
/// or invalid \a priority.

int
ssx_irq_handler_set(SsxIrqId      irq,
                    SsxIrqHandler handler,
                    void          *arg,
                    int           priority)
{
    SsxMachineContext ctx;
    uint32_t ocir;

    if (SSX_ERROR_CHECK_API) {
        SSX_ERROR_IF(!PGP_IRQ_VALID(irq) ||
                     (handler == 0) ||
                     !((priority == SSX_NONCRITICAL) ||
                       (priority == SSX_CRITICAL)),
                     SSX_INVALID_ARGUMENT_IRQ_HANDLER);
    }

    ssx_critical_section_enter(SSX_CRITICAL, &ctx);

    ocir = in32(OCB_OCIR(irq));
    if (priority == SSX_CRITICAL) {
        out32(OCB_OCIR(irq), ocir | PGP_IRQ_MASK32(irq));
    } else {
        out32(OCB_OCIR(irq), ocir & ~PGP_IRQ_MASK32(irq));
    }

    __ppc405_irq_handlers[irq].handler = handler;
    __ppc405_irq_handlers[irq].arg = arg;

    ssx_critical_section_exit(&ctx);

    return SSX_OK;
}


/// Set or clear interrupt debug mode explicitly.

void
ssx_irq_debug_set(SsxIrqId irq, int value)
{
    SsxMachineContext ctx;
    uint32_t ouder;

    ssx_critical_section_enter(SSX_CRITICAL, &ctx);

    ouder = in32(OCB_OUDER(irq));
    if (value) {
        out32(OCB_OUDER(irq), ouder | PGP_IRQ_MASK32(irq));
    } else {
        out32(OCB_OUDER(irq), ouder & ~PGP_IRQ_MASK32(irq));
    }

    ssx_critical_section_exit(&ctx);
}


    

    
        

    

    
    


    
OpenPOWER on IntegriCloud