Simplify the SmmPeriodicSmiLib to call AllocatePool() for every entry in the SMI periodic handler list.

Signed-off-by: niruiyu
Reviewed-by: mdkinney

git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@12173 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
niruiyu 2011-08-19 01:37:47 +00:00
parent ca8afbca68
commit 3e5cfe98e9
1 changed files with 11 additions and 43 deletions

View File

@ -315,8 +315,6 @@ ReclaimPeriodicSmiLibraryHandler (
PERIODIC_SMI_LIBRARY_HANDLER_CONTEXT *PeriodicSmiLibraryHandler PERIODIC_SMI_LIBRARY_HANDLER_CONTEXT *PeriodicSmiLibraryHandler
) )
{ {
LIST_ENTRY *Link;
ASSERT (PeriodicSmiLibraryHandler->DispatchHandle == NULL); ASSERT (PeriodicSmiLibraryHandler->DispatchHandle == NULL);
if (PeriodicSmiLibraryHandler->Stack != NULL) { if (PeriodicSmiLibraryHandler->Stack != NULL) {
FreePages ( FreePages (
@ -326,18 +324,7 @@ ReclaimPeriodicSmiLibraryHandler (
PeriodicSmiLibraryHandler->Stack = NULL; PeriodicSmiLibraryHandler->Stack = NULL;
} }
RemoveEntryList (&PeriodicSmiLibraryHandler->Link); RemoveEntryList (&PeriodicSmiLibraryHandler->Link);
// InsertHeadList (&gFreePeriodicSmiLibraryHandlers, &PeriodicSmiLibraryHandler->Link);
// Insert to gFreePeriodicSmiLibraryHandlers in the reverse order of the address of PeriodicSmiLibraryHandler
//
for ( Link = GetFirstNode (&gFreePeriodicSmiLibraryHandlers)
; !IsNull (&gFreePeriodicSmiLibraryHandlers, Link)
; Link = GetNextNode (&gFreePeriodicSmiLibraryHandlers, Link)
) {
if (Link < &PeriodicSmiLibraryHandler->Link) {
break;
}
}
InsertTailList (Link, &PeriodicSmiLibraryHandler->Link);
} }
/** /**
@ -354,30 +341,21 @@ EnlargeFreePeriodicSmiLibraryHandlerList (
) )
{ {
UINTN Index; UINTN Index;
PERIODIC_SMI_LIBRARY_HANDLER_CONTEXT *PeriodicSmiLibraryHandlers; PERIODIC_SMI_LIBRARY_HANDLER_CONTEXT *PeriodicSmiLibraryHandler;
// //
// The function is assumed to be called only when the list of free periodic SMI library // Add the entries to the list
// handlers is empty.
//
ASSERT (IsListEmpty (&gFreePeriodicSmiLibraryHandlers));
PeriodicSmiLibraryHandlers = AllocatePool (
PERIODIC_SMI_LIBRARY_ALLOCATE_SIZE * sizeof (PERIODIC_SMI_LIBRARY_HANDLER_CONTEXT)
);
if (PeriodicSmiLibraryHandlers == NULL) {
return FALSE;
}
//
// Add the entries to the list in the reverse order of the their memory address
// //
for (Index = 0; Index < PERIODIC_SMI_LIBRARY_ALLOCATE_SIZE; Index++) { for (Index = 0; Index < PERIODIC_SMI_LIBRARY_ALLOCATE_SIZE; Index++) {
PeriodicSmiLibraryHandlers[Index].Signature = PERIODIC_SMI_LIBRARY_HANDLER_CONTEXT_SIGNATURE; PeriodicSmiLibraryHandler = AllocatePool (sizeof (PERIODIC_SMI_LIBRARY_HANDLER_CONTEXT));
InsertHeadList (&gFreePeriodicSmiLibraryHandlers, &PeriodicSmiLibraryHandlers[Index].Link); if (PeriodicSmiLibraryHandler == NULL) {
break;
}
PeriodicSmiLibraryHandler->Signature = PERIODIC_SMI_LIBRARY_HANDLER_CONTEXT_SIGNATURE;
InsertHeadList (&gFreePeriodicSmiLibraryHandlers, &PeriodicSmiLibraryHandler->Link);
} }
return TRUE; return (BOOLEAN) (Index > 0);
} }
/** /**
@ -1175,7 +1153,6 @@ SmmPeriodicSmiLibDestructor (
{ {
LIST_ENTRY *Link; LIST_ENTRY *Link;
PERIODIC_SMI_LIBRARY_HANDLER_CONTEXT *PeriodicSmiLibraryHandler; PERIODIC_SMI_LIBRARY_HANDLER_CONTEXT *PeriodicSmiLibraryHandler;
UINTN Index;
// //
// Free the table of supported periodic SMI tick rates // Free the table of supported periodic SMI tick rates
@ -1196,19 +1173,10 @@ SmmPeriodicSmiLibDestructor (
// //
// Free all the periodic SMI handler entries // Free all the periodic SMI handler entries
// //
Index = 0;
for (Link = GetFirstNode (&gFreePeriodicSmiLibraryHandlers); !IsNull (&gFreePeriodicSmiLibraryHandlers, Link);) { for (Link = GetFirstNode (&gFreePeriodicSmiLibraryHandlers); !IsNull (&gFreePeriodicSmiLibraryHandlers, Link);) {
PeriodicSmiLibraryHandler = PERIODIC_SMI_LIBRARY_HANDLER_CONTEXT_FROM_LINK (Link); PeriodicSmiLibraryHandler = PERIODIC_SMI_LIBRARY_HANDLER_CONTEXT_FROM_LINK (Link);
Link = RemoveEntryList (Link); Link = RemoveEntryList (Link);
Index++; FreePool (PeriodicSmiLibraryHandler);
//
// Because the entries in the list are in the reverse order of the address of PeriodicSmiLibraryHandler and
// every PERIODIC_SMI_LIBRARY_ALLOCATE_SIZE entries are in the same pool returned by AllocatePool(),
// every PERIODIC_SMI_LIBRARY_ALLOCATE_SIZE'th entry is the header of allocated pool.
//
if ((Index % PERIODIC_SMI_LIBRARY_ALLOCATE_SIZE) == 0) {
FreePool (PeriodicSmiLibraryHandler);
}
} }
return EFI_SUCCESS; return EFI_SUCCESS;