From patchwork Sun Jun 30 19:24:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aditya Garg X-Patchwork-Id: 808735 Received: from IND01-BMX-obe.outbound.protection.outlook.com (mail-bmxind01olkn2039.outbound.protection.outlook.com [40.92.103.39]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 14F6422094; Sun, 30 Jun 2024 19:24:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.92.103.39 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719775501; cv=fail; b=Qt3bw30t8TzZuiKpzXu3z10KsNmps3yqQCxUPyOcw4YoJSIuaw8AqembVPAxd1N8XvZ+EW/YwmlxoDkI0MVArEy81TbWEpXoL3oG3hRGSgXvY2rAh6C618p5JYE3WW7vwpo5N+XonuihWuToBeutIVNZ2wW3oVRAQ8Gjko6CllY= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719775501; c=relaxed/simple; bh=xsVhpxSe0ap9PedKD0bcUV28LFfOcKDLOBhMcmGllx0=; h=From:To:CC:Subject:Date:Message-ID:Content-Type:MIME-Version; b=mBntBWk5YVLKNkqjr0AxEXHwFEJeZ8ocoIYl5tZAvoIPSaExobhr0z32YbTVM3v9gHJsf77yzjKFX/chaDSBf4AGxpnwmKFPdcxSmaoj60Uak+0JK/M+t7jFV4T20v5+1ggWSO3FxQuWxEZJcjD5Us/fB4T8Z1gfMX+vauH7gMw= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=live.com; spf=pass smtp.mailfrom=live.com; dkim=pass (2048-bit key) header.d=live.com header.i=@live.com header.b=TgCUbd7d; arc=fail smtp.client-ip=40.92.103.39 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=live.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=live.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=live.com header.i=@live.com header.b="TgCUbd7d" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=W9CoakKPt3I29ooC6p010EgW+qYsu7k1LxQYBL1tqKfMeVrJ541RZo4+8YJtJF/rXhu+Y5VqSowUiaV6xA7tsh7MFm1EGojood//CvJ272/a2o5hQbOJMCsLq5gIG6BMrlW8m8z6myu+1PTDWzTfrrXAtb5Iu8UFDf/N0M61slNbURA8graY0vs3B2W9/lNry06x8+vlKpe5PkPlkENquMTvtaSGnobgbNLxbClmcn+WbFP+Uqkel2wEir0XgHMVMrqUMN8SeP+WhMKgdYoJdT3o+MoThGoh+vprESouLd7c1zND9agywheOI6LzPn27fEU263TtKgQW0UtAskR4Og== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=Z7BenBYfnSQ5rTybFF2nUErtFsChugacaoeahzpAl60=; b=Ku6tdU9VeVMDad8Dzgz1XPytS/uDCnUbSobrjGgGo6EPKBptdciwPtPIFMM+D73Cvit2/yJjk8VAdS+sFdHX5aUnr9jvq23+/jSNGbAonQAO+9m3qFrGnNq3eBycoTyOLr3g0avkmNQXKNh0DWAhFMkK+k+u5xbLiMVBwYoChoDfKwYek3CmqLWWsJKuPxuAFsyyzfKxm1QyjOBMq+f5cDN2YRsVWZYaFkwQgdQb4DWRGHBFFBmoyrc2hcVLhNwmGR4Cztcgw59nC55o9SQP9eS4+gv8lSNqVKlFFCBEJYrfZkRpSDg8aklDIZGM0YmBNB4z+iUJevTaxL/d+q4trw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=live.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Z7BenBYfnSQ5rTybFF2nUErtFsChugacaoeahzpAl60=; b=TgCUbd7dF4SpMvkPAoE7/SkR3JLhQg1tAO52I13RT2XMUrF1GL2zgpxA/GtJs48CvXprNIJyEr9d9Kt0Vbg9t1N6IhE+HMAU2RCqJFPkSSCZVyVmjumQDEB6XBGADuiP2SjJhCqJn+7RC3Nmor6qtk0A+gDzttCtoENG0C9Gl0X3WV8tfttaIX07Rl1gsZ0y7QeCUdYuujk5+3Dthu+n5TKepF5vTyRISgNMASvkJYAWqkWHTAaWadG8pCuDX5g0JOtiUeKXmlCXCNdckRGUxhco/QKptBaUKPbV048af5tMQ+C90Lq6P98qnFY66df25GRba3kmY3PMFZMxvVOkAA== Received: from MA0P287MB0217.INDP287.PROD.OUTLOOK.COM (2603:1096:a01:b3::9) by PN0P287MB2049.INDP287.PROD.OUTLOOK.COM (2603:1096:c01:1bb::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7719.29; Sun, 30 Jun 2024 19:24:54 +0000 Received: from MA0P287MB0217.INDP287.PROD.OUTLOOK.COM ([fe80::98d2:3610:b33c:435a]) by MA0P287MB0217.INDP287.PROD.OUTLOOK.COM ([fe80::98d2:3610:b33c:435a%7]) with mapi id 15.20.7719.029; Sun, 30 Jun 2024 19:24:54 +0000 From: Aditya Garg To: Ard Biesheuvel , Hans de Goede , Lukas Wunner CC: Linux Kernel Mailing List , "linux-efi@vger.kernel.org" , Kerem Karabay , Orlando Chamberlain Subject: [PATCH v2] efi: libstub: add support for the apple_set_os protocol Thread-Topic: [PATCH v2] efi: libstub: add support for the apple_set_os protocol Thread-Index: AQHayyMvFlnFTIp0RUWwNwMGUJGcQg== Date: Sun, 30 Jun 2024 19:24:54 +0000 Message-ID: <75C90B50-9AB9-4F0A-B2CD-43427354D15C@live.com> Accept-Language: en-IN, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-messagesentrepresentingtype: 1 x-tmn: [8/N0KH7yCT8WQmCVnzOJORy/yOueVHKzkaWgoFPy+5wAnhypcrfgxrQswxnCtK5O] x-ms-publictraffictype: Email x-ms-traffictypediagnostic: MA0P287MB0217:EE_|PN0P287MB2049:EE_ x-ms-office365-filtering-correlation-id: 8491d23d-6a5f-41e3-5455-08dc993a51dd x-microsoft-antispam: BCL:0; ARA:14566002|8060799006|461199028|102099032|4302099013|3412199025|440099028|1602099012; x-microsoft-antispam-message-info: 4CzqB8YYOr8Ml8lrytEzRKF/tX9AecfOsHCyUQaNiIY6BEVAlw7na/8iUeG8+vXsZc8ekKh83nsTWZ9gCcJ2ICIJuhGyHGlV8Btnvz9Qf5Tr40GR09q3DAtAttpScbpiMr+g8ajDGHbbCmeEgZN6mJMsw6JVofy8obPngJbuKeN54TV2Ob+GcJ/i/aofY5+rVcjl/PsACGWGqgZrrP3Xl6cAM5Ujkmn0PjjdODO24IEmwAZ0H6rkgaRFY3wqAxz43Px6lZIvtFy11HiqafzGqsA38B+61i8CN+zu2y/bv/ybCz5v6X7DvztOMf6mPWp4eYlYQqY3hPVd+6i9Nb1rbkyvR5B9JHafcYb2sFyYZtbJ2n96NZvWL/XXRFGOOg8KyQtHF+OtxgP4yXb3vv8/JhS+hI8NE0CJVBuz1Vh3ECxKTCNZKtK5xUtYmjCIK8cMZyLv/Ct7x7qPTwS+vVFlv72UzlC9AYS2LqAQtV4iW4UTTXjWrbjq/mBNVv0QgU2Bbdzpwn9wBpoBbPvHDR+HTBYM7nnUX+bybykpp+cWtmttWjFKIb2Tj/uxVHMge0hgh0Ut9deRKEKaL453cR7mvk4hSU1rR4fobxClCd/dsoBaiBNIg+DhjL6v69aoqdUcN1jysl1F2ak/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XH0lkQ3yt9GSgjA5U1m7eDuF1qfMQJ17iIgvzeDgYUOVI76GfbjPT2BHk6ZuyrIXJRf6gY8WkVHf1J1SoaiHmISmGyr32tSEuVlsxaZH7OsKRhAXVzDr7HqMZigdtiF+kDXozp6jmEiZK55D9vUTzSxPWhSrF5sv7tDbGKHVz07gbJw5bFtpG/xoaA+GEqKL7RAYzEJGF6ULvqfXwg5CkDybYDP9+/FAujdr4ozHc5osVJi4Ykr7oLRM06lBZg7JkMz2jU1ZGqkMGN/5Y6WZdpvRen2C0LJjLmzTAgAceUIU7MdHQtUgQkbEQzLlhCWasaLRqqPiWHMZEPQ5xh4roYZUpRZK/nBNSwubFG1zmwLesMHiWVFxe3OOVynYOtWMtRJa/p3meFzT6hIPh848eWWlTOl1KWU/ Content-ID: <39261093FEF91E49AF92DD08E9A19542@INDP287.PROD.OUTLOOK.COM> Precedence: bulk X-Mailing-List: linux-efi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-OriginatorOrg: sct-15-20-4755-11-msonline-outlook-bafef.templateTenant X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: MA0P287MB0217.INDP287.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-CrossTenant-Network-Message-Id: 8491d23d-6a5f-41e3-5455-08dc993a51dd X-MS-Exchange-CrossTenant-rms-persistedconsumerorg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-CrossTenant-originalarrivaltime: 30 Jun 2024 19:24:54.0348 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-Transport-CrossTenantHeadersStamped: PN0P287MB2049 From: Aditya Garg 0c18184de990 ("platform/x86: apple-gmux: support MMIO gmux on T2 Macs") brought support for T2 Macs in apple-gmux. But in order to use dual GPU, the integrated GPU has to be enabled. On such dual GPU EFI Macs, the EFI stub needs to report that it is booting macOS in order to prevent the firmware from disabling the iGPU. This patch is also applicable for some non T2 Intel Macs. Based on this patch for GRUB by Andreas Heider : https://lists.gnu.org/archive/html/grub-devel/2013-12/msg00442.html Credits also goto Kerem Karabay for helping porting the patch to the Linux kernel. Signed-off-by: Aditya Garg Tested-By: Orlando Chamberlain (MacBookPro16,1) Tested-by: Aditya Garg --- drivers/firmware/efi/libstub/efistub.h | 15 +++++++++++ drivers/firmware/efi/libstub/x86-stub.c | 33 ++++++++++++++++++++++--- include/linux/efi.h | 1 + 3 files changed, 46 insertions(+), 3 deletions(-) diff --git a/drivers/firmware/efi/libstub/efistub.h b/drivers/firmware/efi/libstub/efistub.h index 27abb4ce0..4257a8b7c 100644 --- a/drivers/firmware/efi/libstub/efistub.h +++ b/drivers/firmware/efi/libstub/efistub.h @@ -825,6 +825,21 @@ union apple_properties_protocol { } mixed_mode; }; +typedef union apple_set_os_protocol apple_set_os_protocol_t; + +union apple_set_os_protocol { + struct { + unsigned long version; + efi_status_t (__efiapi *set_os_version) (const char *); + efi_status_t (__efiapi *set_os_vendor) (const char *); + }; + struct { + u32 version; + u32 set_os_version; + u32 set_os_vendor; + } mixed_mode; +}; + typedef u32 efi_tcg2_event_log_format; #define INITRD_EVENT_TAG_ID 0x8F3B22ECU diff --git a/drivers/firmware/efi/libstub/x86-stub.c b/drivers/firmware/efi/libstub/x86-stub.c index 1983fd3bf..1eea4f7ba 100644 --- a/drivers/firmware/efi/libstub/x86-stub.c +++ b/drivers/firmware/efi/libstub/x86-stub.c @@ -225,6 +225,30 @@ static void retrieve_apple_device_properties(struct boot_params *boot_params) } } +static void apple_set_os(void) +{ + efi_guid_t guid = APPLE_SET_OS_PROTOCOL_GUID; + apple_set_os_protocol_t *set_os; + efi_status_t status; + + status = efi_bs_call(locate_protocol, &guid, NULL, (void **)&set_os); + if (status != EFI_SUCCESS) + return; + + if (efi_table_attr(set_os, version) >= 2) { + status = efi_fn_call(set_os, set_os_vendor, "Apple Inc."); + if (status != EFI_SUCCESS) + efi_err("Failed to set OS vendor via apple_set_os\n"); + } + + /* The version being set doesn't seem to matter */ + if (efi_table_attr(set_os, version) > 0) { + status = efi_fn_call(set_os, set_os_version, "Mac OS X 10.9"); + if (status != EFI_SUCCESS) + efi_err("Failed to set OS version via apple_set_os\n"); + } +} + efi_status_t efi_adjust_memory_range_protection(unsigned long start, unsigned long size) { @@ -335,9 +359,12 @@ static const efi_char16_t apple[] = L"Apple"; static void setup_quirks(struct boot_params *boot_params) { - if (IS_ENABLED(CONFIG_APPLE_PROPERTIES) && - !memcmp(efistub_fw_vendor(), apple, sizeof(apple))) - retrieve_apple_device_properties(boot_params); + if (!memcmp(efistub_fw_vendor(), apple, sizeof(apple))) { + if (IS_ENABLED(CONFIG_APPLE_PROPERTIES)) { + retrieve_apple_device_properties(boot_params); + } + apple_set_os(); + } } /* diff --git a/include/linux/efi.h b/include/linux/efi.h index 418e55545..e28873eb1 100644 --- a/include/linux/efi.h +++ b/include/linux/efi.h @@ -385,6 +385,7 @@ void efi_native_runtime_setup(void); #define EFI_MEMORY_ATTRIBUTES_TABLE_GUID EFI_GUID(0xdcfa911d, 0x26eb, 0x469f, 0xa2, 0x20, 0x38, 0xb7, 0xdc, 0x46, 0x12, 0x20) #define EFI_CONSOLE_OUT_DEVICE_GUID EFI_GUID(0xd3b36f2c, 0xd551, 0x11d4, 0x9a, 0x46, 0x00, 0x90, 0x27, 0x3f, 0xc1, 0x4d) #define APPLE_PROPERTIES_PROTOCOL_GUID EFI_GUID(0x91bd12fe, 0xf6c3, 0x44fb, 0xa5, 0xb7, 0x51, 0x22, 0xab, 0x30, 0x3a, 0xe0) +#define APPLE_SET_OS_PROTOCOL_GUID EFI_GUID(0xc5c5da95, 0x7d5c, 0x45e6, 0xb2, 0xf1, 0x3f, 0xd5, 0x2b, 0xb1, 0x00, 0x77) #define EFI_TCG2_PROTOCOL_GUID EFI_GUID(0x607f766c, 0x7455, 0x42be, 0x93, 0x0b, 0xe4, 0xd7, 0x6d, 0xb2, 0x72, 0x0f) #define EFI_TCG2_FINAL_EVENTS_TABLE_GUID EFI_GUID(0x1e2ed096, 0x30e2, 0x4254, 0xbd, 0x89, 0x86, 0x3b, 0xbe, 0xf8, 0x23, 0x25) #define EFI_LOAD_FILE_PROTOCOL_GUID EFI_GUID(0x56ec3091, 0x954c, 0x11d2, 0x8e, 0x3f, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b)