use count for dsdt patches

Signed-off-by: SergeySlice <sergey.slice@gmail.com>
This commit is contained in:
SergeySlice 2022-08-17 13:58:30 +03:00
parent d54c3b9601
commit d5a69286c7
6 changed files with 32 additions and 16 deletions

@ -1 +1 @@
Subproject commit c3b81619a9dd9e1cfcf7b85f2f3107c6517840ea
Subproject commit ac03fdb3174877a17da5b3834104bd5034eea0c8

View File

@ -503,14 +503,18 @@ void PatchAllTables()
Len = FixAny((UINT8*)NewTable, Len,
gSettings.ACPI.DSDT.DSDTPatchArray[i].PatchDsdtFind,
gSettings.ACPI.DSDT.DSDTPatchArray[i].PatchDsdtReplace,
gSettings.ACPI.DSDT.DSDTPatchArray[i].Skip);
gSettings.ACPI.DSDT.DSDTPatchArray[i].Skip,
gSettings.ACPI.DSDT.DSDTPatchArray[i].Count
);
//DBG(" OK\n");
}else{
//DBG("Patching: renaming in bridge\n");
Len = FixRenameByBridge2((UINT8*)NewTable, Len, gSettings.ACPI.DSDT.DSDTPatchArray[i].PatchDsdtTgt,
gSettings.ACPI.DSDT.DSDTPatchArray[i].PatchDsdtFind,
gSettings.ACPI.DSDT.DSDTPatchArray[i].PatchDsdtReplace,
gSettings.ACPI.DSDT.DSDTPatchArray[i].Skip);
gSettings.ACPI.DSDT.DSDTPatchArray[i].Skip,
gSettings.ACPI.DSDT.DSDTPatchArray[i].Count
);
}
}
}

View File

@ -1773,11 +1773,11 @@ UINT32 FixADP1 (UINT8* dsdt, UINT32 len)
return len;
}
UINT32 FixAny (UINT8* dsdt, UINT32 len, const XBuffer<UINT8> ToFind, const XBuffer<UINT8>& ToReplace, uint64_t Skip)
UINT32 FixAny (UINT8* dsdt, UINT32 len, const XBuffer<UINT8> ToFind, const XBuffer<UINT8>& ToReplace, uint64_t Skip, int count)
{
INT32 sizeoffset = 0; // Initialization just to silence warning.
INT32 adr;
UINT32 i;
// UINT32 i;
XBool found = false;
if ( ToFind.isEmpty() || ToReplace.isEmpty() ) {
DBG(" invalid patches!\n");
@ -1803,7 +1803,7 @@ UINT32 FixAny (UINT8* dsdt, UINT32 len, const XBuffer<UINT8> ToFind, const XBuff
sizeoffset = (INT32)(ToFind.size() - ToReplace.size()); // Safe cast because of earlier check
sizeoffset = -sizeoffset;
}
for (i = 20; i < len; ) {
for (UINT32 i = 20; i < len; ) {
adr = FindBin(dsdt + i, len - i, ToFind);
if (adr < 0) {
if (found) {
@ -1828,6 +1828,7 @@ UINT32 FixAny (UINT8* dsdt, UINT32 len, const XBuffer<UINT8> ToFind, const XBuff
len = CorrectOuterMethod(dsdt, len, adr + i - 2, sizeoffset);
len = CorrectOuters(dsdt, len, adr + i - 3, sizeoffset);
i += (UINT32)(adr + ToReplace.size()); // if there is no bug before, it should be safe cast.
if (--count == 0) break;
}else{
MsgLog("Skip i=%d ",i);
i += (UINT32)(adr + ToFind.size()); // if there is no bug before, it should be safe cast.
@ -1839,7 +1840,7 @@ UINT32 FixAny (UINT8* dsdt, UINT32 len, const XBuffer<UINT8> ToFind, const XBuff
}
//new method. by goodwin_c
UINT32 FixRenameByBridge2(UINT8* dsdt, UINT32 len, const XBuffer<UINT8>& TgtBrgName, const XBuffer<UINT8>& ToFind, const XBuffer<UINT8>& ToReplace, uint64_t Skip)
UINT32 FixRenameByBridge2(UINT8* dsdt, UINT32 len, const XBuffer<UINT8>& TgtBrgName, const XBuffer<UINT8>& ToFind, const XBuffer<UINT8>& ToReplace, uint64_t Skip, int count)
{
INT32 adr;
XBool found = false;
@ -1898,7 +1899,8 @@ UINT32 FixRenameByBridge2(UINT8* dsdt, UINT32 len, const XBuffer<UINT8>& TgtBrgN
found = true;
if ( ToReplace.notEmpty() ) {
if ( Skip == 0 ) {
CopyMem(dsdt + BrdADR + adr, ToReplace.data(), ToReplace.size());
CopyMem(dsdt + BrdADR + adr, ToReplace.data(), ToReplace.size());
if (--count == 0) break;
} else {
MsgLog("Skip adr=%d ",adr);
Skip--;
@ -5415,7 +5417,9 @@ void FixBiosDsdt(UINT8* temp, EFI_ACPI_2_0_FIXED_ACPI_DESCRIPTION_TABLE* fadt, c
DsdtLen = FixAny(temp, DsdtLen,
gSettings.ACPI.DSDT.DSDTPatchArray[i].PatchDsdtFind,
gSettings.ACPI.DSDT.DSDTPatchArray[i].PatchDsdtReplace,
gSettings.ACPI.DSDT.DSDTPatchArray[i].Skip);
gSettings.ACPI.DSDT.DSDTPatchArray[i].Skip,
gSettings.ACPI.DSDT.DSDTPatchArray[i].Count
);
}else{
// DBG("Patching: renaming in bridge\n");
@ -5423,7 +5427,9 @@ void FixBiosDsdt(UINT8* temp, EFI_ACPI_2_0_FIXED_ACPI_DESCRIPTION_TABLE* fadt, c
gSettings.ACPI.DSDT.DSDTPatchArray[i].PatchDsdtTgt,
gSettings.ACPI.DSDT.DSDTPatchArray[i].PatchDsdtFind,
gSettings.ACPI.DSDT.DSDTPatchArray[i].PatchDsdtReplace,
gSettings.ACPI.DSDT.DSDTPatchArray[i].Skip);
gSettings.ACPI.DSDT.DSDTPatchArray[i].Skip,
gSettings.ACPI.DSDT.DSDTPatchArray[i].Count
);
}
} else {

View File

@ -50,8 +50,8 @@ FindBin (
INT32 FindBin (UINT8 *dsdt, size_t len, const XBuffer<UINT8>& bin);
UINT32 FixAny (UINT8* dsdt, UINT32 len, const XBuffer<UINT8> ToFind, const XBuffer<UINT8>& ToReplace, uint64_t Skip);
UINT32 FixRenameByBridge2 (UINT8* dsdt, UINT32 len, const XBuffer<UINT8>& TgtBrgName, const XBuffer<UINT8>& ToFind, const XBuffer<UINT8>& ToReplace, uint64_t Skip);
UINT32 FixAny (UINT8* dsdt, UINT32 len, const XBuffer<UINT8> ToFind, const XBuffer<UINT8>& ToReplace, uint64_t Skip, int count);
UINT32 FixRenameByBridge2 (UINT8* dsdt, UINT32 len, const XBuffer<UINT8>& TgtBrgName, const XBuffer<UINT8>& ToFind, const XBuffer<UINT8>& ToReplace, uint64_t Skip, int count);
#endif /* PLATFORM_FIXBIOSDSDT_H_ */

View File

@ -837,6 +837,7 @@ public:
XBuffer<UINT8> PatchDsdtTgt = XBuffer<UINT8>();
INPUT_ITEM PatchDsdtMenuItem = INPUT_ITEM(); // Not read from config.plist. Should be moved out.
uint64_t Skip = 0;
int Count = 0;
#if __cplusplus > 201703L
XBool operator == (const DSDT_Patch&) const = default;
@ -850,6 +851,7 @@ public:
if ( !(PatchDsdtTgt == other.PatchDsdtTgt) ) return false;
if ( !(PatchDsdtMenuItem == other.PatchDsdtMenuItem) ) return false;
if ( !(Skip == other.Skip) ) return false;
if (!(Count == other.Count)) return false;
return true;
}
void takeValueFrom(const ConfigPlistClass::ACPI_Class::DSDT_Class::ACPI_DSDT_Patch_Class& other)
@ -861,6 +863,7 @@ public:
PatchDsdtTgt = other.dgetPatchDsdtTgt();
PatchDsdtMenuItem.BValue = !other.dgetDisabled();
Skip = other.dgetSkip();
Count = other.dgetCount();
}
};

View File

@ -121,9 +121,9 @@ public:
const ACPI_DSDT_Fix& getFixHeaders() const {
// FixHeaders is bit 29, but that's a coincidence with the index of the array. ACPI_DSDT_Fixe_Array[FIX_HEADERS_DEPRECATED] would be wrong.
if ( LString8(ACPI_DSDT_Fixe_Array[29].getNewName()) != "FixHeaders_20000000"_XS8 ) {
log_technical_bug("ACPI_DSDT_Fixe_Array[29].getNewName() != \"FixHeaders_20000000\"");
}
// if ( LString8(ACPI_DSDT_Fixe_Array[29].getNewName()) != "FixHeaders_20000000"_XS8 ) {
// log_technical_bug("ACPI_DSDT_Fixe_Array[29].getNewName() != \"FixHeaders_20000000\"");
// }
return ACPI_DSDT_Fixe_Array[29];
}
@ -164,14 +164,16 @@ if ( xmlPath.contains("ACPI/DSDT/Patches[15]"_XS8) ) {
XmlData Replace = XmlData();
TgtBridgeClass TgtBridge = TgtBridgeClass();
XmlUInt64 Skip = XmlUInt64();
XmlInt32 Count = XmlInt32();
XmlDictField m_fields[6] = {
XmlDictField m_fields[7] = {
{"Comment", Comment},
{"Disabled", Disabled},
{"Find", Find},
{"Replace", Replace},
{"TgtBridge", TgtBridge},
{"Skip", Skip},
{"Count", Count},
};
virtual void getFields(XmlDictField** fields, size_t* nb) override { *fields = m_fields; *nb = sizeof(m_fields)/sizeof(m_fields[0]); };
@ -183,6 +185,7 @@ if ( xmlPath.contains("ACPI/DSDT/Patches[15]"_XS8) ) {
const XBuffer<UINT8>& dgetPatchDsdtReplace() const { return Replace.isDefined() ? Replace.value() : XBuffer<UINT8>::NullXBuffer; };
const XBuffer<UINT8>& dgetPatchDsdtTgt() const { return TgtBridge.isDefined() ? TgtBridge.value() : XBuffer<UINT8>::NullXBuffer; };
const decltype(Skip)::ValueType& dgetSkip() const { return Skip.isDefined() ? Skip.value() : Skip.nullValue; };
const decltype(Count)::ValueType& dgetCount() const { return Count.isDefined() ? Count.value() : Count.nullValue; };
};
protected: