1*c2c66affSColin Finck /*
2*c2c66affSColin Finck * COPYRIGHT: See COPYING.ARM in the top level directory
3*c2c66affSColin Finck * PROJECT: ReactOS UEFI Boot Library
4*c2c66affSColin Finck * FILE: boot/environ/lib/io/blkcache.c
5*c2c66affSColin Finck * PURPOSE: Boot Library Block Cache Management Routines
6*c2c66affSColin Finck * PROGRAMMER: Alex Ionescu (alex.ionescu@reactos.org)
7*c2c66affSColin Finck */
8*c2c66affSColin Finck
9*c2c66affSColin Finck /* INCLUDES ******************************************************************/
10*c2c66affSColin Finck
11*c2c66affSColin Finck #include "bl.h"
12*c2c66affSColin Finck
13*c2c66affSColin Finck /* DATA VARIABLES ************************************************************/
14*c2c66affSColin Finck
15*c2c66affSColin Finck ULONG BcpBlockAllocatorHandle;
16*c2c66affSColin Finck ULONG BcpHashTableId;
17*c2c66affSColin Finck
18*c2c66affSColin Finck /* FUNCTIONS *****************************************************************/
19*c2c66affSColin Finck
20*c2c66affSColin Finck NTSTATUS
BcpDestroy(VOID)21*c2c66affSColin Finck BcpDestroy (
22*c2c66affSColin Finck VOID
23*c2c66affSColin Finck )
24*c2c66affSColin Finck {
25*c2c66affSColin Finck //BcpPurgeCacheEntries();
26*c2c66affSColin Finck //return BlpMmDeleteBlockAllocator(BcpBlockAllocatorHandle);
27*c2c66affSColin Finck EfiPrintf(L"Destructor for block cache not yet implemented\r\n");
28*c2c66affSColin Finck return STATUS_NOT_IMPLEMENTED;
29*c2c66affSColin Finck }
30*c2c66affSColin Finck
31*c2c66affSColin Finck BOOLEAN
BcpCompareKey(_In_ PBL_HASH_ENTRY Entry1,_In_ PBL_HASH_ENTRY Entry2)32*c2c66affSColin Finck BcpCompareKey (
33*c2c66affSColin Finck _In_ PBL_HASH_ENTRY Entry1,
34*c2c66affSColin Finck _In_ PBL_HASH_ENTRY Entry2
35*c2c66affSColin Finck )
36*c2c66affSColin Finck {
37*c2c66affSColin Finck PULONG Value1, Value2;
38*c2c66affSColin Finck
39*c2c66affSColin Finck Value1 = Entry1->Value;
40*c2c66affSColin Finck Value2 = Entry2->Value;
41*c2c66affSColin Finck return Entry1->Size == Entry2->Size && Entry1->Flags == Entry2->Flags && *Value1 == *Value2 && Value1[1] == Value2[1] && Value1[2] == Value2[2];
42*c2c66affSColin Finck }
43*c2c66affSColin Finck
44*c2c66affSColin Finck ULONG
BcpHashFunction(_In_ PBL_HASH_ENTRY Entry,_In_ ULONG TableSize)45*c2c66affSColin Finck BcpHashFunction (
46*c2c66affSColin Finck _In_ PBL_HASH_ENTRY Entry,
47*c2c66affSColin Finck _In_ ULONG TableSize
48*c2c66affSColin Finck )
49*c2c66affSColin Finck {
50*c2c66affSColin Finck ULONG i, j, ValueHash;
51*c2c66affSColin Finck PUCHAR ValueBuffer;
52*c2c66affSColin Finck
53*c2c66affSColin Finck j = 0;
54*c2c66affSColin Finck ValueHash = 0;
55*c2c66affSColin Finck i = 0;
56*c2c66affSColin Finck
57*c2c66affSColin Finck ValueBuffer = Entry->Value;
58*c2c66affSColin Finck
59*c2c66affSColin Finck do
60*c2c66affSColin Finck {
61*c2c66affSColin Finck ValueHash += ValueBuffer[i++];
62*c2c66affSColin Finck } while (i < 8);
63*c2c66affSColin Finck
64*c2c66affSColin Finck do
65*c2c66affSColin Finck {
66*c2c66affSColin Finck ValueHash += ValueBuffer[j++ + 8];
67*c2c66affSColin Finck } while (j < 4);
68*c2c66affSColin Finck
69*c2c66affSColin Finck return ValueHash % TableSize;
70*c2c66affSColin Finck }
71*c2c66affSColin Finck
72*c2c66affSColin Finck NTSTATUS
BcInitialize(VOID)73*c2c66affSColin Finck BcInitialize (
74*c2c66affSColin Finck VOID
75*c2c66affSColin Finck )
76*c2c66affSColin Finck {
77*c2c66affSColin Finck NTSTATUS Status;
78*c2c66affSColin Finck
79*c2c66affSColin Finck Status = BlHtCreate(50, BcpHashFunction, BcpCompareKey, &BcpHashTableId);
80*c2c66affSColin Finck if (!NT_SUCCESS(Status))
81*c2c66affSColin Finck {
82*c2c66affSColin Finck goto Quickie;
83*c2c66affSColin Finck }
84*c2c66affSColin Finck
85*c2c66affSColin Finck BcpBlockAllocatorHandle = BlpMmCreateBlockAllocator();
86*c2c66affSColin Finck if (BcpBlockAllocatorHandle == -1)
87*c2c66affSColin Finck {
88*c2c66affSColin Finck Status = STATUS_UNSUCCESSFUL;
89*c2c66affSColin Finck goto Quickie;
90*c2c66affSColin Finck }
91*c2c66affSColin Finck
92*c2c66affSColin Finck Status = BlpIoRegisterDestroyRoutine(BcpDestroy);
93*c2c66affSColin Finck if (Status >= 0)
94*c2c66affSColin Finck {
95*c2c66affSColin Finck return Status;
96*c2c66affSColin Finck }
97*c2c66affSColin Finck
98*c2c66affSColin Finck Quickie:
99*c2c66affSColin Finck EfiPrintf(L"Failure path not yet implemented\r\n");
100*c2c66affSColin Finck #if 0
101*c2c66affSColin Finck if (BcpHashTableId != -1)
102*c2c66affSColin Finck {
103*c2c66affSColin Finck BlHtDestroy(BcpHashTableId);
104*c2c66affSColin Finck }
105*c2c66affSColin Finck if (BcpBlockAllocatorHandle != -1)
106*c2c66affSColin Finck {
107*c2c66affSColin Finck BlpMmDeleteBlockAllocator(BcpBlockAllocatorHandle);
108*c2c66affSColin Finck }
109*c2c66affSColin Finck #endif
110*c2c66affSColin Finck return Status;
111*c2c66affSColin Finck }
112