diff --git a/arch/arm64/boot/dts/apple/t8152-j873-qspi.dtsi b/arch/arm64/boot/dts/apple/t8152-j873-qspi.dtsi index 538511e3ffc17..e89bd8adb8b1d 100644 --- a/arch/arm64/boot/dts/apple/t8152-j873-qspi.dtsi +++ b/arch/arm64/boot/dts/apple/t8152-j873-qspi.dtsi @@ -51,12 +51,13 @@ #size-cells = <1>; /* - * 64 KiB NVRAM v3 banks ("3VVN") from 0x24000 - * to 0x1f4000, as on T8140 J700. + * 13 x 64 KiB NVRAM v3 banks ("3VVN") from 0x24000 + * to 0xf4000 (ADT /arm-io/qspi/spinor/anvram on the + * 1 MiB W25Q80 boot NOR). */ nvram: partition@24000 { label = "nvram"; - reg = <0x24000 0x1d0000>; + reg = <0x24000 0xd0000>; }; }; }; diff --git a/drivers/spi/spi-apple-qspi-policy-test.c b/drivers/spi/spi-apple-qspi-policy-test.c index 0383e506b5338..d73a851a81932 100644 --- a/drivers/spi/spi-apple-qspi-policy-test.c +++ b/drivers/spi/spi-apple-qspi-policy-test.c @@ -154,6 +154,9 @@ static void qspi_policy_status(struct kunit *test) KUNIT_EXPECT_TRUE(test, apple_qspi_status_allows_write(0x04, 0x02, 0, 0x1c)); /* The J813 W25Q64: QE and the SR3 drive strength, no block protection. */ KUNIT_EXPECT_TRUE(test, apple_qspi_status_allows_write(0x00, 0x02, 0x60, 0)); + /* The J873g W25Q80: QE and SR3 0x20, no block protection. */ + KUNIT_EXPECT_TRUE(test, apple_qspi_status_allows_write(0x00, 0x02, 0x20, 0)); + KUNIT_EXPECT_FALSE(test, apple_qspi_status_allows_write(0x04, 0x02, 0x20, 0)); /* CMP, SUS and WPS are refused everywhere. */ KUNIT_EXPECT_FALSE(test, apple_qspi_status_allows_write(0, 0x40, 0, 0x1c)); KUNIT_EXPECT_FALSE(test, apple_qspi_status_allows_write(0, 0x80, 0, 0x1c)); @@ -277,15 +280,17 @@ static void qspi_policy_parts(struct kunit *test) static const unsigned char known[][3] = { { 0xef, 0x65, 0x17 }, { 0xc2, 0x2b, 0x27 }, { 0xef, 0x65, 0x15 }, { 0xc8, 0x83, 0x15 }, - { 0xc8, 0x83, 0x17 }, + { 0xc8, 0x83, 0x17 }, { 0xef, 0x65, 0x14 }, }; static const unsigned int sizes[] = { 0x800000, 0x800000, 0x200000, 0x200000, - 0x800000 }; - static const unsigned char bp_ok[] = { 0, 0, 0x1c, 0x1c, 0 }; + 0x800000, 0x100000 }; + static const unsigned int sfdp_sizes[] = { 0x800000, 0x800000, 0x200000, 0x200000, + 0x800000, 0x200000 }; + static const unsigned char bp_ok[] = { 0, 0, 0x1c, 0x1c, 0, 0 }; static const unsigned char unknown[][3] = { - { 0xef, 0x65, 0x16 }, { 0xef, 0x40, 0x17 }, { 0xc2, 0x2b, 0x28 }, - { 0xc8, 0x60, 0x15 }, { 0xc8, 0x83, 0x16 }, { 0xc8, 0x83, 0x18 }, - { 0, 0, 0 }, { 0xff, 0xff, 0xff }, + { 0xef, 0x65, 0x13 }, { 0xef, 0x65, 0x16 }, { 0xef, 0x40, 0x17 }, + { 0xc2, 0x2b, 0x28 }, { 0xc8, 0x60, 0x15 }, { 0xc8, 0x83, 0x16 }, + { 0xc8, 0x83, 0x18 }, { 0, 0, 0 }, { 0xff, 0xff, 0xff }, }; const struct apple_qspi_part *part; unsigned int i; @@ -294,6 +299,7 @@ static void qspi_policy_parts(struct kunit *test) part = apple_qspi_find_part(known[i]); KUNIT_ASSERT_NOT_NULL(test, part); KUNIT_EXPECT_EQ(test, part->size, sizes[i]); + KUNIT_EXPECT_EQ(test, apple_qspi_part_sfdp_size(part), sfdp_sizes[i]); KUNIT_EXPECT_EQ(test, part->bp_ok, bp_ok[i]); } for (i = 0; i < ARRAY_SIZE(unknown); i++) @@ -302,6 +308,10 @@ static void qspi_policy_parts(struct kunit *test) part = apple_qspi_find_part(known[2]); KUNIT_EXPECT_LE(test, 0x1f4000ULL, (unsigned long long)part->size); KUNIT_EXPECT_GT(test, 0x800000ULL, (unsigned long long)part->size); + /* The J873g 13-bank window fits 1 MiB; an oversized 2 MiB J700 window does not. */ + part = apple_qspi_find_part(known[5]); + KUNIT_EXPECT_LE(test, 0xf4000ULL, (unsigned long long)part->size); + KUNIT_EXPECT_GT(test, 0x1f4000ULL, (unsigned long long)part->size); } static void qspi_policy_protected(struct kunit *test) diff --git a/drivers/spi/spi-apple-qspi-policy.h b/drivers/spi/spi-apple-qspi-policy.h index 0a8e502cfcbb4..54a5f6dfd7f8c 100644 --- a/drivers/spi/spi-apple-qspi-policy.h +++ b/drivers/spi/spi-apple-qspi-policy.h @@ -156,19 +156,22 @@ static inline int apple_qspi_nvram_bank_state(const unsigned char h[24]) /* * The boot NOR parts whose nvram partition may be written: the JEDEC ID, the - * size, which bounds the window (a three-byte address past it wraps around) - * and must match the part's SFDP density, and the SR1 block-protect bits the - * part's firmware leaves set. Those stay set; apple_qspi_protected_range() - * says what they protect. + * physical size, which bounds the window (a three-byte address past it wraps + * around), the SR1 block-protect bits the part's firmware leaves set, and + * optionally sfdp_size when a part's factory SFDP density differs from its + * physical size (0 means SFDP density must equal size). Protected bits stay + * set; apple_qspi_protected_range() says what they protect. */ struct apple_qspi_part { unsigned char jedec[3]; unsigned int size; unsigned char bp_ok; + unsigned int sfdp_size; }; #define APPLE_QSPI_JEDEC_W25Q64 { 0xef, 0x65, 0x17 } #define APPLE_QSPI_JEDEC_W25Q16 { 0xef, 0x65, 0x15 } +#define APPLE_QSPI_JEDEC_W25Q80 { 0xef, 0x65, 0x14 } #define APPLE_QSPI_JEDEC_MX_2B27 { 0xc2, 0x2b, 0x27 } #define APPLE_QSPI_JEDEC_GD25UF16E { 0xc8, 0x83, 0x15 } #define APPLE_QSPI_JEDEC_GD25UF64E { 0xc8, 0x83, 0x17 } @@ -184,8 +187,20 @@ static const struct apple_qspi_part apple_qspi_parts[] = { { APPLE_QSPI_JEDEC_GD25UF16E, 0x200000, 0x1c }, /* J775D (M5 Ultra): no block protection left set, SR1 0x00 */ { APPLE_QSPI_JEDEC_GD25UF64E, 0x800000, 0 }, + /* + * J873g (Mac mini, M6): 1 MiB die (wraps at 0x100000, ADT spinor + * ranges 0x100000), no BP bits (SR1 0x00, SR2 0x02, SR3 0x20), + * factory SFDP BFPT reports 16 Mbit (0x00ffffff = 0x200000). + */ + { APPLE_QSPI_JEDEC_W25Q80, 0x100000, 0, 0x200000 }, }; +static inline unsigned int +apple_qspi_part_sfdp_size(const struct apple_qspi_part *part) +{ + return part->sfdp_size ? part->sfdp_size : part->size; +} + static inline const struct apple_qspi_part * apple_qspi_find_part(const unsigned char id[3]) { diff --git a/drivers/spi/spi-apple-qspi.c b/drivers/spi/spi-apple-qspi.c index 9b1e1bcaf8954..aaa76d2375dfd 100644 --- a/drivers/spi/spi-apple-qspi.c +++ b/drivers/spi/spi-apple-qspi.c @@ -716,7 +716,8 @@ static int apple_qspi_qualify(struct spi_mem *mem, struct apple_qspi *qspi, ret = apple_qspi_read_sfdp(mem, table, dword, sizeof(dword)); if (ret) return ret; - if (apple_qspi_sfdp_size(get_unaligned_le32(&dword[4])) != part->size) { + if (apple_qspi_sfdp_size(get_unaligned_le32(&dword[4])) != + apple_qspi_part_sfdp_size(part)) { *denial = "part-size"; ret = -ENODEV; goto latch; diff --git a/tools/asahi/qspi-nvram-tests.py b/tools/asahi/qspi-nvram-tests.py index b34f00178013c..7191853b72c95 100644 --- a/tools/asahi/qspi-nvram-tests.py +++ b/tools/asahi/qspi-nvram-tests.py @@ -167,16 +167,17 @@ def function(source, signature): static bool sent(unsigned int o){for(unsigned int i=0;isize==sizes[i]&&part->bp_ok==tolerated[i]); + assert(part&&part->size==sizes[i]&&apple_qspi_part_sfdp_size(part)==sfdp_sizes[i]&&part->bp_ok==tolerated[i]); } - const u8 unknown[][3]={{0xef,0x65,0x16},{0xef,0x65,0x18},{0xc2,0x2b,0x28},{0xc8,0x60,0x15},{0xef,0x40,0x17},{0,0,0},{0xff,0xff,0xff}}; + const u8 unknown[][3]={{0xef,0x65,0x13},{0xef,0x65,0x16},{0xef,0x65,0x18},{0xc2,0x2b,0x28},{0xc8,0x60,0x15},{0xef,0x40,0x17},{0,0,0},{0xff,0xff,0xff}}; for(unsigned int i=0;iaddr.val < qspi->write_start || op->addr.val + len > qspi->write_end', '0'), ('protected-qualify', '!apple_qspi_unprotected_banks(', '0 && !apple_qspi_unprotected_banks('), - ('sfdp-size', '!= part->size) {', '!= part->size && 0) {'), + ('sfdp-size', 'apple_qspi_part_sfdp_size(part)) {', + 'apple_qspi_part_sfdp_size(part) && 0) {'), ('window-read-only', '!read_only && size &&', 'size &&'), ('window-bank', '!(size % APPLE_QSPI_NVRAM_BANK) &&', ''), ('range', 'addr >= start &&', 'addr >= 1 &&'), @@ -489,6 +511,10 @@ def main(): 'APPLE_QSPI_JEDEC_GD25UF16E\t{ 0xc8, 0x83, 0x16 }'), ('j775d-gd-id', 'APPLE_QSPI_JEDEC_GD25UF64E\t{ 0xc8, 0x83, 0x17 }', 'APPLE_QSPI_JEDEC_GD25UF64E\t{ 0xc8, 0x83, 0x18 }'), + ('j873g-w25q80-id', 'APPLE_QSPI_JEDEC_W25Q80\t\t{ 0xef, 0x65, 0x14 }', + 'APPLE_QSPI_JEDEC_W25Q80\t\t{ 0xef, 0x65, 0x13 }'), + ('j873g-w25q80-size', '{ APPLE_QSPI_JEDEC_W25Q80, 0x100000, 0, 0x200000 }', + '{ APPLE_QSPI_JEDEC_W25Q80, 0x200000, 0, 0x200000 }'), ('read-only', 'read_only || !qspi->nvram_write_candidate || qspi->write_fault', '!qspi->nvram_write_candidate || qspi->write_fault'), ('fault-latch', 'write_fault_latched = true;', 'write_fault_latched = false;'),