diff options
Diffstat (limited to 'drivers')
65 files changed, 655 insertions, 989 deletions
diff --git a/drivers/ata/sata_sil.c b/drivers/ata/sata_sil.c index 7e4e97d803e..dda712f42cb 100644 --- a/drivers/ata/sata_sil.c +++ b/drivers/ata/sata_sil.c @@ -27,11 +27,7 @@ #include "sata_sil.h" -#ifdef CONFIG_DM_PCI #define virt_to_bus(devno, v) dm_pci_virt_to_mem(devno, (void *) (v)) -#else -#define virt_to_bus(devno, v) pci_virt_to_mem(devno, (void *) (v)) -#endif /* just compatible ahci_ops */ struct sil_ops { @@ -616,11 +612,7 @@ static int sil_init_sata(struct udevice *uc_dev, int dev) #else priv->sil_sata_desc[dev] = sata; priv->port_num = dev; -#ifdef CONFIG_DM_PCI sata->devno = uc_dev->parent; -#else - sata->devno = sata_info.devno; -#endif /* CONFIG_DM_PCI */ #endif sata->id = dev; sata->port = port; diff --git a/drivers/ata/sata_sil.h b/drivers/ata/sata_sil.h index a300c0c3887..bea4322c919 100644 --- a/drivers/ata/sata_sil.h +++ b/drivers/ata/sata_sil.h @@ -21,11 +21,7 @@ struct sil_sata { u16 pio; u16 mwdma; u16 udma; -#ifdef CONFIG_DM_PCI struct udevice *devno; -#else - pci_dev_t devno; -#endif int wcache; int flush; int flush_ext; diff --git a/drivers/bios_emulator/atibios.c b/drivers/bios_emulator/atibios.c index 6c7cc24cbd9..9547470a2f7 100644 --- a/drivers/bios_emulator/atibios.c +++ b/drivers/bios_emulator/atibios.c @@ -230,19 +230,12 @@ This function executes the BIOS POST code on the controller. We assume that at this stage the controller has its I/O and memory space enabled and that all other controllers are in a disabled state. ****************************************************************************/ -#ifdef CONFIG_DM_PCI static void PCI_doBIOSPOST(struct udevice *pcidev, BE_VGAInfo *vga_info, int vesa_mode, struct vbe_mode_info *mode_info) -#else -static void PCI_doBIOSPOST(pci_dev_t pcidev, BE_VGAInfo *vga_info, - int vesa_mode, struct vbe_mode_info *mode_info) -#endif { RMREGS regs; RMSREGS sregs; -#ifdef CONFIG_DM_PCI pci_dev_t bdf; -#endif /* Determine the value to store in AX for BIOS POST. Per the PCI specs, AH must contain the bus and AL must contain the devfn, encoded as @@ -250,14 +243,9 @@ static void PCI_doBIOSPOST(pci_dev_t pcidev, BE_VGAInfo *vga_info, */ memset(®s, 0, sizeof(regs)); memset(&sregs, 0, sizeof(sregs)); -#ifdef CONFIG_DM_PCI bdf = dm_pci_get_bdf(pcidev); regs.x.ax = (int)PCI_BUS(bdf) << 8 | (int)PCI_DEV(bdf) << 3 | (int)PCI_FUNC(bdf); -#else - regs.x.ax = ((int)PCI_BUS(pcidev) << 8) | - ((int)PCI_DEV(pcidev) << 3) | (int)PCI_FUNC(pcidev); -#endif /*Setup the X86 emulator for the VGA BIOS*/ BE_setVGA(vga_info); @@ -300,28 +288,15 @@ NOTE: This function leaves the original memory aperture disabled by leaving it programmed to all 1's. It must be restored to the correct value later. ****************************************************************************/ -#ifdef CONFIG_DM_PCI static u32 PCI_findBIOSAddr(struct udevice *pcidev, int *bar) -#else -static u32 PCI_findBIOSAddr(pci_dev_t pcidev, int *bar) -#endif { u32 base, size; for (*bar = 0x10; *bar <= 0x14; (*bar) += 4) { -#ifdef CONFIG_DM_PCI dm_pci_read_config32(pcidev, *bar, &base); -#else - pci_read_config_dword(pcidev, *bar, &base); -#endif if (!(base & 0x1)) { -#ifdef CONFIG_DM_PCI dm_pci_write_config32(pcidev, *bar, 0xFFFFFFFF); dm_pci_read_config32(pcidev, *bar, &size); -#else - pci_write_config_dword(pcidev, *bar, 0xFFFFFFFF); - pci_read_config_dword(pcidev, *bar, &size); -#endif size = ~(size & ~0xFF) + 1; if (size >= MAX_BIOSLEN) return base & ~0xFF; @@ -344,19 +319,11 @@ necessary). Anyway to fix this we change all I/O mapped base registers and chop off the top bits. ****************************************************************************/ -#ifdef CONFIG_DM_PCI static void PCI_fixupIObase(struct udevice *pcidev, int reg, u32 *base) -#else -static void PCI_fixupIObase(pci_dev_t pcidev, int reg, u32 * base) -#endif { if ((*base & 0x1) && (*base > 0xFFFE)) { *base &= 0xFFFF; -#ifdef CONFIG_DM_PCI dm_pci_write_config32(pcidev, reg, *base); -#else - pci_write_config_dword(pcidev, reg, *base); -#endif } } @@ -371,30 +338,18 @@ Pointers to the mapped BIOS image REMARKS: Maps a pointer to the BIOS image on the graphics card on the PCI bus. ****************************************************************************/ -#ifdef CONFIG_DM_PCI void *PCI_mapBIOSImage(struct udevice *pcidev) -#else -void *PCI_mapBIOSImage(pci_dev_t pcidev) -#endif { u32 BIOSImageBus; int BIOSImageBAR; u8 *BIOSImage; /*Save PCI BAR registers that might get changed*/ -#ifdef CONFIG_DM_PCI dm_pci_read_config32(pcidev, PCI_ROM_ADDRESS, &saveROMBaseAddress); dm_pci_read_config32(pcidev, PCI_BASE_ADDRESS_0, &saveBaseAddress10); dm_pci_read_config32(pcidev, PCI_BASE_ADDRESS_1, &saveBaseAddress14); dm_pci_read_config32(pcidev, PCI_BASE_ADDRESS_2, &saveBaseAddress18); dm_pci_read_config32(pcidev, PCI_BASE_ADDRESS_4, &saveBaseAddress20); -#else - pci_read_config_dword(pcidev, PCI_ROM_ADDRESS, &saveROMBaseAddress); - pci_read_config_dword(pcidev, PCI_BASE_ADDRESS_0, &saveBaseAddress10); - pci_read_config_dword(pcidev, PCI_BASE_ADDRESS_1, &saveBaseAddress14); - pci_read_config_dword(pcidev, PCI_BASE_ADDRESS_2, &saveBaseAddress18); - pci_read_config_dword(pcidev, PCI_BASE_ADDRESS_4, &saveBaseAddress20); -#endif /*Fix up I/O base registers to less than 64K */ if(saveBaseAddress14 != 0) @@ -413,21 +368,12 @@ void *PCI_mapBIOSImage(pci_dev_t pcidev) return NULL; } -#ifdef CONFIG_DM_PCI BIOSImage = dm_pci_bus_to_virt(pcidev, BIOSImageBus, PCI_REGION_MEM, 0, MAP_NOCACHE); /*Change the PCI BAR registers to map it onto the bus.*/ dm_pci_write_config32(pcidev, BIOSImageBAR, 0); dm_pci_write_config32(pcidev, PCI_ROM_ADDRESS, BIOSImageBus | 0x1); -#else - BIOSImage = pci_bus_to_virt(pcidev, BIOSImageBus, - PCI_REGION_MEM, 0, MAP_NOCACHE); - - /*Change the PCI BAR registers to map it onto the bus.*/ - pci_write_config_dword(pcidev, BIOSImageBAR, 0); - pci_write_config_dword(pcidev, PCI_ROM_ADDRESS, BIOSImageBus | 0x1); -#endif udelay(1); /*Check that the BIOS image is valid. If not fail, or return the @@ -447,7 +393,6 @@ pcidev - PCI device info for the video card on the bus REMARKS: Unmaps the BIOS image for the device and restores framebuffer mappings ****************************************************************************/ -#ifdef CONFIG_DM_PCI void PCI_unmapBIOSImage(struct udevice *pcidev, void *BIOSImage) { dm_pci_write_config32(pcidev, PCI_ROM_ADDRESS, saveROMBaseAddress); @@ -456,16 +401,6 @@ void PCI_unmapBIOSImage(struct udevice *pcidev, void *BIOSImage) dm_pci_write_config32(pcidev, PCI_BASE_ADDRESS_2, saveBaseAddress18); dm_pci_write_config32(pcidev, PCI_BASE_ADDRESS_4, saveBaseAddress20); } -#else -void PCI_unmapBIOSImage(pci_dev_t pcidev, void *BIOSImage) -{ - pci_write_config_dword(pcidev, PCI_ROM_ADDRESS, saveROMBaseAddress); - pci_write_config_dword(pcidev, PCI_BASE_ADDRESS_0, saveBaseAddress10); - pci_write_config_dword(pcidev, PCI_BASE_ADDRESS_1, saveBaseAddress14); - pci_write_config_dword(pcidev, PCI_BASE_ADDRESS_2, saveBaseAddress18); - pci_write_config_dword(pcidev, PCI_BASE_ADDRESS_4, saveBaseAddress20); -} -#endif /**************************************************************************** PARAMETERS: @@ -479,22 +414,14 @@ REMARKS: Loads and POST's the display controllers BIOS, directly from the BIOS image we can extract over the PCI bus. ****************************************************************************/ -#ifdef CONFIG_DM_PCI static int PCI_postController(struct udevice *pcidev, uchar *bios_rom, int bios_len, BE_VGAInfo *vga_info, int vesa_mode, struct vbe_mode_info *mode_info) -#else -static int PCI_postController(pci_dev_t pcidev, uchar *bios_rom, int bios_len, - BE_VGAInfo *vga_info, int vesa_mode, - struct vbe_mode_info *mode_info) -#endif { u32 bios_image_len; uchar *mapped_bios; uchar *copy_of_bios; -#ifdef CONFIG_DM_PCI pci_dev_t bdf; -#endif if (bios_rom) { copy_of_bios = bios_rom; @@ -522,16 +449,10 @@ static int PCI_postController(pci_dev_t pcidev, uchar *bios_rom, int bios_len, } /*Save information in vga_info structure*/ -#ifdef CONFIG_DM_PCI bdf = dm_pci_get_bdf(pcidev); vga_info->function = PCI_FUNC(bdf); vga_info->device = PCI_DEV(bdf); vga_info->bus = PCI_BUS(bdf); -#else - vga_info->function = PCI_FUNC(pcidev); - vga_info->device = PCI_DEV(pcidev); - vga_info->bus = PCI_BUS(pcidev); -#endif vga_info->pcidev = pcidev; vga_info->BIOSImage = copy_of_bios; vga_info->BIOSImageLen = bios_image_len; @@ -549,22 +470,13 @@ static int PCI_postController(pci_dev_t pcidev, uchar *bios_rom, int bios_len, return true; } -#ifdef CONFIG_DM_PCI int biosemu_setup(struct udevice *pcidev, BE_VGAInfo **vga_infop) -#else -int biosemu_setup(pci_dev_t pcidev, BE_VGAInfo **vga_infop) -#endif { BE_VGAInfo *VGAInfo; -#ifdef CONFIG_DM_PCI pci_dev_t bdf = dm_pci_get_bdf(pcidev); printf("videoboot: Booting PCI video card bus %d, function %d, device %d\n", PCI_BUS(bdf), PCI_FUNC(bdf), PCI_DEV(bdf)); -#else - printf("videoboot: Booting PCI video card bus %d, function %d, device %d\n", - PCI_BUS(pcidev), PCI_FUNC(pcidev), PCI_DEV(pcidev)); -#endif /*Initialise the x86 BIOS emulator*/ if ((VGAInfo = malloc(sizeof(*VGAInfo))) == NULL) { printf("videoboot: Out of memory!\n"); @@ -582,15 +494,9 @@ void biosemu_set_interrupt_handler(int intnum, int (*int_func)(void)) X86EMU_setupIntrFunc(intnum, (X86EMU_intrFuncs)int_func); } -#ifdef CONFIG_DM_PCI int biosemu_run(struct udevice *pcidev, uchar *bios_rom, int bios_len, BE_VGAInfo *vga_info, int clean_up, int vesa_mode, struct vbe_mode_info *mode_info) -#else -int biosemu_run(pci_dev_t pcidev, uchar *bios_rom, int bios_len, - BE_VGAInfo *vga_info, int clean_up, int vesa_mode, - struct vbe_mode_info *mode_info) -#endif { /*Post all the display controller BIOS'es*/ if (!PCI_postController(pcidev, bios_rom, bios_len, vga_info, @@ -623,12 +529,8 @@ REMARKS: Boots the PCI/AGP video card on the bus using the Video ROM BIOS image and the X86 BIOS emulator module. ****************************************************************************/ -#ifdef CONFIG_DM_PCI int BootVideoCardBIOS(struct udevice *pcidev, BE_VGAInfo **pVGAInfo, int clean_up) -#else -int BootVideoCardBIOS(pci_dev_t pcidev, BE_VGAInfo **pVGAInfo, int clean_up) -#endif { BE_VGAInfo *VGAInfo; int ret; diff --git a/drivers/bios_emulator/bios.c b/drivers/bios_emulator/bios.c index 77c7f94bc63..9596a1fdd3e 100644 --- a/drivers/bios_emulator/bios.c +++ b/drivers/bios_emulator/bios.c @@ -185,21 +185,12 @@ static void X86API int1A(int unused) case 0xB103: /* Find PCI class code */ M.x86.R_AH = DEVICE_NOT_FOUND; #ifdef __KERNEL__ -#ifdef CONFIG_DM_PCI dm_pci_read_config8(_BE_env.vgaInfo.pcidev, PCI_CLASS_PROG, &interface); dm_pci_read_config8(_BE_env.vgaInfo.pcidev, PCI_CLASS_DEVICE, &subclass); dm_pci_read_config8(_BE_env.vgaInfo.pcidev, PCI_CLASS_DEVICE + 1, &baseclass); -#else - pci_read_config_byte(_BE_env.vgaInfo.pcidev, PCI_CLASS_PROG, - &interface); - pci_read_config_byte(_BE_env.vgaInfo.pcidev, PCI_CLASS_DEVICE, - &subclass); - pci_read_config_byte(_BE_env.vgaInfo.pcidev, - PCI_CLASS_DEVICE + 1, &baseclass); -#endif if (M.x86.R_CL == interface && M.x86.R_CH == subclass && (u8) (M.x86.R_ECX >> 16) == baseclass) { #else @@ -218,13 +209,8 @@ static void X86API int1A(int unused) if (M.x86.R_BX == pciSlot) { M.x86.R_AH = SUCCESSFUL; #ifdef __KERNEL__ -# ifdef CONFIG_DM_PCI dm_pci_read_config8(_BE_env.vgaInfo.pcidev, M.x86.R_DI, &M.x86.R_CL); -# else - pci_read_config_byte(_BE_env.vgaInfo.pcidev, M.x86.R_DI, - &M.x86.R_CL); -# endif #else M.x86.R_CL = (u8) PCI_accessReg(M.x86.R_DI, 0, PCI_READ_BYTE, @@ -238,13 +224,8 @@ static void X86API int1A(int unused) if (M.x86.R_BX == pciSlot) { M.x86.R_AH = SUCCESSFUL; #ifdef __KERNEL__ -# ifdef CONFIG_DM_PCI dm_pci_read_config16(_BE_env.vgaInfo.pcidev, M.x86.R_DI, &M.x86.R_CX); -# else - pci_read_config_word(_BE_env.vgaInfo.pcidev, M.x86.R_DI, - &M.x86.R_CX); -# endif #else M.x86.R_CX = (u16) PCI_accessReg(M.x86.R_DI, 0, PCI_READ_WORD, @@ -258,13 +239,8 @@ static void X86API int1A(int unused) if (M.x86.R_BX == pciSlot) { M.x86.R_AH = SUCCESSFUL; #ifdef __KERNEL__ -# ifdef CONFIG_DM_PCI dm_pci_read_config32(_BE_env.vgaInfo.pcidev, M.x86.R_DI, &M.x86.R_ECX); -# else - pci_read_config_dword(_BE_env.vgaInfo.pcidev, - M.x86.R_DI, &M.x86.R_ECX); -# endif #else M.x86.R_ECX = (u32) PCI_accessReg(M.x86.R_DI, 0, PCI_READ_DWORD, @@ -278,13 +254,8 @@ static void X86API int1A(int unused) if (M.x86.R_BX == pciSlot) { M.x86.R_AH = SUCCESSFUL; #ifdef __KERNEL__ -# ifdef CONFIG_DM_PCI dm_pci_write_config8(_BE_env.vgaInfo.pcidev, M.x86.R_DI, M.x86.R_CL); -# else - pci_write_config_byte(_BE_env.vgaInfo.pcidev, - M.x86.R_DI, M.x86.R_CL); -# endif #else PCI_accessReg(M.x86.R_DI, M.x86.R_CL, PCI_WRITE_BYTE, _BE_env.vgaInfo.pciInfo); @@ -297,13 +268,8 @@ static void X86API int1A(int unused) if (M.x86.R_BX == pciSlot) { M.x86.R_AH = SUCCESSFUL; #ifdef __KERNEL__ -# ifdef CONFIG_DM_PCI dm_pci_write_config32(_BE_env.vgaInfo.pcidev, M.x86.R_DI, M.x86.R_CX); -# else - pci_write_config_word(_BE_env.vgaInfo.pcidev, - M.x86.R_DI, M.x86.R_CX); -# endif #else PCI_accessReg(M.x86.R_DI, M.x86.R_CX, PCI_WRITE_WORD, _BE_env.vgaInfo.pciInfo); @@ -316,13 +282,8 @@ static void X86API int1A(int unused) if (M.x86.R_BX == pciSlot) { M.x86.R_AH = SUCCESSFUL; #ifdef __KERNEL__ -# ifdef CONFIG_DM_PCI dm_pci_write_config32(_BE_env.vgaInfo.pcidev, M.x86.R_DI, M.x86.R_ECX); -# else - pci_write_config_dword(_BE_env.vgaInfo.pcidev, - M.x86.R_DI, M.x86.R_ECX); -# endif #else PCI_accessReg(M.x86.R_DI, M.x86.R_ECX, PCI_WRITE_DWORD, _BE_env.vgaInfo.pciInfo); diff --git a/drivers/core/fdtaddr.c b/drivers/core/fdtaddr.c index b9874c743d1..4ffbd6b2ebc 100644 --- a/drivers/core/fdtaddr.c +++ b/drivers/core/fdtaddr.c @@ -200,8 +200,7 @@ fdt_addr_t devfdt_get_addr_pci(const struct udevice *dev) ulong addr; addr = devfdt_get_addr(dev); - if (CONFIG_IS_ENABLED(PCI) && IS_ENABLED(CONFIG_DM_PCI) && - addr == FDT_ADDR_T_NONE) { + if (CONFIG_IS_ENABLED(PCI) && addr == FDT_ADDR_T_NONE) { struct fdt_pci_addr pci_addr; u32 bar; int ret; diff --git a/drivers/dfu/dfu_mmc.c b/drivers/dfu/dfu_mmc.c index e63fa84ce4f..3dab5a5f633 100644 --- a/drivers/dfu/dfu_mmc.c +++ b/drivers/dfu/dfu_mmc.c @@ -348,7 +348,7 @@ int dfu_fill_entity_mmc(struct dfu_entity *dfu, char *devstr, char *s) const char *argv[3]; const char **parg = argv; - dfu->data.mmc.dev_num = simple_strtoul(devstr, NULL, 10); + dfu->data.mmc.dev_num = dectoul(devstr, NULL); for (; parg < argv + sizeof(argv) / sizeof(*argv); ++parg) { *parg = strsep(&s, " "); diff --git a/drivers/dfu/dfu_mtd.c b/drivers/dfu/dfu_mtd.c index 894b5708753..0b7f17761fd 100644 --- a/drivers/dfu/dfu_mtd.c +++ b/drivers/dfu/dfu_mtd.c @@ -268,9 +268,9 @@ int dfu_fill_entity_mtd(struct dfu_entity *dfu, char *devstr, char *s) st = strsep(&s, " "); if (!strcmp(st, "raw")) { dfu->layout = DFU_RAW_ADDR; - dfu->data.mtd.start = simple_strtoul(s, &s, 16); + dfu->data.mtd.start = hextoul(s, &s); s++; - dfu->data.mtd.size = simple_strtoul(s, &s, 16); + dfu->data.mtd.size = hextoul(s, &s); } else if ((!strcmp(st, "part")) || (!strcmp(st, "partubi"))) { char mtd_id[32]; struct mtd_device *mtd_dev; @@ -279,7 +279,7 @@ int dfu_fill_entity_mtd(struct dfu_entity *dfu, char *devstr, char *s) dfu->layout = DFU_RAW_ADDR; - part = simple_strtoul(s, &s, 10); + part = dectoul(s, &s); sprintf(mtd_id, "%s,%d", devstr, part - 1); printf("using id '%s'\n", mtd_id); diff --git a/drivers/dfu/dfu_nand.c b/drivers/dfu/dfu_nand.c index b8d24d203be..e53b35e42b8 100644 --- a/drivers/dfu/dfu_nand.c +++ b/drivers/dfu/dfu_nand.c @@ -204,9 +204,9 @@ int dfu_fill_entity_nand(struct dfu_entity *dfu, char *devstr, char *s) st = strsep(&s, " "); if (!strcmp(st, "raw")) { dfu->layout = DFU_RAW_ADDR; - dfu->data.nand.start = simple_strtoul(s, &s, 16); + dfu->data.nand.start = hextoul(s, &s); s++; - dfu->data.nand.size = simple_strtoul(s, &s, 16); + dfu->data.nand.size = hextoul(s, &s); } else if ((!strcmp(st, "part")) || (!strcmp(st, "partubi"))) { char mtd_id[32]; struct mtd_device *mtd_dev; @@ -215,9 +215,9 @@ int dfu_fill_entity_nand(struct dfu_entity *dfu, char *devstr, char *s) dfu->layout = DFU_RAW_ADDR; - dev = simple_strtoul(s, &s, 10); + dev = dectoul(s, &s); s++; - part = simple_strtoul(s, &s, 10); + part = dectoul(s, &s); sprintf(mtd_id, "%s%d,%d", "nand", dev, part - 1); debug("using id '%s'\n", mtd_id); diff --git a/drivers/dfu/dfu_ram.c b/drivers/dfu/dfu_ram.c index ab0ce9e6fa9..cc7e45ba335 100644 --- a/drivers/dfu/dfu_ram.c +++ b/drivers/dfu/dfu_ram.c @@ -74,8 +74,8 @@ int dfu_fill_entity_ram(struct dfu_entity *dfu, char *devstr, char *s) } dfu->layout = DFU_RAM_ADDR; - dfu->data.ram.start = simple_strtoul(argv[1], NULL, 16); - dfu->data.ram.size = simple_strtoul(argv[2], NULL, 16); + dfu->data.ram.start = hextoul(argv[1], NULL); + dfu->data.ram.size = hextoul(argv[2], NULL); dfu->write_medium = dfu_write_medium_ram; dfu->get_medium_size = dfu_get_medium_size_ram; diff --git a/drivers/dfu/dfu_sf.c b/drivers/dfu/dfu_sf.c index 8f8c4259772..7e64ab772f0 100644 --- a/drivers/dfu/dfu_sf.c +++ b/drivers/dfu/dfu_sf.c @@ -171,9 +171,9 @@ int dfu_fill_entity_sf(struct dfu_entity *dfu, char *devstr, char *s) st = strsep(&s, " "); if (!strcmp(st, "raw")) { dfu->layout = DFU_RAW_ADDR; - dfu->data.sf.start = simple_strtoul(s, &s, 16); + dfu->data.sf.start = hextoul(s, &s); s++; - dfu->data.sf.size = simple_strtoul(s, &s, 16); + dfu->data.sf.size = hextoul(s, &s); } else if (CONFIG_IS_ENABLED(DFU_SF_PART) && (!strcmp(st, "part") || !strcmp(st, "partubi"))) { char mtd_id[32]; @@ -184,9 +184,9 @@ int dfu_fill_entity_sf(struct dfu_entity *dfu, char *devstr, char *s) dfu->layout = DFU_RAW_ADDR; - dev = simple_strtoul(s, &s, 10); + dev = dectoul(s, &s); s++; - part = simple_strtoul(s, &s, 10); + part = dectoul(s, &s); sprintf(mtd_id, "%s%d,%d", "nor", dev, part - 1); printf("using id '%s'\n", mtd_id); diff --git a/drivers/dfu/dfu_virt.c b/drivers/dfu/dfu_virt.c index 62605bcde50..80c99cb06e3 100644 --- a/drivers/dfu/dfu_virt.c +++ b/drivers/dfu/dfu_virt.c @@ -38,7 +38,7 @@ int dfu_fill_entity_virt(struct dfu_entity *dfu, char *devstr, char *s) dfu->dev_type = DFU_DEV_VIRT; dfu->layout = DFU_RAW_ADDR; - dfu->data.virt.dev_num = simple_strtoul(devstr, NULL, 10); + dfu->data.virt.dev_num = dectoul(devstr, NULL); dfu->write_medium = dfu_write_medium_virt; dfu->get_medium_size = dfu_get_medium_size_virt; diff --git a/drivers/fastboot/fb_command.c b/drivers/fastboot/fb_command.c index 3a5db5b08fc..98eccc34556 100644 --- a/drivers/fastboot/fb_command.c +++ b/drivers/fastboot/fb_command.c @@ -208,7 +208,7 @@ static void download(char *cmd_parameter, char *response) return; } fastboot_bytes_received = 0; - fastboot_bytes_expected = simple_strtoul(cmd_parameter, &tmp, 16); + fastboot_bytes_expected = hextoul(cmd_parameter, &tmp); if (fastboot_bytes_expected == 0) { fastboot_fail("Expected nonzero image size", response); return; diff --git a/drivers/gpio/gpio-uclass.c b/drivers/gpio/gpio-uclass.c index 131099cc176..8c77777dbe3 100644 --- a/drivers/gpio/gpio-uclass.c +++ b/drivers/gpio/gpio-uclass.c @@ -122,7 +122,7 @@ int dm_gpio_lookup_name(const char *name, struct gpio_desc *desc) int numeric; int ret; - numeric = isdigit(*name) ? simple_strtoul(name, NULL, 10) : -1; + numeric = isdigit(*name) ? dectoul(name, NULL) : -1; for (ret = uclass_first_device(UCLASS_GPIO, &dev); dev; ret = uclass_next_device(&dev)) { diff --git a/drivers/gpio/mxs_gpio.c b/drivers/gpio/mxs_gpio.c index 5775a22abd4..7b9d88a8a75 100644 --- a/drivers/gpio/mxs_gpio.c +++ b/drivers/gpio/mxs_gpio.c @@ -123,12 +123,12 @@ int name_to_gpio(const char *name) unsigned bank, pin; char *end; - bank = simple_strtoul(name, &end, 10); + bank = dectoul(name, &end); if (!*end || *end != ':') return bank; - pin = simple_strtoul(end + 1, NULL, 10); + pin = dectoul(end + 1, NULL); return (bank << MXS_PAD_BANK_SHIFT) | (pin << MXS_PAD_PIN_SHIFT); } diff --git a/drivers/gpio/pca953x.c b/drivers/gpio/pca953x.c index 4ab8cee2d18..2fd2996798c 100644 --- a/drivers/gpio/pca953x.c +++ b/drivers/gpio/pca953x.c @@ -221,11 +221,11 @@ static int do_pca953x(struct cmd_tbl *cmdtp, int flag, int argc, /* arg2 used as chip number or pin number */ if (argc > 2) - ul_arg2 = simple_strtoul(argv[2], NULL, 16); + ul_arg2 = hextoul(argv[2], NULL); /* arg3 used as pin or invert value */ if (argc > 3) - ul_arg3 = simple_strtoul(argv[3], NULL, 16) & 0x1; + ul_arg3 = hextoul(argv[3], NULL) & 0x1; switch ((long)c->cmd) { case PCA953X_CMD_INFO: diff --git a/drivers/gpio/tca642x.c b/drivers/gpio/tca642x.c index 7007c7a0027..7f67f96b0ec 100644 --- a/drivers/gpio/tca642x.c +++ b/drivers/gpio/tca642x.c @@ -262,11 +262,11 @@ static int do_tca642x(struct cmd_tbl *cmdtp, int flag, int argc, /* arg2 used as chip number or pin number */ if (argc > 2) - ul_arg2 = simple_strtoul(argv[2], NULL, 10); + ul_arg2 = dectoul(argv[2], NULL); /* arg3 used as pin or invert value */ if (argc > 3) - ul_arg3 = simple_strtoul(argv[3], NULL, 10) & 0x1; + ul_arg3 = dectoul(argv[3], NULL) & 0x1; switch ((int)c->cmd) { case TCA642X_CMD_INFO: diff --git a/drivers/misc/ds4510.c b/drivers/misc/ds4510.c index a2a52915654..9340596f2c6 100644 --- a/drivers/misc/ds4510.c +++ b/drivers/misc/ds4510.c @@ -271,11 +271,11 @@ int do_ds4510(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) /* arg2 used as chip addr and pin number */ if (argc > 2) - ul_arg2 = simple_strtoul(argv[2], NULL, 16); + ul_arg2 = hextoul(argv[2], NULL); /* arg3 used as output/pullup value */ if (argc > 3) - ul_arg3 = simple_strtoul(argv[3], NULL, 16); + ul_arg3 = hextoul(argv[3], NULL); switch ((int)c->cmd) { case DS4510_CMD_DEVICE: @@ -337,9 +337,9 @@ int do_ds4510(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) else return cmd_usage(cmdtp); - addr = simple_strtoul(argv[3], NULL, 16); - off += simple_strtoul(argv[4], NULL, 16); - cnt = simple_strtoul(argv[5], NULL, 16); + addr = hextoul(argv[3], NULL); + off += hextoul(argv[4], NULL); + cnt = hextoul(argv[5], NULL); if ((off + cnt) > end) { printf("ERROR: invalid len\n"); diff --git a/drivers/mmc/arm_pl180_mmci.c b/drivers/mmc/arm_pl180_mmci.c index b2d1b4f9aa9..f99b5f997e2 100644 --- a/drivers/mmc/arm_pl180_mmci.c +++ b/drivers/mmc/arm_pl180_mmci.c @@ -424,7 +424,6 @@ static int arm_pl180_mmc_probe(struct udevice *dev) struct pl180_mmc_host *host = dev_get_priv(dev); struct mmc_config *cfg = &pdata->cfg; struct clk clk; - u32 bus_width; u32 periphid; int ret; @@ -444,37 +443,35 @@ static int arm_pl180_mmc_probe(struct udevice *dev) SDI_CLKCR_HWFC_EN; host->clock_in = clk_get_rate(&clk); + cfg->name = dev->name; + cfg->voltages = VOLTAGE_WINDOW_SD; + cfg->host_caps = 0; + cfg->f_min = host->clock_in / (2 * (SDI_CLKCR_CLKDIV_INIT_V1 + 1)); + cfg->f_max = MMC_CLOCK_MAX; + cfg->b_max = CONFIG_SYS_MMC_MAX_BLK_COUNT; + periphid = dev_read_u32_default(dev, "arm,primecell-periphid", 0); switch (periphid) { case STM32_MMCI_ID: /* stm32 variant */ host->version2 = false; break; + case UX500V2_MMCI_ID: + host->pwr_init = SDI_PWR_OPD | SDI_PWR_PWRCTRL_ON; + host->clkdiv_init = SDI_CLKCR_CLKDIV_INIT_V2 | SDI_CLKCR_CLKEN | + SDI_CLKCR_HWFC_EN; + cfg->voltages = VOLTAGE_WINDOW_MMC; + cfg->f_min = host->clock_in / (2 + SDI_CLKCR_CLKDIV_INIT_V2); + host->version2 = true; + break; default: host->version2 = true; } - cfg->name = dev->name; - cfg->voltages = VOLTAGE_WINDOW_SD; - cfg->host_caps = 0; - cfg->f_min = host->clock_in / (2 * (SDI_CLKCR_CLKDIV_INIT_V1 + 1)); - cfg->f_max = dev_read_u32_default(dev, "max-frequency", MMC_CLOCK_MAX); - cfg->b_max = CONFIG_SYS_MMC_MAX_BLK_COUNT; - gpio_request_by_name(dev, "cd-gpios", 0, &host->cd_gpio, GPIOD_IS_IN); - bus_width = dev_read_u32_default(dev, "bus-width", 1); - switch (bus_width) { - case 8: - cfg->host_caps |= MMC_MODE_8BIT; - /* Hosts capable of 8-bit transfers can also do 4 bits */ - case 4: - cfg->host_caps |= MMC_MODE_4BIT; - break; - case 1: - break; - default: - dev_err(dev, "Invalid bus-width value %u\n", bus_width); - } + ret = mmc_of_parse(dev, cfg); + if (ret) + return ret; arm_pl180_mmc_init(host); mmc->priv = host; @@ -526,20 +523,17 @@ static const struct dm_mmc_ops arm_pl180_dm_mmc_ops = { static int arm_pl180_mmc_of_to_plat(struct udevice *dev) { struct pl180_mmc_host *host = dev_get_priv(dev); - fdt_addr_t addr; - addr = dev_read_addr(dev); - if (addr == FDT_ADDR_T_NONE) + host->base = dev_read_addr_ptr(dev); + if (!host->base) return -EINVAL; - host->base = (void *)addr; - return 0; } static const struct udevice_id arm_pl180_mmc_match[] = { { .compatible = "arm,pl180" }, - { .compatible = "arm,primecell" }, + { .compatible = "arm,pl18x" }, { /* sentinel */ } }; diff --git a/drivers/mmc/arm_pl180_mmci.h b/drivers/mmc/arm_pl180_mmci.h index 61ee96a112d..15c29beadbc 100644 --- a/drivers/mmc/arm_pl180_mmci.h +++ b/drivers/mmc/arm_pl180_mmci.h @@ -142,6 +142,7 @@ #define SDI_FIFO_BURST_SIZE 8 #define STM32_MMCI_ID 0x00880180 +#define UX500V2_MMCI_ID 0x10480180 struct sdi_registers { u32 power; /* 0x00*/ diff --git a/drivers/mmc/rpmb.c b/drivers/mmc/rpmb.c index ea7e506666b..b68d98573c9 100644 --- a/drivers/mmc/rpmb.c +++ b/drivers/mmc/rpmb.c @@ -480,10 +480,24 @@ int mmc_rpmb_route_frames(struct mmc *mmc, void *req, unsigned long reqlen, * and possibly just delay an eventual error which will be harder * to track down. */ + void *rpmb_data = NULL; + int ret; if (reqlen % sizeof(struct s_rpmb) || rsplen % sizeof(struct s_rpmb)) return -EINVAL; - return rpmb_route_frames(mmc, req, reqlen / sizeof(struct s_rpmb), - rsp, rsplen / sizeof(struct s_rpmb)); + if (!IS_ALIGNED((uintptr_t)req, ARCH_DMA_MINALIGN)) { + /* Memory alignment is required by MMC driver */ + rpmb_data = malloc(reqlen); + if (!rpmb_data) + return -ENOMEM; + + memcpy(rpmb_data, req, reqlen); + req = rpmb_data; + } + + ret = rpmb_route_frames(mmc, req, reqlen / sizeof(struct s_rpmb), + rsp, rsplen / sizeof(struct s_rpmb)); + free(rpmb_data); + return ret; } diff --git a/drivers/mtd/spi/spi-nor-core.c b/drivers/mtd/spi/spi-nor-core.c index 99e2f16349a..d5d905fa5a1 100644 --- a/drivers/mtd/spi/spi-nor-core.c +++ b/drivers/mtd/spi/spi-nor-core.c @@ -2604,18 +2604,28 @@ static int spi_nor_init_params(struct spi_nor *nor, params->size = info->sector_size * info->n_sectors; params->page_size = info->page_size; + if (!(info->flags & SPI_NOR_NO_FR)) { + /* Default to Fast Read for DT and non-DT platform devices. */ + params->hwcaps.mask |= SNOR_HWCAPS_READ_FAST; + + /* Mask out Fast Read if not requested at DT instantiation. */ +#if CONFIG_IS_ENABLED(DM_SPI) + if (!ofnode_read_bool(dev_ofnode(nor->spi->dev), + "m25p,fast-read")) + params->hwcaps.mask &= ~SNOR_HWCAPS_READ_FAST; +#endif + } + /* (Fast) Read settings. */ params->hwcaps.mask |= SNOR_HWCAPS_READ; spi_nor_set_read_settings(¶ms->reads[SNOR_CMD_READ], 0, 0, SPINOR_OP_READ, SNOR_PROTO_1_1_1); - if (!(info->flags & SPI_NOR_NO_FR)) { - params->hwcaps.mask |= SNOR_HWCAPS_READ_FAST; + if (params->hwcaps.mask & SNOR_HWCAPS_READ_FAST) spi_nor_set_read_settings(¶ms->reads[SNOR_CMD_READ_FAST], 0, 8, SPINOR_OP_READ_FAST, SNOR_PROTO_1_1_1); - } if (info->flags & SPI_NOR_DUAL_READ) { params->hwcaps.mask |= SNOR_HWCAPS_READ_1_1_2; @@ -2858,10 +2868,11 @@ spi_nor_adjust_hwcaps(struct spi_nor *nor, unsigned int cap; /* - * Enable all caps by default. We will mask them after checking what's - * really supported using spi_mem_supports_op(). + * Start by assuming the controller supports every capability. + * We will mask them after checking what's really supported + * using spi_mem_supports_op(). */ - *hwcaps = SNOR_HWCAPS_ALL; + *hwcaps = SNOR_HWCAPS_ALL & params->hwcaps.mask; /* X-X-X modes are not supported yet, mask them all. */ *hwcaps &= ~SNOR_HWCAPS_X_X_X; diff --git a/drivers/mtd/spi/spi-nor-ids.c b/drivers/mtd/spi/spi-nor-ids.c index 6f84c54a474..cb3a08872d6 100644 --- a/drivers/mtd/spi/spi-nor-ids.c +++ b/drivers/mtd/spi/spi-nor-ids.c @@ -359,6 +359,7 @@ const struct flash_info spi_nor_ids[] = { #ifdef CONFIG_SPI_FLASH_XMC /* XMC (Wuhan Xinxin Semiconductor Manufacturing Corp.) */ { INFO("XM25QH64A", 0x207017, 0, 64 * 1024, 128, SECT_4K | SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ) }, + { INFO("XM25QH64C", 0x204017, 0, 64 * 1024, 128, SECT_4K | SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ) }, { INFO("XM25QH128A", 0x207018, 0, 64 * 1024, 256, SECT_4K | SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ) }, #endif { }, diff --git a/drivers/net/e1000.c b/drivers/net/e1000.c index 60613b7df07..5bdcede8f14 100644 --- a/drivers/net/e1000.c +++ b/drivers/net/e1000.c @@ -5796,7 +5796,7 @@ static int do_e1000(struct cmd_tbl *cmdtp, int flag, int argc, } /* Make sure we can find the requested e1000 card */ - cardnum = simple_strtoul(argv[1], NULL, 10); + cardnum = dectoul(argv[1], NULL); #ifdef CONFIG_DM_ETH e1000_name(name, cardnum); ret = uclass_get_device_by_name(UCLASS_ETH, name, &dev); diff --git a/drivers/net/e1000_spi.c b/drivers/net/e1000_spi.c index 4fcc65d9782..69adf282c73 100644 --- a/drivers/net/e1000_spi.c +++ b/drivers/net/e1000_spi.c @@ -399,7 +399,7 @@ static int do_e1000_spi_dump(struct cmd_tbl *cmdtp, struct e1000_hw *hw, } /* Parse the arguments */ - dest = (void *)simple_strtoul(argv[0], NULL, 16); + dest = (void *)hextoul(argv[0], NULL); offset = simple_strtoul(argv[1], NULL, 0); length = simple_strtoul(argv[2], NULL, 0); @@ -444,7 +444,7 @@ static int do_e1000_spi_program(struct cmd_tbl *cmdtp, struct e1000_hw *hw, } /* Parse the arguments */ - source = (const void *)simple_strtoul(argv[0], NULL, 16); + source = (const void *)hextoul(argv[0], NULL); offset = simple_strtoul(argv[1], NULL, 0); length = simple_strtoul(argv[2], NULL, 0); diff --git a/drivers/net/fm/fdt.c b/drivers/net/fm/fdt.c index 242d27a34ea..3855d7d58fa 100644 --- a/drivers/net/fm/fdt.c +++ b/drivers/net/fm/fdt.c @@ -42,7 +42,7 @@ void fdt_fixup_fman_firmware(void *blob) if (!p) return; - fmanfw = (struct qe_firmware *)simple_strtoul(p, NULL, 16); + fmanfw = (struct qe_firmware *)hextoul(p, NULL); if (!fmanfw) return; diff --git a/drivers/net/fsl-mc/mc.c b/drivers/net/fsl-mc/mc.c index 914ec001ec6..d52c986d4bd 100644 --- a/drivers/net/fsl-mc/mc.c +++ b/drivers/net/fsl-mc/mc.c @@ -642,7 +642,7 @@ static unsigned long get_mc_boot_timeout_ms(void) char *timeout_ms_env_var = env_get(MC_BOOT_TIMEOUT_ENV_VAR); if (timeout_ms_env_var) { - timeout_ms = simple_strtoul(timeout_ms_env_var, NULL, 10); + timeout_ms = dectoul(timeout_ms_env_var, NULL); if (timeout_ms == 0) { printf("fsl-mc: WARNING: Invalid value for \'" MC_BOOT_TIMEOUT_ENV_VAR @@ -956,8 +956,7 @@ unsigned long mc_get_dram_block_size(void) char *dram_block_size_env_var = env_get(MC_MEM_SIZE_ENV_VAR); if (dram_block_size_env_var) { - dram_block_size = simple_strtoul(dram_block_size_env_var, NULL, - 16); + dram_block_size = hextoul(dram_block_size_env_var, NULL); if (dram_block_size < CONFIG_SYS_LS_MC_DRAM_BLOCK_MIN_SIZE) { printf("fsl-mc: WARNING: Invalid value for \'" diff --git a/drivers/net/netconsole.c b/drivers/net/netconsole.c index f1d0630d020..cec96c57150 100644 --- a/drivers/net/netconsole.c +++ b/drivers/net/netconsole.c @@ -87,7 +87,7 @@ static int refresh_settings_from_env(void) return -1; /* ncip is 0.0.0.0 */ p = strchr(env_get("ncip"), ':'); if (p != NULL) { - nc_out_port = simple_strtoul(p + 1, NULL, 10); + nc_out_port = dectoul(p + 1, NULL); nc_in_port = nc_out_port; } } else { @@ -96,10 +96,10 @@ static int refresh_settings_from_env(void) p = env_get("ncoutport"); if (p != NULL) - nc_out_port = simple_strtoul(p, NULL, 10); + nc_out_port = dectoul(p, NULL); p = env_get("ncinport"); if (p != NULL) - nc_in_port = simple_strtoul(p, NULL, 10); + nc_in_port = dectoul(p, NULL); if (is_broadcast(nc_ip)) /* broadcast MAC address */ diff --git a/drivers/net/pfe_eth/pfe_cmd.c b/drivers/net/pfe_eth/pfe_cmd.c index 364750f65c7..2fe0db0fe71 100644 --- a/drivers/net/pfe_eth/pfe_cmd.c +++ b/drivers/net/pfe_eth/pfe_cmd.c @@ -41,7 +41,7 @@ static void pfe_command_pe(int argc, char *const argv[]) } id = simple_strtoul(argv[4], NULL, 0); - addr = simple_strtoul(argv[5], NULL, 16); + addr = hextoul(argv[5], NULL); size = 4; for (i = 0; i < num; i++, addr += 4) { @@ -75,7 +75,7 @@ static void pfe_command_pe(int argc, char *const argv[]) } id = simple_strtoul(argv[4], NULL, 0); - addr = simple_strtoul(argv[5], NULL, 16); + addr = hextoul(argv[5], NULL); size = 4; for (i = 0; i < num; i++, addr += 4) { @@ -99,9 +99,9 @@ static void pfe_command_pe(int argc, char *const argv[]) } id = simple_strtoul(argv[4], NULL, 0); - val = simple_strtoul(argv[5], NULL, 16); + val = hextoul(argv[5], NULL); val = cpu_to_be32(val); - addr = simple_strtoul(argv[6], NULL, 16); + addr = hextoul(argv[6], NULL); size = 4; pe_dmem_write(id, val, addr, size); } else { @@ -123,7 +123,7 @@ static void pfe_command_pe(int argc, char *const argv[]) return; } - offset = simple_strtoul(argv[4], NULL, 16); + offset = hextoul(argv[4], NULL); for (i = 0; i < num; i++, offset += 4) { pe_lmem_read(&val, 4, offset); @@ -141,9 +141,9 @@ static void pfe_command_pe(int argc, char *const argv[]) return; } - val = simple_strtoul(argv[4], NULL, 16); + val = hextoul(argv[4], NULL); val = cpu_to_be32(val); - offset = simple_strtoul(argv[5], NULL, 16); + offset = hextoul(argv[5], NULL); pe_lmem_write(&val, 4, offset); } else { printf("Usage: pfe pe lmem [read | write] <parameters>\n"); diff --git a/drivers/net/pfe_eth/pfe_firmware.c b/drivers/net/pfe_eth/pfe_firmware.c index ac86e33c550..ad5bc3c8624 100644 --- a/drivers/net/pfe_eth/pfe_firmware.c +++ b/drivers/net/pfe_eth/pfe_firmware.c @@ -298,7 +298,7 @@ int pfe_firmware_init(void) if (!p) { max_fw_count = 2; } else { - max_fw_count = simple_strtoul(p, NULL, 10); + max_fw_count = dectoul(p, NULL); if (max_fw_count) max_fw_count = 3; else diff --git a/drivers/net/phy/b53.c b/drivers/net/phy/b53.c index 21da53c7e5b..c706e2b9bde 100644 --- a/drivers/net/phy/b53.c +++ b/drivers/net/phy/b53.c @@ -646,9 +646,9 @@ int do_b53_reg_read(const char *name, int argc, char *const argv[]) return ret; } - page = simple_strtoul(argv[1], NULL, 16); - offset = simple_strtoul(argv[2], NULL, 16); - width = simple_strtoul(argv[3], NULL, 10); + page = hextoul(argv[1], NULL); + offset = hextoul(argv[2], NULL); + width = dectoul(argv[3], NULL); switch (width) { case 8: @@ -698,13 +698,13 @@ int do_b53_reg_write(const char *name, int argc, char *const argv[]) return ret; } - page = simple_strtoul(argv[1], NULL, 16); - offset = simple_strtoul(argv[2], NULL, 16); - width = simple_strtoul(argv[3], NULL, 10); + page = hextoul(argv[1], NULL); + offset = hextoul(argv[2], NULL); + width = dectoul(argv[3], NULL); if (width == 48 || width == 64) value64 = simple_strtoull(argv[4], NULL, 16); else - value = simple_strtoul(argv[4], NULL, 16); + value = hextoul(argv[4], NULL); switch (width) { case 8: diff --git a/drivers/net/phy/mv88e6352.c b/drivers/net/phy/mv88e6352.c index 62a7f192149..56060762d85 100644 --- a/drivers/net/phy/mv88e6352.c +++ b/drivers/net/phy/mv88e6352.c @@ -238,9 +238,9 @@ int do_mvsw_reg_read(const char *name, int argc, char *const argv[]) u16 value = 0, phyaddr, reg, port; int ret; - phyaddr = simple_strtoul(argv[1], NULL, 10); - port = simple_strtoul(argv[2], NULL, 10); - reg = simple_strtoul(argv[3], NULL, 10); + phyaddr = dectoul(argv[1], NULL); + port = dectoul(argv[2], NULL); + reg = dectoul(argv[3], NULL); ret = sw_reg_read(name, phyaddr, port, reg, &value); printf("%#x\n", value); @@ -253,10 +253,10 @@ int do_mvsw_reg_write(const char *name, int argc, char *const argv[]) u16 value = 0, phyaddr, reg, port; int ret; - phyaddr = simple_strtoul(argv[1], NULL, 10); - port = simple_strtoul(argv[2], NULL, 10); - reg = simple_strtoul(argv[3], NULL, 10); - value = simple_strtoul(argv[4], NULL, 16); + phyaddr = dectoul(argv[1], NULL); + port = dectoul(argv[2], NULL); + reg = dectoul(argv[3], NULL); + value = hextoul(argv[4], NULL); ret = sw_reg_write(name, phyaddr, port, reg, value); diff --git a/drivers/net/qe/dm_qe_uec.c b/drivers/net/qe/dm_qe_uec.c index eb0501bc5a8..a12c8cd2ac5 100644 --- a/drivers/net/qe/dm_qe_uec.c +++ b/drivers/net/qe/dm_qe_uec.c @@ -938,7 +938,7 @@ enum qe_clock qe_clock_source(const char *source) return QE_CLK_NONE; if (strncasecmp(source, "brg", 3) == 0) { - i = simple_strtoul(source + 3, NULL, 10); + i = dectoul(source + 3, NULL); if (i >= 1 && i <= 16) return (QE_BRG1 - 1) + i; else @@ -946,7 +946,7 @@ enum qe_clock qe_clock_source(const char *source) } if (strncasecmp(source, "clk", 3) == 0) { - i = simple_strtoul(source + 3, NULL, 10); + i = dectoul(source + 3, NULL); if (i >= 1 && i <= 24) return (QE_CLK1 - 1) + i; else diff --git a/drivers/pci/Makefile b/drivers/pci/Makefile index 83d7a4e403c..bdfdec98a08 100644 --- a/drivers/pci/Makefile +++ b/drivers/pci/Makefile @@ -19,7 +19,6 @@ obj-$(CONFIG_PCI_GT64120) += pci_gt64120.o obj-$(CONFIG_PCI_MPC85XX) += pci_mpc85xx.o obj-$(CONFIG_PCI_MSC01) += pci_msc01.o obj-$(CONFIG_PCIE_IMX) += pcie_imx.o -obj-$(CONFIG_FTPCI100) += pci_ftpci100.o obj-$(CONFIG_PCI_MVEBU) += pci_mvebu.o obj-$(CONFIG_PCI_RCAR_GEN2) += pci-rcar-gen2.o obj-$(CONFIG_PCI_RCAR_GEN3) += pci-rcar-gen3.o diff --git a/drivers/pci/pci_common.c b/drivers/pci/pci_common.c index 5231b69dc9a..02a71da30fa 100644 --- a/drivers/pci/pci_common.c +++ b/drivers/pci/pci_common.c @@ -99,7 +99,7 @@ __weak int pci_skip_dev(struct pci_controller *hose, pci_dev_t dev) return 0; } -#if !defined(CONFIG_DM_PCI) || defined(CONFIG_DM_PCI_COMPAT) +#if defined(CONFIG_DM_PCI_COMPAT) /* Get a virtual address associated with a BAR region */ void *pci_map_bar(pci_dev_t pdev, int bar, int flags) { @@ -361,4 +361,4 @@ pci_dev_t pci_find_class(uint find_class, int index) return -ENODEV; } -#endif /* !CONFIG_DM_PCI || CONFIG_DM_PCI_COMPAT */ +#endif /* CONFIG_DM_PCI_COMPAT */ diff --git a/drivers/pci/pci_ftpci100.c b/drivers/pci/pci_ftpci100.c deleted file mode 100644 index 32fac878a67..00000000000 --- a/drivers/pci/pci_ftpci100.c +++ /dev/null @@ -1,319 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0+ -/* - * Faraday FTPCI100 PCI Bridge Controller Device Driver Implementation - * - * Copyright (C) 2011 Andes Technology Corporation - * Gavin Guo, Andes Technology Corporation <gavinguo@andestech.com> - * Macpaul Lin, Andes Technology Corporation <macpaul@andestech.com> - */ -#include <common.h> -#include <init.h> -#include <log.h> -#include <malloc.h> -#include <pci.h> - -#include <faraday/ftpci100.h> - -#include <asm/io.h> -#include <asm/types.h> /* u32, u16.... used by pci.h */ - -struct ftpci100_data { - unsigned int reg_base; - unsigned int io_base; - unsigned int mem_base; - unsigned int mmio_base; - unsigned int ndevs; -}; - -static struct pci_config devs[FTPCI100_MAX_FUNCTIONS]; -static struct pci_controller local_hose; - -static void setup_pci_bar(unsigned int bus, unsigned int dev, unsigned func, - unsigned char header, struct ftpci100_data *priv) -{ - struct pci_controller *hose = (struct pci_controller *)&local_hose; - unsigned int i, tmp32, bar_no, iovsmem = 1; - pci_dev_t dev_nu; - - /* A device is present, add an entry to the array */ - devs[priv->ndevs].bus = bus; - devs[priv->ndevs].dev = dev; - devs[priv->ndevs].func = func; - - dev_nu = PCI_BDF(bus, dev, func); - - if ((header & 0x7f) == 0x01) - /* PCI-PCI Bridge */ - bar_no = 2; - else - bar_no = 6; - - /* Allocate address spaces by configuring BARs */ - for (i = 0; i < bar_no; i++) { - pci_hose_write_config_dword(hose, dev_nu, - PCI_BASE_ADDRESS_0 + i * 4, 0xffffffff); - pci_hose_read_config_dword(hose, dev_nu, - PCI_BASE_ADDRESS_0 + i * 4, &tmp32); - - if (tmp32 == 0x0) - continue; - - /* IO space */ - if (tmp32 & 0x1) { - iovsmem = 0; - unsigned int size_mask = ~(tmp32 & 0xfffffffc); - - if (priv->io_base & size_mask) - priv->io_base = (priv->io_base & ~size_mask) + \ - size_mask + 1; - - devs[priv->ndevs].bar[i].addr = priv->io_base; - devs[priv->ndevs].bar[i].size = size_mask + 1; - - pci_hose_write_config_dword(hose, dev_nu, - PCI_BASE_ADDRESS_0 + i * 4, - priv->io_base); - - debug("Allocated IO address 0x%X-" \ - "0x%X for Bus %d, Device %d, Function %d\n", - priv->io_base, - priv->io_base + size_mask, bus, dev, func); - - priv->io_base += size_mask + 1; - } else { - /* Memory space */ - unsigned int is_64bit = ((tmp32 & 0x6) == 0x4); - unsigned int is_pref = tmp32 & 0x8; - unsigned int size_mask = ~(tmp32 & 0xfffffff0); - unsigned int alloc_base; - unsigned int *addr_mem_base; - - if (is_pref) - addr_mem_base = &priv->mem_base; - else - addr_mem_base = &priv->mmio_base; - - alloc_base = *addr_mem_base; - - if (alloc_base & size_mask) - alloc_base = (alloc_base & ~size_mask) \ - + size_mask + 1; - - pci_hose_write_config_dword(hose, dev_nu, - PCI_BASE_ADDRESS_0 + i * 4, alloc_base); - - debug("Allocated %s address 0x%X-" \ - "0x%X for Bus %d, Device %d, Function %d\n", - is_pref ? "MEM" : "MMIO", alloc_base, - alloc_base + size_mask, bus, dev, func); - - devs[priv->ndevs].bar[i].addr = alloc_base; - devs[priv->ndevs].bar[i].size = size_mask + 1; - - debug("BAR address BAR size\n"); - debug("%010x %08d\n", - devs[priv->ndevs].bar[0].addr, - devs[priv->ndevs].bar[0].size); - - alloc_base += size_mask + 1; - *addr_mem_base = alloc_base; - - if (is_64bit) { - i++; - pci_hose_write_config_dword(hose, dev_nu, - PCI_BASE_ADDRESS_0 + i * 4, 0x0); - } - } - } - - /* Enable Bus Master, Memory Space, and IO Space */ - pci_hose_read_config_dword(hose, dev_nu, PCI_CACHE_LINE_SIZE, &tmp32); - pci_hose_write_config_dword(hose, dev_nu, PCI_CACHE_LINE_SIZE, 0x08); - pci_hose_read_config_dword(hose, dev_nu, PCI_CACHE_LINE_SIZE, &tmp32); - - pci_hose_read_config_dword(hose, dev_nu, PCI_COMMAND, &tmp32); - - tmp32 &= 0xffff; - - if (iovsmem == 0) - tmp32 |= 0x5; - else - tmp32 |= 0x6; - - pci_hose_write_config_dword(hose, dev_nu, PCI_COMMAND, tmp32); -} - -static void pci_bus_scan(struct ftpci100_data *priv) -{ - struct pci_controller *hose = (struct pci_controller *)&local_hose; - unsigned int bus, dev, func; - pci_dev_t dev_nu; - unsigned int data32; - unsigned int tmp; - unsigned char header; - unsigned char int_pin; - unsigned int niobars; - unsigned int nmbars; - - priv->ndevs = 1; - - nmbars = 0; - niobars = 0; - - for (bus = 0; bus < MAX_BUS_NUM; bus++) - for (dev = 0; dev < MAX_DEV_NUM; dev++) - for (func = 0; func < MAX_FUN_NUM; func++) { - dev_nu = PCI_BDF(bus, dev, func); - pci_hose_read_config_dword(hose, dev_nu, - PCI_VENDOR_ID, &data32); - - /* - * some broken boards return 0 or ~0, - * if a slot is empty. - */ - if (data32 == 0xffffffff || - data32 == 0x00000000 || - data32 == 0x0000ffff || - data32 == 0xffff0000) - continue; - - pci_hose_read_config_dword(hose, dev_nu, - PCI_HEADER_TYPE, &tmp); - header = (unsigned char)tmp; - setup_pci_bar(bus, dev, func, header, priv); - - devs[priv->ndevs].v_id = (u16)(data32 & \ - 0x0000ffff); - - devs[priv->ndevs].d_id = (u16)((data32 & \ - 0xffff0000) >> 16); - - /* Figure out what INTX# line the card uses */ - pci_hose_read_config_byte(hose, dev_nu, - PCI_INTERRUPT_PIN, &int_pin); - - /* assign the appropriate irq line */ - if (int_pin > PCI_IRQ_LINES) { - printf("more irq lines than expect\n"); - } else if (int_pin != 0) { - /* This device uses an interrupt line */ - devs[priv->ndevs].pin = int_pin; - } - - pci_hose_read_config_dword(hose, dev_nu, - PCI_CLASS_DEVICE, &data32); - - debug("%06d %03d %03d " \ - "%04d %08x %08x " \ - "%03d %08x %06d %08x\n", - priv->ndevs, devs[priv->ndevs].bus, - devs[priv->ndevs].dev, - devs[priv->ndevs].func, - devs[priv->ndevs].d_id, - devs[priv->ndevs].v_id, - devs[priv->ndevs].pin, - devs[priv->ndevs].bar[0].addr, - devs[priv->ndevs].bar[0].size, - data32 >> 8); - - priv->ndevs++; - } -} - -static void ftpci_preinit(struct ftpci100_data *priv) -{ - struct ftpci100_ahbc *ftpci100; - struct pci_controller *hose = (struct pci_controller *)&local_hose; - u32 pci_config_addr; - u32 pci_config_data; - - priv->reg_base = CONFIG_FTPCI100_BASE; - priv->io_base = CONFIG_FTPCI100_BASE + CONFIG_FTPCI100_IO_SIZE; - priv->mmio_base = CONFIG_FTPCI100_MEM_BASE; - priv->mem_base = CONFIG_FTPCI100_MEM_BASE + CONFIG_FTPCI100_MEM_SIZE; - - ftpci100 = (struct ftpci100_ahbc *)priv->reg_base; - - pci_config_addr = (u32) &ftpci100->conf; - pci_config_data = (u32) &ftpci100->data; - - /* print device name */ - printf("FTPCI100\n"); - - /* dump basic configuration */ - debug("%s: Config addr is %08X, data port is %08X\n", - __func__, pci_config_addr, pci_config_data); - - /* PCI memory space */ - pci_set_region(hose->regions + 0, - CONFIG_PCI_MEM_BUS, - CONFIG_PCI_MEM_PHYS, - CONFIG_PCI_MEM_SIZE, - PCI_REGION_MEM); - hose->region_count++; - - /* PCI IO space */ - pci_set_region(hose->regions + 1, - CONFIG_PCI_IO_BUS, - CONFIG_PCI_IO_PHYS, - CONFIG_PCI_IO_SIZE, - PCI_REGION_IO); - hose->region_count++; - -#if defined(CONFIG_PCI_SYS_BUS) - /* PCI System Memory space */ - pci_set_region(hose->regions + 2, - CONFIG_PCI_SYS_BUS, - CONFIG_PCI_SYS_PHYS, - CONFIG_PCI_SYS_SIZE, - PCI_REGION_MEM | PCI_REGION_SYS_MEMORY); - hose->region_count++; -#endif - - /* setup indirect read/write function */ - pci_setup_indirect(hose, pci_config_addr, pci_config_data); - - /* register hose */ - pci_register_hose(hose); -} - -void pci_ftpci_init(void) -{ - struct ftpci100_data *priv = NULL; - struct pci_controller *hose = (struct pci_controller *)&local_hose; - pci_dev_t bridge_num; - - struct pci_device_id bridge_ids[] = { - {FTPCI100_BRIDGE_VENDORID, FTPCI100_BRIDGE_DEVICEID}, - {0, 0} - }; - - priv = malloc(sizeof(struct ftpci100_data)); - - if (!priv) { - printf("%s(): failed to malloc priv\n", __func__); - return; - } - - memset(priv, 0, sizeof(struct ftpci100_data)); - - ftpci_preinit(priv); - - debug("Device bus dev func deviceID vendorID pin address" \ - " size class\n"); - - pci_bus_scan(priv); - - /* - * Setup the PCI Bridge Window to 1GB, - * it will cause USB OHCI Host controller Unrecoverable Error - * if it is not set. - */ - bridge_num = pci_find_devices(bridge_ids, 0); - if (bridge_num == -1) { - printf("PCI Bridge not found\n"); - return; - } - pci_hose_write_config_dword(hose, bridge_num, PCI_MEM_BASE_SIZE1, - FTPCI100_BASE_ADR_SIZE(1024)); -} diff --git a/drivers/pci/pci_gt64120.c b/drivers/pci/pci_gt64120.c index e57fedf036e..153c65b119a 100644 --- a/drivers/pci/pci_gt64120.c +++ b/drivers/pci/pci_gt64120.c @@ -114,69 +114,6 @@ static int gt_config_access(struct gt64120_pci_controller *gt, return 0; } -#if !IS_ENABLED(CONFIG_DM_PCI) -static int gt_read_config_dword(struct pci_controller *hose, pci_dev_t dev, - int where, u32 *value) -{ - struct gt64120_pci_controller *gt = hose_to_gt64120(hose); - - *value = 0xffffffff; - return gt_config_access(gt, PCI_ACCESS_READ, dev, where, value); -} - -static int gt_write_config_dword(struct pci_controller *hose, pci_dev_t dev, - int where, u32 value) -{ - struct gt64120_pci_controller *gt = hose_to_gt64120(hose); - u32 data = value; - - return gt_config_access(gt, PCI_ACCESS_WRITE, dev, where, &data); -} - -void gt64120_pci_init(void *regs, unsigned long sys_bus, unsigned long sys_phys, - unsigned long sys_size, unsigned long mem_bus, - unsigned long mem_phys, unsigned long mem_size, - unsigned long io_bus, unsigned long io_phys, - unsigned long io_size) -{ - static struct gt64120_pci_controller global_gt; - struct gt64120_pci_controller *gt; - struct pci_controller *hose; - - gt = &global_gt; - gt->regs = regs; - - hose = >->hose; - - hose->first_busno = 0; - hose->last_busno = 0; - - /* System memory space */ - pci_set_region(&hose->regions[0], sys_bus, sys_phys, sys_size, - PCI_REGION_MEM | PCI_REGION_SYS_MEMORY); - - /* PCI memory space */ - pci_set_region(&hose->regions[1], mem_bus, mem_phys, mem_size, - PCI_REGION_MEM); - - /* PCI I/O space */ - pci_set_region(&hose->regions[2], io_bus, io_phys, io_size, - PCI_REGION_IO); - - hose->region_count = 3; - - pci_set_ops(hose, - pci_hose_read_config_byte_via_dword, - pci_hose_read_config_word_via_dword, - gt_read_config_dword, - pci_hose_write_config_byte_via_dword, - pci_hose_write_config_word_via_dword, - gt_write_config_dword); - - pci_register_hose(hose); - hose->last_busno = pci_hose_scan(hose); -} -#else static int gt64120_pci_read_config(const struct udevice *dev, pci_dev_t bdf, uint where, ulong *val, enum pci_size_t size) @@ -246,4 +183,3 @@ U_BOOT_DRIVER(gt64120_pci) = { .probe = gt64120_pci_probe, .priv_auto = sizeof(struct gt64120_pci_controller), }; -#endif diff --git a/drivers/pci/pci_msc01.c b/drivers/pci/pci_msc01.c index c17da475d01..2f1b688fc32 100644 --- a/drivers/pci/pci_msc01.c +++ b/drivers/pci/pci_msc01.c @@ -62,69 +62,6 @@ static int msc01_config_access(struct msc01_pci_controller *msc01, return 0; } -#if !IS_ENABLED(CONFIG_DM_PCI) -static int msc01_read_config_dword(struct pci_controller *hose, pci_dev_t dev, - int where, u32 *value) -{ - struct msc01_pci_controller *msc01 = hose_to_msc01(hose); - - *value = 0xffffffff; - return msc01_config_access(msc01, PCI_ACCESS_READ, dev, where, value); -} - -static int msc01_write_config_dword(struct pci_controller *hose, pci_dev_t dev, - int where, u32 value) -{ - struct msc01_pci_controller *gt = hose_to_msc01(hose); - u32 data = value; - - return msc01_config_access(gt, PCI_ACCESS_WRITE, dev, where, &data); -} - -void msc01_pci_init(void *base, unsigned long sys_bus, unsigned long sys_phys, - unsigned long sys_size, unsigned long mem_bus, - unsigned long mem_phys, unsigned long mem_size, - unsigned long io_bus, unsigned long io_phys, - unsigned long io_size) -{ - static struct msc01_pci_controller global_msc01; - struct msc01_pci_controller *msc01; - struct pci_controller *hose; - - msc01 = &global_msc01; - msc01->base = base; - - hose = &msc01->hose; - - hose->first_busno = 0; - hose->last_busno = 0; - - /* System memory space */ - pci_set_region(&hose->regions[0], sys_bus, sys_phys, sys_size, - PCI_REGION_MEM | PCI_REGION_SYS_MEMORY); - - /* PCI memory space */ - pci_set_region(&hose->regions[1], mem_bus, mem_phys, mem_size, - PCI_REGION_MEM); - - /* PCI I/O space */ - pci_set_region(&hose->regions[2], io_bus, io_phys, io_size, - PCI_REGION_IO); - - hose->region_count = 3; - - pci_set_ops(hose, - pci_hose_read_config_byte_via_dword, - pci_hose_read_config_word_via_dword, - msc01_read_config_dword, - pci_hose_write_config_byte_via_dword, - pci_hose_write_config_word_via_dword, - msc01_write_config_dword); - - pci_register_hose(hose); - hose->last_busno = pci_hose_scan(hose); -} -#else static int msc01_pci_read_config(const struct udevice *dev, pci_dev_t bdf, uint where, ulong *val, enum pci_size_t size) { @@ -192,4 +129,3 @@ U_BOOT_DRIVER(msc01_pci) = { .probe = msc01_pci_probe, .priv_auto = sizeof(struct msc01_pci_controller), }; -#endif diff --git a/drivers/pci/pcie_imx.c b/drivers/pci/pcie_imx.c index 7b46fdb89a3..756166fd3ea 100644 --- a/drivers/pci/pcie_imx.c +++ b/drivers/pci/pcie_imx.c @@ -681,86 +681,6 @@ static int imx_pcie_link_up(struct imx_pcie_priv *priv) return 0; } -#if !CONFIG_IS_ENABLED(DM_PCI) -static struct imx_pcie_priv imx_pcie_priv = { - .dbi_base = (void __iomem *)MX6_DBI_ADDR, - .cfg_base = (void __iomem *)MX6_ROOT_ADDR, -}; - -static struct imx_pcie_priv *priv = &imx_pcie_priv; - -static int imx_pcie_read_config(struct pci_controller *hose, pci_dev_t d, - int where, u32 *val) -{ - struct imx_pcie_priv *priv = hose->priv_data; - - return imx_pcie_read_cfg(priv, d, where, val); -} - -static int imx_pcie_write_config(struct pci_controller *hose, pci_dev_t d, - int where, u32 val) -{ - struct imx_pcie_priv *priv = hose->priv_data; - - return imx_pcie_write_cfg(priv, d, where, val); -} - -void imx_pcie_init(void) -{ - /* Static instance of the controller. */ - static struct pci_controller pcc; - struct pci_controller *hose = &pcc; - int ret; - - memset(&pcc, 0, sizeof(pcc)); - - hose->priv_data = priv; - - /* PCI I/O space */ - pci_set_region(&hose->regions[0], - MX6_IO_ADDR, MX6_IO_ADDR, - MX6_IO_SIZE, PCI_REGION_IO); - - /* PCI memory space */ - pci_set_region(&hose->regions[1], - MX6_MEM_ADDR, MX6_MEM_ADDR, - MX6_MEM_SIZE, PCI_REGION_MEM); - - /* System memory space */ - pci_set_region(&hose->regions[2], - MMDC0_ARB_BASE_ADDR, MMDC0_ARB_BASE_ADDR, - 0xefffffff, PCI_REGION_MEM | PCI_REGION_SYS_MEMORY); - - hose->region_count = 3; - - pci_set_ops(hose, - pci_hose_read_config_byte_via_dword, - pci_hose_read_config_word_via_dword, - imx_pcie_read_config, - pci_hose_write_config_byte_via_dword, - pci_hose_write_config_word_via_dword, - imx_pcie_write_config); - - /* Start the controller. */ - ret = imx_pcie_link_up(priv); - - if (!ret) { - pci_register_hose(hose); - hose->last_busno = pci_hose_scan(hose); - } -} - -void imx_pcie_remove(void) -{ - imx6_pcie_assert_core_reset(priv, true); -} - -/* Probe function. */ -void pci_init_board(void) -{ - imx_pcie_init(); -} -#else static int imx_pcie_dm_read_config(const struct udevice *dev, pci_dev_t bdf, uint offset, ulong *value, enum pci_size_t size) @@ -852,4 +772,3 @@ U_BOOT_DRIVER(imx_pcie) = { .priv_auto = sizeof(struct imx_pcie_priv), .flags = DM_FLAG_OS_PREPARE, }; -#endif diff --git a/drivers/pinctrl/nexell/pinctrl-nexell.c b/drivers/pinctrl/nexell/pinctrl-nexell.c index 6b01f47657c..20497a746d2 100644 --- a/drivers/pinctrl/nexell/pinctrl-nexell.c +++ b/drivers/pinctrl/nexell/pinctrl-nexell.c @@ -34,7 +34,7 @@ unsigned long pin_to_bank_base(struct udevice *dev, const char *pin_name, idx++; } bank[idx] = '\0'; - *pin = (u32)simple_strtoul(&pin_name[++idx], NULL, 10); + *pin = (u32)dectoul(&pin_name[++idx], NULL); /* lookup the pin bank data using the pin bank name */ for (idx = 0; idx < nr_banks; idx++) diff --git a/drivers/pinctrl/pinctrl-uclass.c b/drivers/pinctrl/pinctrl-uclass.c index ea7275ca004..dfe60b6dadb 100644 --- a/drivers/pinctrl/pinctrl-uclass.c +++ b/drivers/pinctrl/pinctrl-uclass.c @@ -69,7 +69,7 @@ static int pinctrl_select_state_full(struct udevice *dev, const char *statename) * If statename is not found in "pinctrl-names", * assume statename is just the integer state ID. */ - state = simple_strtoul(statename, &end, 10); + state = dectoul(statename, &end); if (*end) return -EINVAL; } diff --git a/drivers/power/power_core.c b/drivers/power/power_core.c index eeed8e24a90..4f7ba099cd9 100644 --- a/drivers/power/power_core.c +++ b/drivers/power/power_core.c @@ -159,7 +159,7 @@ static int do_pmic(struct cmd_tbl *cmdtp, int flag, int argc, if (argc < 4) return CMD_RET_USAGE; - reg = simple_strtoul(argv[3], NULL, 16); + reg = hextoul(argv[3], NULL); ret = pmic_reg_read(p, reg, &val); if (ret) @@ -174,8 +174,8 @@ static int do_pmic(struct cmd_tbl *cmdtp, int flag, int argc, if (argc < 5) return CMD_RET_USAGE; - reg = simple_strtoul(argv[3], NULL, 16); - val = simple_strtoul(argv[4], NULL, 16); + reg = hextoul(argv[3], NULL); + val = hextoul(argv[4], NULL); pmic_reg_write(p, reg, val); return CMD_RET_SUCCESS; diff --git a/drivers/qe/qe.c b/drivers/qe/qe.c index 97883ffc879..bd0a10c9d21 100644 --- a/drivers/qe/qe.c +++ b/drivers/qe/qe.c @@ -794,7 +794,7 @@ static int qe_cmd(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) return cmd_usage(cmdtp); if (strcmp(argv[1], "fw") == 0) { - addr = simple_strtoul(argv[2], NULL, 16); + addr = hextoul(argv[2], NULL); if (!addr) { printf("Invalid address\n"); @@ -807,7 +807,7 @@ static int qe_cmd(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) */ if (argc > 3) { - ulong length = simple_strtoul(argv[3], NULL, 16); + ulong length = hextoul(argv[3], NULL); struct qe_firmware *firmware = (void *)addr; if (length != be32_to_cpu(firmware->header.length)) { diff --git a/drivers/ram/octeon/octeon_ddr.c b/drivers/ram/octeon/octeon_ddr.c index e7b61d39f5c..42daf068668 100644 --- a/drivers/ram/octeon/octeon_ddr.c +++ b/drivers/ram/octeon/octeon_ddr.c @@ -2544,7 +2544,7 @@ try_again: eptr = env_get("limit_dram_mbytes"); if (eptr) { - unsigned int mbytes = simple_strtoul(eptr, NULL, 10); + unsigned int mbytes = dectoul(eptr, NULL); if (mbytes > 0) { memsize_mbytes = mbytes; diff --git a/drivers/rtc/m41t60.c b/drivers/rtc/m41t60.c index 692042b9351..b8ad33e0125 100644 --- a/drivers/rtc/m41t60.c +++ b/drivers/rtc/m41t60.c @@ -214,7 +214,7 @@ void rtc_reset(void) * the M41T60 documentation for further details. */ if (s) { - unsigned long const l = simple_strtoul(s, 0, 16); + unsigned long const l = hextoul(s, 0); if (l <= 0x3F) { if ((data[RTC_CTRL] & 0x3F) != l) { diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c index ce69750c7ff..d93d2419285 100644 --- a/drivers/scsi/scsi.c +++ b/drivers/scsi/scsi.c @@ -284,7 +284,6 @@ void scsi_init(void) */ for (i = 0; i < ARRAY_SIZE(scsi_device_list); i++) { /* get PCI Device ID */ -#ifdef CONFIG_DM_PCI struct udevice *dev; int ret; @@ -294,11 +293,6 @@ void scsi_init(void) busdevfunc = dm_pci_get_bdf(dev); break; } -#else - busdevfunc = pci_find_device(scsi_device_list[i].vendor, - scsi_device_list[i].device, - 0); -#endif if (busdevfunc != -1) break; } diff --git a/drivers/serial/serial-uclass.c b/drivers/serial/serial-uclass.c index 2b4feace53a..8171b17faf8 100644 --- a/drivers/serial/serial-uclass.c +++ b/drivers/serial/serial-uclass.c @@ -395,7 +395,7 @@ static int on_baudrate(const char *name, const char *value, enum env_op op, /* * Switch to new baudrate if new baudrate is supported */ - baudrate = simple_strtoul(value, NULL, 10); + baudrate = dectoul(value, NULL); /* Not actually changing */ if (gd->baudrate == baudrate) diff --git a/drivers/serial/serial.c b/drivers/serial/serial.c index dea25a049c8..ebbd21916d7 100644 --- a/drivers/serial/serial.c +++ b/drivers/serial/serial.c @@ -61,7 +61,7 @@ static int on_baudrate(const char *name, const char *value, enum env_op op, /* * Switch to new baudrate if new baudrate is supported */ - baudrate = simple_strtoul(value, NULL, 10); + baudrate = dectoul(value, NULL); /* Not actually changing */ if (gd->baudrate == baudrate) diff --git a/drivers/spi/ich.c b/drivers/spi/ich.c index 3d49c22a9da..08d54e86f45 100644 --- a/drivers/spi/ich.c +++ b/drivers/spi/ich.c @@ -918,12 +918,14 @@ static int ich_spi_child_pre_probe(struct udevice *dev) struct spi_slave *slave = dev_get_parent_priv(dev); /* - * Yes this controller can only write a small number of bytes at + * Yes this controller can only transfer a small number of bytes at * once! The limit is typically 64 bytes. For hardware sequencing a * a loop is used to get around this. */ - if (!plat->hwseq) + if (!plat->hwseq) { + slave->max_read_size = priv->databytes; slave->max_write_size = priv->databytes; + } /* * ICH 7 SPI controller only supports array read command * and byte program command for SST flash diff --git a/drivers/spi/spi-mem-nodm.c b/drivers/spi/spi-mem-nodm.c index a228c808c74..77ddb19a9f3 100644 --- a/drivers/spi/spi-mem-nodm.c +++ b/drivers/spi/spi-mem-nodm.c @@ -93,12 +93,14 @@ int spi_mem_adjust_op_size(struct spi_slave *slave, if (slave->max_write_size && len > slave->max_write_size) return -EINVAL; - if (op->data.dir == SPI_MEM_DATA_IN && slave->max_read_size) - op->data.nbytes = min(op->data.nbytes, - slave->max_read_size); - else if (slave->max_write_size) + if (op->data.dir == SPI_MEM_DATA_IN) { + if (slave->max_read_size) + op->data.nbytes = min(op->data.nbytes, + slave->max_read_size); + } else if (slave->max_write_size) { op->data.nbytes = min(op->data.nbytes, slave->max_write_size - len); + } if (!op->data.nbytes) return -EINVAL; diff --git a/drivers/timer/Kconfig b/drivers/timer/Kconfig index ee81dfa7768..89131426542 100644 --- a/drivers/timer/Kconfig +++ b/drivers/timer/Kconfig @@ -124,12 +124,12 @@ config RENESAS_OSTM_TIMER Enables support for the Renesas OSTM Timer driver. This timer is present on Renesas RZ/A1 R7S72100 SoCs. -config X86_TSC_TIMER_EARLY_FREQ - int "x86 TSC timer frequency in MHz when used as the early timer" +config X86_TSC_TIMER_FREQ + int "x86 TSC timer frequency in Hz" depends on X86_TSC_TIMER - default 1000 + default 1000000000 help - Sets the estimated CPU frequency in MHz when TSC is used as the + Sets the estimated CPU frequency in Hz when TSC is used as the early timer and the frequency can neither be calibrated via some hardware ways, nor got from device tree at the time when device tree is not available yet. diff --git a/drivers/timer/tsc_timer.c b/drivers/timer/tsc_timer.c index 7d19a99622b..adef50c3744 100644 --- a/drivers/timer/tsc_timer.c +++ b/drivers/timer/tsc_timer.c @@ -425,12 +425,13 @@ static void tsc_timer_ensure_setup(bool early) goto done; if (early) - fast_calibrate = CONFIG_X86_TSC_TIMER_EARLY_FREQ; + gd->arch.clock_rate = CONFIG_X86_TSC_TIMER_FREQ; else return; done: - gd->arch.clock_rate = fast_calibrate * 1000000; + if (!gd->arch.clock_rate) + gd->arch.clock_rate = fast_calibrate * 1000000; } gd->arch.tsc_inited = true; } diff --git a/drivers/tpm/Makefile b/drivers/tpm/Makefile index f64d20067f8..c65be526700 100644 --- a/drivers/tpm/Makefile +++ b/drivers/tpm/Makefile @@ -6,11 +6,11 @@ obj-$(CONFIG_$(SPL_TPL_)TPM) += tpm-uclass.o obj-$(CONFIG_TPM_ATMEL_TWI) += tpm_atmel_twi.o obj-$(CONFIG_TPM_TIS_INFINEON) += tpm_tis_infineon.o obj-$(CONFIG_TPM_TIS_LPC) += tpm_tis_lpc.o -obj-$(CONFIG_TPM_TIS_SANDBOX) += tpm_tis_sandbox.o +obj-$(CONFIG_TPM_TIS_SANDBOX) += tpm_tis_sandbox.o sandbox_common.o obj-$(CONFIG_TPM_ST33ZP24_I2C) += tpm_tis_st33zp24_i2c.o obj-$(CONFIG_TPM_ST33ZP24_SPI) += tpm_tis_st33zp24_spi.o obj-$(CONFIG_$(SPL_TPL_)TPM2_CR50_I2C) += cr50_i2c.o -obj-$(CONFIG_TPM2_TIS_SANDBOX) += tpm2_tis_sandbox.o +obj-$(CONFIG_TPM2_TIS_SANDBOX) += tpm2_tis_sandbox.o sandbox_common.o obj-$(CONFIG_TPM2_TIS_SPI) += tpm2_tis_spi.o obj-$(CONFIG_TPM2_FTPM_TEE) += tpm2_ftpm_tee.o diff --git a/drivers/tpm/sandbox_common.c b/drivers/tpm/sandbox_common.c new file mode 100644 index 00000000000..7e0b2502e35 --- /dev/null +++ b/drivers/tpm/sandbox_common.c @@ -0,0 +1,77 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Common features for sandbox TPM1 and TPM2 implementations + * + * Copyright 2021 Google LLC + */ + +#define LOG_CATEGORY UCLASS_TPM + +#include <common.h> +#include <tpm-v1.h> +#include <tpm-v2.h> +#include <asm/unaligned.h> +#include "sandbox_common.h" + +#define TPM_ERR_CODE_OFS (2 + 4) /* after tag and size */ + +int sb_tpm_index_to_seq(u32 index) +{ + index &= ~HR_NV_INDEX; + switch (index) { + case FIRMWARE_NV_INDEX: + return NV_SEQ_FIRMWARE; + case KERNEL_NV_INDEX: + return NV_SEQ_KERNEL; + case BACKUP_NV_INDEX: + return NV_SEQ_BACKUP; + case FWMP_NV_INDEX: + return NV_SEQ_FWMP; + case MRC_REC_HASH_NV_INDEX: + return NV_SEQ_REC_HASH; + case 0: + return NV_SEQ_GLOBAL_LOCK; + case TPM_NV_INDEX_LOCK: + return NV_SEQ_ENABLE_LOCKING; + } + + printf("Invalid nv index %#x\n", index); + return -1; +} + +void sb_tpm_read_data(const struct nvdata_state nvdata[NV_SEQ_COUNT], + enum sandbox_nv_space seq, u8 *buf, int data_ofs, + int length) +{ + const struct nvdata_state *nvd = &nvdata[seq]; + + if (!nvd->present) + put_unaligned_be32(TPM_BADINDEX, buf + TPM_ERR_CODE_OFS); + else if (length > nvd->length) + put_unaligned_be32(TPM_BAD_DATASIZE, buf + TPM_ERR_CODE_OFS); + else + memcpy(buf + data_ofs, &nvd->data, length); +} + +void sb_tpm_write_data(struct nvdata_state nvdata[NV_SEQ_COUNT], + enum sandbox_nv_space seq, const u8 *buf, int data_ofs, + int length) +{ + struct nvdata_state *nvd = &nvdata[seq]; + + if (length > nvd->length) + log_err("Invalid length %x (max %x)\n", length, nvd->length); + else + memcpy(&nvdata[seq].data, buf + data_ofs, length); +} + +void sb_tpm_define_data(struct nvdata_state nvdata[NV_SEQ_COUNT], + enum sandbox_nv_space seq, int length) +{ + struct nvdata_state *nvd = &nvdata[seq]; + + if (length > NV_DATA_SIZE) + log_err("Invalid length %x (max %x)\n", length, NV_DATA_SIZE); + nvd->length = length; + nvd->present = true; +} diff --git a/drivers/tpm/sandbox_common.h b/drivers/tpm/sandbox_common.h new file mode 100644 index 00000000000..e822a200fd3 --- /dev/null +++ b/drivers/tpm/sandbox_common.h @@ -0,0 +1,108 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* + * Common features for sandbox TPM1 and TPM2 implementations + * + * Copyright 2021 Google LLC + */ + +#ifndef __TPM_SANDBOX_COMMON_H +#define __TPM_SANDBOX_COMMON_H + +/* + * These numbers derive from adding the sizes of command fields as shown in + * the TPM commands manual. + */ +#define TPM_HDR_LEN 10 + +/* These are the different non-volatile spaces that we emulate */ +enum sandbox_nv_space { + NV_SEQ_ENABLE_LOCKING, + NV_SEQ_GLOBAL_LOCK, + NV_SEQ_FIRMWARE, + NV_SEQ_KERNEL, + NV_SEQ_BACKUP, + NV_SEQ_FWMP, + NV_SEQ_REC_HASH, + + NV_SEQ_COUNT, +}; + +/* TPM NVRAM location indices */ +#define FIRMWARE_NV_INDEX 0x1007 +#define KERNEL_NV_INDEX 0x1008 +#define BACKUP_NV_INDEX 0x1009 +#define FWMP_NV_INDEX 0x100a +#define MRC_REC_HASH_NV_INDEX 0x100b + +/* Size of each non-volatile space */ +#define NV_DATA_SIZE 0x28 + +/** + * struct nvdata_state - state of a single non-volatile-data 'space' + * + * @present: true if present + * @length: length in bytes (max NV_DATA_SIZE) + * @data: contents of non-volatile space + */ +struct nvdata_state { + bool present; + int length; + u8 data[NV_DATA_SIZE]; +}; + +/** + * sb_tpm_index_to_seq() - convert an index into a space sequence number + * + * This converts the index as used by the vboot code into an internal sequence + * number used by the sandbox emulation. + * + * @index: Index to use (FIRMWARE_NV_INDEX, etc.) + * @return associated space (enum sandbox_nv_space) + */ +int sb_tpm_index_to_seq(uint index); + +/** + * sb_tpm_read_data() - Read non-volatile data + * + * This handles a TPM read of nvdata. If the nvdata is not present, a + * TPM_BADINDEX error is put in the buffer. If @length is too large, + * TPM_BAD_DATASIZE is put in the buffer. + * + * @nvdata: Current nvdata state + * @seq: Sequence number to read + * @recvbuf: Buffer to update with the TPM response, assumed to contain zeroes + * @data_ofs: Offset of the 'data' portion of @recvbuf + * @length: Number of bytes to read + */ +void sb_tpm_read_data(const struct nvdata_state nvdata[NV_SEQ_COUNT], + enum sandbox_nv_space seq, u8 *recvbuf, int data_ofs, + int length); + +/** + * sb_tpm_write_data() - Write non-volatile data + * + * If @length is too large, an error is logged and nothing is written. + * + * @nvdata: Current nvdata state + * @seq: Sequence number to read + * @buf: Buffer containing the data to write + * @data_ofs: Offset of the 'data' portion of @buf + * @length: Number of bytes to write + */ +void sb_tpm_write_data(struct nvdata_state nvdata[NV_SEQ_COUNT], + enum sandbox_nv_space seq, const u8 *buf, int data_ofs, + int length); + +/** + * sb_tpm_define_data() - Set up non-volatile data + * + * If @length is too large, an error is logged and nothing is written. + * + * @nvdata: Current nvdata state + * @seq: Sequence number to set up + * @length: Length of space in bytes + */ +void sb_tpm_define_data(struct nvdata_state nvdata[NV_SEQ_COUNT], + enum sandbox_nv_space seq, int length); + +#endif diff --git a/drivers/tpm/tpm2_tis_sandbox.c b/drivers/tpm/tpm2_tis_sandbox.c index 24c804a5645..ac6eb143539 100644 --- a/drivers/tpm/tpm2_tis_sandbox.c +++ b/drivers/tpm/tpm2_tis_sandbox.c @@ -11,6 +11,8 @@ #include <asm/unaligned.h> #include <linux/bitops.h> #include <u-boot/crc.h> +#include <u-boot/sha256.h> +#include "sandbox_common.h" /* Hierarchies */ enum tpm2_hierarchy { @@ -38,29 +40,178 @@ enum tpm2_cap_tpm_property { #define SANDBOX_TPM_PCR_NB 1 -static const u8 sandbox_extended_once_pcr[] = { - 0xf5, 0xa5, 0xfd, 0x42, 0xd1, 0x6a, 0x20, 0x30, - 0x27, 0x98, 0xef, 0x6e, 0xd3, 0x09, 0x97, 0x9b, - 0x43, 0x00, 0x3d, 0x23, 0x20, 0xd9, 0xf0, 0xe8, - 0xea, 0x98, 0x31, 0xa9, 0x27, 0x59, 0xfb, 0x4b, -}; - +/* + * Information about our TPM emulation. This is preserved in the sandbox + * state file if enabled. + * + * @valid: true if this is valid (only used in s_state) + * @init_done: true if open() has been called + * @startup_done: true if TPM2_CC_STARTUP has been processed + * @tests_done: true if TPM2_CC_SELF_TEST has be processed + * @pw: TPM password per hierarchy + * @pw_sz: Size of each password in bytes + * @properties: TPM properties + * @pcr: TPM Platform Configuration Registers. Each of these holds a hash and + * can be 'extended' a number of times, meaning another hash is added into + * its value (initial value all zeroes) + * @pcr_extensions: Number of times each PCR has been extended (starts at 0) + * @nvdata: non-volatile data, used to store important things for the platform + */ struct sandbox_tpm2 { + bool valid; /* TPM internal states */ bool init_done; bool startup_done; bool tests_done; - /* TPM password per hierarchy */ char pw[TPM2_HIERARCHY_NB][TPM2_DIGEST_LEN + 1]; int pw_sz[TPM2_HIERARCHY_NB]; - /* TPM properties */ u32 properties[TPM2_PROPERTY_NB]; - /* TPM PCRs */ u8 pcr[SANDBOX_TPM_PCR_NB][TPM2_DIGEST_LEN]; - /* TPM PCR extensions */ u32 pcr_extensions[SANDBOX_TPM_PCR_NB]; + struct nvdata_state nvdata[NV_SEQ_COUNT]; }; +static struct sandbox_tpm2 s_state, *g_state; + +/** + * sandbox_tpm2_read_state() - read the sandbox EC state from the state file + * + * If data is available, then blob and node will provide access to it. If + * not this function sets up an empty TPM. + * + * @blob: Pointer to device tree blob, or NULL if no data to read + * @node: Node offset to read from + */ +static int sandbox_tpm2_read_state(const void *blob, int node) +{ + struct sandbox_tpm2 *state = &s_state; + char prop_name[20]; + const char *prop; + int len; + int i; + + if (!blob) + return 0; + state->tests_done = fdtdec_get_int(blob, node, "tests-done", 0); + + for (i = 0; i < TPM2_HIERARCHY_NB; i++) { + snprintf(prop_name, sizeof(prop_name), "pw%d", i); + + prop = fdt_getprop(blob, node, prop_name, &len); + if (len > TPM2_DIGEST_LEN) + return log_msg_ret("pw", -E2BIG); + if (prop) { + memcpy(state->pw[i], prop, len); + state->pw_sz[i] = len; + } + } + + for (i = 0; i < TPM2_PROPERTY_NB; i++) { + snprintf(prop_name, sizeof(prop_name), "properties%d", i); + state->properties[i] = fdtdec_get_uint(blob, node, prop_name, + 0); + } + + for (i = 0; i < SANDBOX_TPM_PCR_NB; i++) { + int subnode; + + snprintf(prop_name, sizeof(prop_name), "pcr%d", i); + subnode = fdt_subnode_offset(blob, node, prop_name); + if (subnode < 0) + continue; + prop = fdt_getprop(blob, subnode, "value", &len); + if (len != TPM2_DIGEST_LEN) + return log_msg_ret("pcr", -E2BIG); + memcpy(state->pcr[i], prop, TPM2_DIGEST_LEN); + state->pcr_extensions[i] = fdtdec_get_uint(blob, subnode, + "extensions", 0); + } + + for (i = 0; i < NV_SEQ_COUNT; i++) { + struct nvdata_state *nvd = &state->nvdata[i]; + + sprintf(prop_name, "nvdata%d", i); + prop = fdt_getprop(blob, node, prop_name, &len); + if (len > NV_DATA_SIZE) + return log_msg_ret("nvd", -E2BIG); + if (prop) { + memcpy(nvd->data, prop, len); + nvd->length = len; + nvd->present = true; + } + } + s_state.valid = true; + + return 0; +} + +/** + * sandbox_tpm2_write_state() - Write out our state to the state file + * + * The caller will ensure that there is a node ready for the state. The node + * may already contain the old state, in which case it is overridden. + * + * @blob: Device tree blob holding state + * @node: Node to write our state into + */ +static int sandbox_tpm2_write_state(void *blob, int node) +{ + const struct sandbox_tpm2 *state = g_state; + char prop_name[20]; + int i; + + if (!state) + return 0; + + /* + * We are guaranteed enough space to write basic properties. This is + * SANDBOX_STATE_MIN_SPACE. + * + * We could use fdt_add_subnode() to put each set of data in its + * own node - perhaps useful if we add access information to each. + */ + fdt_setprop_u32(blob, node, "tests-done", state->tests_done); + + for (i = 0; i < TPM2_HIERARCHY_NB; i++) { + if (state->pw_sz[i]) { + snprintf(prop_name, sizeof(prop_name), "pw%d", i); + fdt_setprop(blob, node, prop_name, state->pw[i], + state->pw_sz[i]); + } + } + + for (i = 0; i < TPM2_PROPERTY_NB; i++) { + snprintf(prop_name, sizeof(prop_name), "properties%d", i); + fdt_setprop_u32(blob, node, prop_name, state->properties[i]); + } + + for (i = 0; i < SANDBOX_TPM_PCR_NB; i++) { + int subnode; + + snprintf(prop_name, sizeof(prop_name), "pcr%d", i); + subnode = fdt_add_subnode(blob, node, prop_name); + fdt_setprop(blob, subnode, "value", state->pcr[i], + TPM2_DIGEST_LEN); + fdt_setprop_u32(blob, subnode, "extensions", + state->pcr_extensions[i]); + } + + for (i = 0; i < NV_SEQ_COUNT; i++) { + const struct nvdata_state *nvd = &state->nvdata[i]; + + if (nvd->present) { + snprintf(prop_name, sizeof(prop_name), "nvdata%d", i); + fdt_setprop(blob, node, prop_name, nvd->data, + nvd->length); + } + } + + return 0; +} + +SANDBOX_STATE_IO(sandbox_tpm2, "sandbox,tpm2", sandbox_tpm2_read_state, + sandbox_tpm2_write_state); + /* * Check the tag validity depending on the command (authentication required or * not). If authentication is required, check it is valid. Update the auth @@ -93,6 +244,10 @@ static int sandbox_tpm2_check_session(struct udevice *dev, u32 command, u16 tag, case TPM2_CC_DAM_RESET: case TPM2_CC_DAM_PARAMETERS: case TPM2_CC_PCR_EXTEND: + case TPM2_CC_NV_READ: + case TPM2_CC_NV_WRITE: + case TPM2_CC_NV_WRITELOCK: + case TPM2_CC_NV_DEFINE_SPACE: if (tag != TPM2_ST_SESSIONS) { printf("Session required for command 0x%x\n", command); return TPM2_RC_AUTH_CONTEXT; @@ -121,6 +276,10 @@ static int sandbox_tpm2_check_session(struct udevice *dev, u32 command, u16 tag, break; case TPM2_RH_PLATFORM: *hierarchy = TPM2_HIERARCHY_PLATFORM; + if (command == TPM2_CC_NV_READ || + command == TPM2_CC_NV_WRITE || + command == TPM2_CC_NV_WRITELOCK) + *auth += sizeof(u32); break; default: printf("Wrong handle 0x%x\n", handle); @@ -242,15 +401,17 @@ static int sandbox_tpm2_extend(struct udevice *dev, int pcr_index, const u8 *extension) { struct sandbox_tpm2 *tpm = dev_get_priv(dev); - int i; + sha256_context ctx; - /* Only simulate the first extensions from all '0' with only '0' */ - for (i = 0; i < TPM2_DIGEST_LEN; i++) - if (tpm->pcr[pcr_index][i] || extension[i]) - return TPM2_RC_FAILURE; + /* Zero the PCR if this is the first use */ + if (!tpm->pcr_extensions[pcr_index]) + memset(tpm->pcr[pcr_index], '\0', TPM2_DIGEST_LEN); + + sha256_starts(&ctx); + sha256_update(&ctx, tpm->pcr[pcr_index], TPM2_DIGEST_LEN); + sha256_update(&ctx, extension, TPM2_DIGEST_LEN); + sha256_finish(&ctx, tpm->pcr[pcr_index]); - memcpy(tpm->pcr[pcr_index], sandbox_extended_once_pcr, - TPM2_DIGEST_LEN); tpm->pcr_extensions[pcr_index]++; return 0; @@ -477,15 +638,8 @@ static int sandbox_tpm2_xfer(struct udevice *dev, const u8 *sendbuf, for (i = 0; i < pcr_array_sz; i++) pcr_map += (u64)sent[i] << (i * 8); - if (pcr_map >> SANDBOX_TPM_PCR_NB) { - printf("Sandbox TPM handles up to %d PCR(s)\n", - SANDBOX_TPM_PCR_NB); - rc = TPM2_RC_VALUE; - return sandbox_tpm2_fill_buf(recv, recv_len, tag, rc); - } - if (!pcr_map) { - printf("Empty PCR map.\n"); + printf("Empty PCR map\n"); rc = TPM2_RC_VALUE; return sandbox_tpm2_fill_buf(recv, recv_len, tag, rc); } @@ -494,6 +648,13 @@ static int sandbox_tpm2_xfer(struct udevice *dev, const u8 *sendbuf, if (pcr_map & BIT(i)) pcr_index = i; + if (pcr_index >= SANDBOX_TPM_PCR_NB) { + printf("Invalid index %d, sandbox TPM handles up to %d PCR(s)\n", + pcr_index, SANDBOX_TPM_PCR_NB); + rc = TPM2_RC_VALUE; + return sandbox_tpm2_fill_buf(recv, recv_len, tag, rc); + } + /* Write tag */ put_unaligned_be16(tag, recv); recv += sizeof(tag); @@ -527,9 +688,9 @@ static int sandbox_tpm2_xfer(struct udevice *dev, const u8 *sendbuf, pcr_index = get_unaligned_be32(sendbuf + sizeof(tag) + sizeof(length) + sizeof(command)); - if (pcr_index > SANDBOX_TPM_PCR_NB) { - printf("Sandbox TPM handles up to %d PCR(s)\n", - SANDBOX_TPM_PCR_NB); + if (pcr_index >= SANDBOX_TPM_PCR_NB) { + printf("Invalid index %d, sandbox TPM handles up to %d PCR(s)\n", + pcr_index, SANDBOX_TPM_PCR_NB); rc = TPM2_RC_VALUE; } @@ -557,6 +718,64 @@ static int sandbox_tpm2_xfer(struct udevice *dev, const u8 *sendbuf, sandbox_tpm2_fill_buf(recv, recv_len, tag, rc); break; + case TPM2_CC_NV_READ: { + int index, seq; + + index = get_unaligned_be32(sendbuf + TPM2_HDR_LEN + 4); + length = get_unaligned_be16(sent); + /* ignore offset */ + seq = sb_tpm_index_to_seq(index); + if (seq < 0) + return log_msg_ret("index", -EINVAL); + printf("tpm: nvread index=%#02x, len=%#02x, seq=%#02x\n", index, + length, seq); + *recv_len = TPM2_HDR_LEN + 6 + length; + memset(recvbuf, '\0', *recv_len); + put_unaligned_be32(length, recvbuf + 2); + sb_tpm_read_data(tpm->nvdata, seq, recvbuf, + TPM2_HDR_LEN + 4 + 2, length); + break; + } + case TPM2_CC_NV_WRITE: { + int index, seq; + + index = get_unaligned_be32(sendbuf + TPM2_HDR_LEN + 4); + length = get_unaligned_be16(sent); + sent += sizeof(u16); + + /* ignore offset */ + seq = sb_tpm_index_to_seq(index); + if (seq < 0) + return log_msg_ret("index", -EINVAL); + printf("tpm: nvwrite index=%#02x, len=%#02x, seq=%#02x\n", index, + length, seq); + memcpy(&tpm->nvdata[seq].data, sent, length); + tpm->nvdata[seq].present = true; + *recv_len = TPM2_HDR_LEN + 2; + memset(recvbuf, '\0', *recv_len); + break; + } + case TPM2_CC_NV_DEFINE_SPACE: { + int policy_size, index, seq; + + policy_size = get_unaligned_be16(sent + 12); + index = get_unaligned_be32(sent + 2); + sent += 14 + policy_size; + length = get_unaligned_be16(sent); + seq = sb_tpm_index_to_seq(index); + if (seq < 0) + return -EINVAL; + printf("tpm: define_space index=%x, len=%x, seq=%x, policy_size=%x\n", + index, length, seq, policy_size); + sb_tpm_define_data(tpm->nvdata, seq, length); + *recv_len = 12; + memset(recvbuf, '\0', *recv_len); + break; + } + case TPM2_CC_NV_WRITELOCK: + *recv_len = 12; + memset(recvbuf, '\0', *recv_len); + break; default: printf("TPM2 command %02x unknown in Sandbox\n", command); rc = TPM2_RC_COMMAND_CODE; @@ -594,11 +813,13 @@ static int sandbox_tpm2_probe(struct udevice *dev) /* Use the TPM v2 stack */ priv->version = TPM_V2; - memset(tpm, 0, sizeof(*tpm)); - priv->pcr_count = 32; priv->pcr_select_min = 2; + if (s_state.valid) + memcpy(tpm, &s_state, sizeof(*tpm)); + g_state = tpm; + return 0; } diff --git a/drivers/tpm/tpm_tis_sandbox.c b/drivers/tpm/tpm_tis_sandbox.c index 67139cea3be..efbeb00ab63 100644 --- a/drivers/tpm/tpm_tis_sandbox.c +++ b/drivers/tpm/tpm_tis_sandbox.c @@ -9,61 +9,10 @@ #include <asm/state.h> #include <asm/unaligned.h> #include <u-boot/crc.h> - -/* TPM NVRAM location indices. */ -#define FIRMWARE_NV_INDEX 0x1007 -#define KERNEL_NV_INDEX 0x1008 -#define BACKUP_NV_INDEX 0x1009 -#define FWMP_NV_INDEX 0x100a -#define REC_HASH_NV_INDEX 0x100b -#define REC_HASH_NV_SIZE VB2_SHA256_DIGEST_SIZE +#include "sandbox_common.h" #define NV_DATA_PUBLIC_PERMISSIONS_OFFSET 60 -/* Kernel TPM space - KERNEL_NV_INDEX, locked with physical presence */ -#define ROLLBACK_SPACE_KERNEL_VERSION 2 -#define ROLLBACK_SPACE_KERNEL_UID 0x4752574C /* 'GRWL' */ - -struct rollback_space_kernel { - /* Struct version, for backwards compatibility */ - uint8_t struct_version; - /* Unique ID to detect space redefinition */ - uint32_t uid; - /* Kernel versions */ - uint32_t kernel_versions; - /* Reserved for future expansion */ - uint8_t reserved[3]; - /* Checksum (v2 and later only) */ - uint8_t crc8; -} __packed rollback_space_kernel; - -/* - * These numbers derive from adding the sizes of command fields as shown in - * the TPM commands manual. - */ -#define TPM_REQUEST_HEADER_LENGTH 10 -#define TPM_RESPONSE_HEADER_LENGTH 10 - -/* These are the different non-volatile spaces that we emulate */ -enum { - NV_GLOBAL_LOCK, - NV_SEQ_FIRMWARE, - NV_SEQ_KERNEL, - NV_SEQ_BACKUP, - NV_SEQ_FWMP, - NV_SEQ_REC_HASH, - - NV_SEQ_COUNT, -}; - -/* Size of each non-volatile space */ -#define NV_DATA_SIZE 0x20 - -struct nvdata_state { - bool present; - u8 data[NV_DATA_SIZE]; -}; - /* * Information about our TPM emulation. This is preserved in the sandbox * state file if enabled. @@ -71,7 +20,7 @@ struct nvdata_state { static struct tpm_state { bool valid; struct nvdata_state nvdata[NV_SEQ_COUNT]; -} g_state; +} s_state, *g_state; /** * sandbox_tpm_read_state() - read the sandbox EC state from the state file @@ -84,6 +33,7 @@ static struct tpm_state { */ static int sandbox_tpm_read_state(const void *blob, int node) { + struct tpm_state *state = &s_state; const char *prop; int len; int i; @@ -92,22 +42,27 @@ static int sandbox_tpm_read_state(const void *blob, int node) return 0; for (i = 0; i < NV_SEQ_COUNT; i++) { + struct nvdata_state *nvd = &state->nvdata[i]; char prop_name[20]; sprintf(prop_name, "nvdata%d", i); prop = fdt_getprop(blob, node, prop_name, &len); - if (prop && len == NV_DATA_SIZE) { - memcpy(g_state.nvdata[i].data, prop, NV_DATA_SIZE); - g_state.nvdata[i].present = true; + if (len >= NV_DATA_SIZE) + return log_msg_ret("nvd", -E2BIG); + if (prop) { + memcpy(nvd->data, prop, len); + nvd->length = len; + nvd->present = true; } } - g_state.valid = true; + + s_state.valid = true; return 0; } /** - * cros_ec_write_state() - Write out our state to the state file + * sandbox_tpm_write_state() - Write out our state to the state file * * The caller will ensure that there is a node ready for the state. The node * may already contain the old state, in which case it is overridden. @@ -117,20 +72,25 @@ static int sandbox_tpm_read_state(const void *blob, int node) */ static int sandbox_tpm_write_state(void *blob, int node) { + const struct tpm_state *state = g_state; int i; + if (!state) + return 0; + /* * We are guaranteed enough space to write basic properties. * We could use fdt_add_subnode() to put each set of data in its * own node - perhaps useful if we add access informaiton to each. */ for (i = 0; i < NV_SEQ_COUNT; i++) { + const struct nvdata_state *nvd = &state->nvdata[i]; char prop_name[20]; - if (g_state.nvdata[i].present) { - sprintf(prop_name, "nvdata%d", i); - fdt_setprop(blob, node, prop_name, - g_state.nvdata[i].data, NV_DATA_SIZE); + if (nvd->present) { + snprintf(prop_name, sizeof(prop_name), "nvdata%d", i); + fdt_setprop(blob, node, prop_name, nvd->data, + nvd->length); } } @@ -140,27 +100,6 @@ static int sandbox_tpm_write_state(void *blob, int node) SANDBOX_STATE_IO(sandbox_tpm, "google,sandbox-tpm", sandbox_tpm_read_state, sandbox_tpm_write_state); -static int index_to_seq(uint32_t index) -{ - switch (index) { - case FIRMWARE_NV_INDEX: - return NV_SEQ_FIRMWARE; - case KERNEL_NV_INDEX: - return NV_SEQ_KERNEL; - case BACKUP_NV_INDEX: - return NV_SEQ_BACKUP; - case FWMP_NV_INDEX: - return NV_SEQ_FWMP; - case REC_HASH_NV_INDEX: - return NV_SEQ_REC_HASH; - case 0: - return NV_GLOBAL_LOCK; - } - - printf("Invalid nv index %#x\n", index); - return -1; -} - static void handle_cap_flag_space(u8 **datap, uint index) { struct tpm_nv_data_public pub; @@ -201,16 +140,13 @@ static int sandbox_tpm_xfer(struct udevice *dev, const uint8_t *sendbuf, printf("Get flags index %#02x\n", index); *recv_len = 22; memset(recvbuf, '\0', *recv_len); - data = recvbuf + TPM_RESPONSE_HEADER_LENGTH + - sizeof(uint32_t); + data = recvbuf + TPM_HDR_LEN + sizeof(uint32_t); switch (index) { case FIRMWARE_NV_INDEX: break; case KERNEL_NV_INDEX: handle_cap_flag_space(&data, index); - *recv_len = data - recvbuf - - TPM_RESPONSE_HEADER_LENGTH - - sizeof(uint32_t); + *recv_len = data - recvbuf; break; case TPM_CAP_FLAG_PERMANENT: { struct tpm_permanent_flags *pflags; @@ -227,15 +163,12 @@ static int sandbox_tpm_xfer(struct udevice *dev, const uint8_t *sendbuf, printf(" ** Unknown flags index %x\n", index); return -ENOSYS; } - put_unaligned_be32(*recv_len, - recvbuf + - TPM_RESPONSE_HEADER_LENGTH); + put_unaligned_be32(*recv_len, recvbuf + TPM_HDR_LEN); break; case TPM_CAP_NV_INDEX: index = get_unaligned_be32(sendbuf + 18); printf("Get cap nv index %#02x\n", index); - put_unaligned_be32(22, recvbuf + - TPM_RESPONSE_HEADER_LENGTH); + put_unaligned_be32(22, recvbuf + TPM_HDR_LEN); break; default: printf(" ** Unknown 0x65 command type %#02x\n", @@ -246,54 +179,42 @@ static int sandbox_tpm_xfer(struct udevice *dev, const uint8_t *sendbuf, case TPM_CMD_NV_WRITE_VALUE: index = get_unaligned_be32(sendbuf + 10); length = get_unaligned_be32(sendbuf + 18); - seq = index_to_seq(index); + seq = sb_tpm_index_to_seq(index); if (seq < 0) return -EINVAL; printf("tpm: nvwrite index=%#02x, len=%#02x\n", index, length); - memcpy(&tpm->nvdata[seq].data, sendbuf + 22, length); - tpm->nvdata[seq].present = true; - *recv_len = 12; - memset(recvbuf, '\0', *recv_len); + sb_tpm_write_data(tpm->nvdata, seq, sendbuf, 22, length); break; case TPM_CMD_NV_READ_VALUE: /* nvread */ index = get_unaligned_be32(sendbuf + 10); length = get_unaligned_be32(sendbuf + 18); - seq = index_to_seq(index); + seq = sb_tpm_index_to_seq(index); if (seq < 0) return -EINVAL; printf("tpm: nvread index=%#02x, len=%#02x, seq=%#02x\n", index, length, seq); - *recv_len = TPM_RESPONSE_HEADER_LENGTH + sizeof(uint32_t) + - length; + *recv_len = TPM_HDR_LEN + sizeof(uint32_t) + length; memset(recvbuf, '\0', *recv_len); - put_unaligned_be32(length, recvbuf + - TPM_RESPONSE_HEADER_LENGTH); - if (seq == NV_SEQ_KERNEL) { - struct rollback_space_kernel rsk; - - data = recvbuf + TPM_RESPONSE_HEADER_LENGTH + - sizeof(uint32_t); - memset(&rsk, 0, sizeof(struct rollback_space_kernel)); - rsk.struct_version = 2; - rsk.uid = ROLLBACK_SPACE_KERNEL_UID; - rsk.crc8 = crc8(0, (unsigned char *)&rsk, - offsetof(struct rollback_space_kernel, - crc8)); - memcpy(data, &rsk, sizeof(rsk)); - } else if (!tpm->nvdata[seq].present) { - put_unaligned_be32(TPM_BADINDEX, recvbuf + - sizeof(uint16_t) + sizeof(uint32_t)); - } else { - memcpy(recvbuf + TPM_RESPONSE_HEADER_LENGTH + - sizeof(uint32_t), &tpm->nvdata[seq].data, - length); - } + put_unaligned_be32(length, recvbuf + TPM_HDR_LEN); + sb_tpm_read_data(tpm->nvdata, seq, recvbuf, TPM_HDR_LEN + 4, + length); break; case TPM_CMD_EXTEND: *recv_len = 30; memset(recvbuf, '\0', *recv_len); break; case TPM_CMD_NV_DEFINE_SPACE: + index = get_unaligned_be32(sendbuf + 12); + length = get_unaligned_be32(sendbuf + 77); + seq = sb_tpm_index_to_seq(index); + if (seq < 0) + return -EINVAL; + printf("tpm: define_space index=%#02x, len=%#02x, seq=%#02x\n", + index, length, seq); + sb_tpm_define_data(tpm->nvdata, seq, length); + *recv_len = 12; + memset(recvbuf, '\0', *recv_len); + break; case 0x15: /* pcr read */ case 0x5d: /* force clear */ case 0x6f: /* physical enable */ @@ -328,7 +249,9 @@ static int sandbox_tpm_probe(struct udevice *dev) { struct tpm_state *tpm = dev_get_priv(dev); - memcpy(tpm, &g_state, sizeof(*tpm)); + if (s_state.valid) + memcpy(tpm, &s_state, sizeof(*tpm)); + g_state = tpm; return 0; } diff --git a/drivers/usb/cdns3/gadget.c b/drivers/usb/cdns3/gadget.c index 83dbb5a103d..fcaeab9cc1d 100644 --- a/drivers/usb/cdns3/gadget.c +++ b/drivers/usb/cdns3/gadget.c @@ -1659,7 +1659,7 @@ cdns3_endpoint *cdns3_find_available_ep(struct cdns3_device *priv_dev, /* ep name pattern likes epXin or epXout */ char c[2] = {ep->name[2], '\0'}; - num = simple_strtoul(c, NULL, 10); + num = dectoul(c, NULL); priv_ep = ep_to_cdns3_ep(ep); if (cdns3_ep_dir_is_correct(desc, priv_ep)) { diff --git a/drivers/usb/gadget/epautoconf.c b/drivers/usb/gadget/epautoconf.c index 7da334f5d31..01337d6511b 100644 --- a/drivers/usb/gadget/epautoconf.c +++ b/drivers/usb/gadget/epautoconf.c @@ -144,7 +144,7 @@ static int ep_matches( /* report address */ if (isdigit(ep->name[2])) { - u8 num = simple_strtoul(&ep->name[2], NULL, 10); + u8 num = dectoul(&ep->name[2], NULL); desc->bEndpointAddress |= num; #ifdef MANY_ENDPOINTS } else if (desc->bEndpointAddress & USB_DIR_IN) { diff --git a/drivers/usb/gadget/ether.c b/drivers/usb/gadget/ether.c index 16922ff15c6..43073286572 100644 --- a/drivers/usb/gadget/ether.c +++ b/drivers/usb/gadget/ether.c @@ -2401,8 +2401,7 @@ static int _usb_eth_init(struct ether_priv *priv) usb_gadget_connect(gadget); if (env_get("cdc_connect_timeout")) - timeout = simple_strtoul(env_get("cdc_connect_timeout"), - NULL, 10) * CONFIG_SYS_HZ; + timeout = dectoul(env_get("cdc_connect_timeout"), NULL) * CONFIG_SYS_HZ; ts = get_timer(0); while (!dev->network_started) { /* Handle control-c and timeouts */ diff --git a/drivers/usb/host/ohci-hcd.c b/drivers/usb/host/ohci-hcd.c index c62d8feecce..fedf0db9c7e 100644 --- a/drivers/usb/host/ohci-hcd.c +++ b/drivers/usb/host/ohci-hcd.c @@ -54,7 +54,7 @@ #if defined(CONFIG_CPU_ARM920T) || \ defined(CONFIG_PCI_OHCI) || \ - defined(CONFIG_DM_PCI) || \ + defined(CONFIG_PCI) || \ defined(CONFIG_SYS_OHCI_USE_NPS) # define OHCI_USE_NPS /* force NoPowerSwitching mode */ #endif diff --git a/drivers/video/ati_radeon_fb.c b/drivers/video/ati_radeon_fb.c index c4da2e3ae7f..383666781cc 100644 --- a/drivers/video/ati_radeon_fb.c +++ b/drivers/video/ati_radeon_fb.c @@ -642,7 +642,7 @@ void *video_hw_init(void) if (penv) { /* deceide if it is a string */ if (penv[0] <= '9') { - videomode = (int) simple_strtoul (penv, NULL, 16); + videomode = (int)hextoul(penv, NULL); tmp = 1; } } else { diff --git a/drivers/video/cfb_console.c b/drivers/video/cfb_console.c index 1f491a48d6a..5e1ee061e8e 100644 --- a/drivers/video/cfb_console.c +++ b/drivers/video/cfb_console.c @@ -1857,7 +1857,7 @@ static void *video_logo(void) ret = splash_screen_prepare(); if (ret < 0) return video_fb_address; - addr = simple_strtoul(s, NULL, 16); + addr = hextoul(s, NULL); if (video_display_bitmap(addr, video_logo_xpos, diff --git a/drivers/video/console_truetype.c b/drivers/video/console_truetype.c index fa11b3bbefe..98427f4c618 100644 --- a/drivers/video/console_truetype.c +++ b/drivers/video/console_truetype.c @@ -128,38 +128,36 @@ static int console_truetype_set_row(struct udevice *dev, uint row, int clr) struct video_priv *vid_priv = dev_get_uclass_priv(dev->parent); struct console_tt_priv *priv = dev_get_priv(dev); void *end, *line; - int pixels = priv->font_size * vid_priv->line_length; - int i, ret; + int ret; line = vid_priv->fb + row * priv->font_size * vid_priv->line_length; + end = line + priv->font_size * vid_priv->line_length; + switch (vid_priv->bpix) { #ifdef CONFIG_VIDEO_BPP8 case VIDEO_BPP8: { - uint8_t *dst = line; + u8 *dst; - for (i = 0; i < pixels; i++) - *dst++ = clr; - end = dst; + for (dst = line; dst < (u8 *)end; ++dst) + *dst = clr; break; } #endif #ifdef CONFIG_VIDEO_BPP16 case VIDEO_BPP16: { - uint16_t *dst = line; + u16 *dst = line; - for (i = 0; i < pixels; i++) - *dst++ = clr; - end = dst; + for (dst = line; dst < (u16 *)end; ++dst) + *dst = clr; break; } #endif #ifdef CONFIG_VIDEO_BPP32 case VIDEO_BPP32: { - uint32_t *dst = line; + u32 *dst = line; - for (i = 0; i < pixels; i++) - *dst++ = clr; - end = dst; + for (dst = line; dst < (u32 *)end; ++dst) + *dst = clr; break; } #endif diff --git a/drivers/video/mx3fb.c b/drivers/video/mx3fb.c index 9b42ca8d03f..e6dd2b83c6f 100644 --- a/drivers/video/mx3fb.c +++ b/drivers/video/mx3fb.c @@ -820,7 +820,7 @@ void *video_hw_init(void) if (penv) { /* decide if it is a string */ if (penv[0] <= '9') { - videomode = (int) simple_strtoul(penv, NULL, 16); + videomode = (int)hextoul(penv, NULL); tmp = 1; } } else { diff --git a/drivers/video/vidconsole-uclass.c b/drivers/video/vidconsole-uclass.c index 8f7d987cdd2..8132efa55a3 100644 --- a/drivers/video/vidconsole-uclass.c +++ b/drivers/video/vidconsole-uclass.c @@ -692,8 +692,8 @@ static int do_video_setcursor(struct cmd_tbl *cmdtp, int flag, int argc, if (uclass_first_device_err(UCLASS_VIDEO_CONSOLE, &dev)) return CMD_RET_FAILURE; - col = simple_strtoul(argv[1], NULL, 10); - row = simple_strtoul(argv[2], NULL, 10); + col = dectoul(argv[1], NULL); + row = dectoul(argv[2], NULL); vidconsole_position_cursor(dev, col, row); return 0; |