master
h 68 lines 2.11 KB
Raw
1 /*
2 * BCM2835 One-Time Programmable (OTP) Memory
3 *
4 * Copyright (c) 2024 Rayhan Faizel <rayhan.faizel@gmail.com>
5 *
6 * SPDX-License-Identifier: MIT
7 */
8
9 #ifndef BCM2835_OTP_H
10 #define BCM2835_OTP_H
11
12 #include "hw/core/sysbus.h"
13 #include "qom/object.h"
14
15 #define TYPE_BCM2835_OTP "bcm2835-otp"
16 OBJECT_DECLARE_SIMPLE_TYPE(BCM2835OTPState, BCM2835_OTP)
17
18 #define BCM2835_OTP_ROW_COUNT 66
19
20 /* https://elinux.org/BCM2835_registers#OTP */
21 #define BCM2835_OTP_BOOTMODE_REG 0x00
22 #define BCM2835_OTP_CONFIG_REG 0x04
23 #define BCM2835_OTP_CTRL_LO_REG 0x08
24 #define BCM2835_OTP_CTRL_HI_REG 0x0c
25 #define BCM2835_OTP_STATUS_REG 0x10
26 #define BCM2835_OTP_BITSEL_REG 0x14
27 #define BCM2835_OTP_DATA_REG 0x18
28 #define BCM2835_OTP_ADDR_REG 0x1c
29 #define BCM2835_OTP_WRITE_DATA_READ_REG 0x20
30 #define BCM2835_OTP_INIT_STATUS_REG 0x24
31
32
33 /* -- Row 32: Undocumented -- */
34
35 #define BCM2835_OTP_ROW_32 32
36
37 /* Lock OTP Programming (Customer OTP and private key) */
38 #define BCM2835_OTP_ROW_32_LOCK BIT(6)
39
40 /* -- Row 36-43: Customer OTP -- */
41
42 #define BCM2835_OTP_CUSTOMER_OTP 36
43 #define BCM2835_OTP_CUSTOMER_OTP_LEN 8
44
45 /* Magic numbers to lock programming of customer OTP and private key */
46 #define BCM2835_OTP_LOCK_NUM1 0xffffffff
47 #define BCM2835_OTP_LOCK_NUM2 0xaffe0000
48
49 /* -- Row 56-63: Device-specific private key -- */
50
51 #define BCM2835_OTP_PRIVATE_KEY 56
52 #define BCM2835_OTP_PRIVATE_KEY_LEN 8
53
54
55 struct BCM2835OTPState {
56 /* <private> */
57 SysBusDevice parent_obj;
58
59 /* <public> */
60 MemoryRegion iomem;
61 uint32_t otp_rows[BCM2835_OTP_ROW_COUNT];
62 };
63
64
65 uint32_t bcm2835_otp_get_row(BCM2835OTPState *s, unsigned int row);
66 void bcm2835_otp_set_row(BCM2835OTPState *s, unsigned int row, uint32_t value);
67
68 #endif