summaryrefslogtreecommitdiffstats
path: root/private/ntos/nthals/halppc/ppc/pxflshio.c
blob: 681d199129e358f527b660ed747c998e1f963cd4 (plain) (blame)
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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197

/*++

Copyright (c) 1991-1993  Microsoft Corporation
        Copyright 1994 MOTOROLA, INC.  All Rights Reserved.  This file
        contains copyrighted material.  Use of this file is restricted
        by the provisions of a Motorola Software License Agreement.

Module Name:

    psflshio.c

Abstract:

    This module implements miscellaneous PowerPC HAL functions.

Author:

    Jim Wooldridge  (jimw@austin.ibm.com)

Environment:

    Kernel mode

Revision History:

--*/

#include "halp.h"
#include "arccodes.h"

//
// Prototypes.
//

VOID
HalpSweepPhysicalRangeInBothCaches(
    ULONG StartingPage,
    ULONG Offset,
    ULONG Length
    );

VOID
HalpSweepPhysicalIcacheRange(
    ULONG StartingPage,
    ULONG Offset,
    ULONG Length
    );


ULONG
HalGetDmaAlignmentRequirement (
    VOID
    )

/*++

Routine Description:

    This function returns the alignment requirements for DMA transfers on
    host system.

Arguments:

    None.

Return Value:

    The DMA alignment requirement is returned as the fucntion value.

--*/

{

    return 1;
}

VOID
HalFlushIoBuffers (
    IN PMDL Mdl,
    IN BOOLEAN ReadOperation,
    IN BOOLEAN DmaOperation
    )

/*++

Routine Description:

    This function flushes the I/O buffer specified by the memory descriptor
    list from the data cache on the current processor.

Arguments:

    Mdl - Supplies a pointer to a memory descriptor list that describes the
        I/O buffer location.

    ReadOperation - Supplies a boolean value that determines whether the I/O
        operation is a read into memory.

    DmaOperation - Supplies a boolean value that determines whether the I/O
        operation is a DMA operation.

Return Value:

    None.

--*/

{

    ULONG Length;
    ULONG PartialLength;
    ULONG Offset;
    PULONG Page;
    BOOLEAN DoDcache = FALSE;

    Length = Mdl->ByteCount;

    if ( !Length ) {
        return;
    }
    //
    // If the I/O operation is not a DMA operation,
    // and the  I/O operation is a page read operation,
    // then sweep (index/writeback/invalidate) the data cache.
    //

    if (((DmaOperation == FALSE) &&
        (ReadOperation != FALSE) &&
        ((Mdl->MdlFlags & MDL_IO_PAGE_READ) != 0))) {
        DoDcache = TRUE;
    }

    //
    // If the I/O operation is a page read, then sweep (index/invalidate)
    // the range from the cache.  Note it is not reasonable to sweep
    // the entire cache on an MP system as "Flash Invalidate" doesn't
    // broadcast the invalidate to other processors.
    //

    if ((ReadOperation != FALSE) &&
        ((Mdl->MdlFlags & MDL_IO_PAGE_READ) != 0)) {

        Offset = Mdl->ByteOffset;
        PartialLength = PAGE_SIZE - Offset;
        if (PartialLength > Length) {
            PartialLength = Length;
        }

        Page = (PULONG)(Mdl + 1);

        if (DoDcache == TRUE) {
            HalpSweepPhysicalRangeInBothCaches(
                *Page++,
                Offset,
                PartialLength
                );
            Length -= PartialLength;
            if (Length) {
                PartialLength = PAGE_SIZE;
                do {
                    if (PartialLength > Length) {
                        PartialLength = Length;
                    }
                    HalpSweepPhysicalRangeInBothCaches(
                        *Page++,
                        0,
                        PartialLength
                        );
                    Length -= PartialLength;
                } while (Length != 0);
            }
        } else {
            HalpSweepPhysicalIcacheRange(
                *Page++,
                Offset,
                PartialLength
                );
            Length -= PartialLength;
            if (Length) {
                PartialLength = PAGE_SIZE;
                do {
                    if (PartialLength > Length) {
                        PartialLength = Length;
                    }
                    HalpSweepPhysicalIcacheRange(
                        *Page++,
                        0,
                        PartialLength
                        );
                    Length -= PartialLength;
                } while (Length != 0);
            }
        }
    }
    return;
}