Commit 8a3c60cd authored by Carl-Daniel Hailfinger's avatar Carl-Daniel Hailfinger
Browse files

Add struct flashctx * parameter to all functions accessing flash chips


All programmer access function prototypes except init have been made
static and moved to the respective file.

A few internal functions in flash chip drivers had chipaddr parameters
which are no longer needed.

The lines touched by flashctx changes have been adjusted to 80 columns
except in header files.

Corresponding to flashrom svn r1474.
Signed-off-by: default avatarCarl-Daniel Hailfinger <c-d.hailfinger.devel.2006@gmx.net>
Acked-by: default avatarMichael Karcher <flashrom@mkarcher.dialup.fu-berlin.de>
No related merge requests found
...@@ -28,24 +28,25 @@ ...@@ -28,24 +28,25 @@
functions. */ functions. */
/* chunksize is 1 */ /* chunksize is 1 */
int write_m29f400bt(struct flashctx *flash, uint8_t *src, unsigned int start, unsigned int len) int write_m29f400bt(struct flashctx *flash, uint8_t *src, unsigned int start,
unsigned int len)
{ {
int i; int i;
chipaddr bios = flash->virtual_memory; chipaddr bios = flash->virtual_memory;
chipaddr dst = flash->virtual_memory + start; chipaddr dst = flash->virtual_memory + start;
for (i = 0; i < len; i++) { for (i = 0; i < len; i++) {
chip_writeb(0xAA, bios + 0xAAA); chip_writeb(flash, 0xAA, bios + 0xAAA);
chip_writeb(0x55, bios + 0x555); chip_writeb(flash, 0x55, bios + 0x555);
chip_writeb(0xA0, bios + 0xAAA); chip_writeb(flash, 0xA0, bios + 0xAAA);
/* transfer data from source to destination */ /* transfer data from source to destination */
chip_writeb(*src, dst); chip_writeb(flash, *src, dst);
toggle_ready_jedec(dst); toggle_ready_jedec(flash, dst);
#if 0 #if 0
/* We only want to print something in the error case. */ /* We only want to print something in the error case. */
msg_cerr("Value in the flash at address 0x%lx = %#x, want %#x\n", msg_cerr("Value in the flash at address 0x%lx = %#x, want %#x\n",
(dst - bios), chip_readb(dst), *src); (dst - bios), chip_readb(flash, dst), *src);
#endif #endif
dst++; dst++;
src++; src++;
...@@ -60,21 +61,21 @@ int probe_m29f400bt(struct flashctx *flash) ...@@ -60,21 +61,21 @@ int probe_m29f400bt(struct flashctx *flash)
chipaddr bios = flash->virtual_memory; chipaddr bios = flash->virtual_memory;
uint8_t id1, id2; uint8_t id1, id2;
chip_writeb(0xAA, bios + 0xAAA); chip_writeb(flash, 0xAA, bios + 0xAAA);
chip_writeb(0x55, bios + 0x555); chip_writeb(flash, 0x55, bios + 0x555);
chip_writeb(0x90, bios + 0xAAA); chip_writeb(flash, 0x90, bios + 0xAAA);
programmer_delay(10); programmer_delay(10);
id1 = chip_readb(bios); id1 = chip_readb(flash, bios);
/* The data sheet says id2 is at (bios + 0x01) and id2 listed in /* The data sheet says id2 is at (bios + 0x01) and id2 listed in
* flash.h does not match. It should be possible to use JEDEC probe. * flash.h does not match. It should be possible to use JEDEC probe.
*/ */
id2 = chip_readb(bios + 0x02); id2 = chip_readb(flash, bios + 0x02);
chip_writeb(0xAA, bios + 0xAAA); chip_writeb(flash, 0xAA, bios + 0xAAA);
chip_writeb(0x55, bios + 0x555); chip_writeb(flash, 0x55, bios + 0x555);
chip_writeb(0xF0, bios + 0xAAA); chip_writeb(flash, 0xF0, bios + 0xAAA);
programmer_delay(10); programmer_delay(10);
...@@ -90,42 +91,44 @@ int erase_m29f400bt(struct flashctx *flash) ...@@ -90,42 +91,44 @@ int erase_m29f400bt(struct flashctx *flash)
{ {
chipaddr bios = flash->virtual_memory; chipaddr bios = flash->virtual_memory;
chip_writeb(0xAA, bios + 0xAAA); chip_writeb(flash, 0xAA, bios + 0xAAA);
chip_writeb(0x55, bios + 0x555); chip_writeb(flash, 0x55, bios + 0x555);
chip_writeb(0x80, bios + 0xAAA); chip_writeb(flash, 0x80, bios + 0xAAA);
chip_writeb(0xAA, bios + 0xAAA); chip_writeb(flash, 0xAA, bios + 0xAAA);
chip_writeb(0x55, bios + 0x555); chip_writeb(flash, 0x55, bios + 0x555);
chip_writeb(0x10, bios + 0xAAA); chip_writeb(flash, 0x10, bios + 0xAAA);
programmer_delay(10); programmer_delay(10);
toggle_ready_jedec(bios); toggle_ready_jedec(flash, bios);
/* FIXME: Check the status register for errors. */ /* FIXME: Check the status register for errors. */
return 0; return 0;
} }
int block_erase_m29f400bt(struct flashctx *flash, unsigned int start, unsigned int len) int block_erase_m29f400bt(struct flashctx *flash, unsigned int start,
unsigned int len)
{ {
chipaddr bios = flash->virtual_memory; chipaddr bios = flash->virtual_memory;
chipaddr dst = bios + start; chipaddr dst = bios + start;
chip_writeb(0xAA, bios + 0xAAA); chip_writeb(flash, 0xAA, bios + 0xAAA);
chip_writeb(0x55, bios + 0x555); chip_writeb(flash, 0x55, bios + 0x555);
chip_writeb(0x80, bios + 0xAAA); chip_writeb(flash, 0x80, bios + 0xAAA);
chip_writeb(0xAA, bios + 0xAAA); chip_writeb(flash, 0xAA, bios + 0xAAA);
chip_writeb(0x55, bios + 0x555); chip_writeb(flash, 0x55, bios + 0x555);
chip_writeb(0x30, dst); chip_writeb(flash, 0x30, dst);
programmer_delay(10); programmer_delay(10);
toggle_ready_jedec(bios); toggle_ready_jedec(flash, bios);
/* FIXME: Check the status register for errors. */ /* FIXME: Check the status register for errors. */
return 0; return 0;
} }
int block_erase_chip_m29f400bt(struct flashctx *flash, unsigned int address, unsigned int blocklen) int block_erase_chip_m29f400bt(struct flashctx *flash, unsigned int address,
unsigned int blocklen)
{ {
if ((address != 0) || (blocklen != flash->total_size * 1024)) { if ((address != 0) || (blocklen != flash->total_size * 1024)) {
msg_cerr("%s called with incorrect arguments\n", msg_cerr("%s called with incorrect arguments\n",
......
...@@ -55,6 +55,10 @@ const struct pcidev_status nics_3com[] = { ...@@ -55,6 +55,10 @@ const struct pcidev_status nics_3com[] = {
{}, {},
}; };
static void nic3com_chip_writeb(const struct flashctx *flash, uint8_t val,
chipaddr addr);
static uint8_t nic3com_chip_readb(const struct flashctx *flash,
const chipaddr addr);
static const struct par_programmer par_programmer_nic3com = { static const struct par_programmer par_programmer_nic3com = {
.chip_readb = nic3com_chip_readb, .chip_readb = nic3com_chip_readb,
.chip_readw = fallback_chip_readw, .chip_readw = fallback_chip_readw,
...@@ -116,13 +120,15 @@ int nic3com_init(void) ...@@ -116,13 +120,15 @@ int nic3com_init(void)
return 0; return 0;
} }
void nic3com_chip_writeb(uint8_t val, chipaddr addr) static void nic3com_chip_writeb(const struct flashctx *flash, uint8_t val,
chipaddr addr)
{ {
OUTL((uint32_t)addr, io_base_addr + BIOS_ROM_ADDR); OUTL((uint32_t)addr, io_base_addr + BIOS_ROM_ADDR);
OUTB(val, io_base_addr + BIOS_ROM_DATA); OUTB(val, io_base_addr + BIOS_ROM_DATA);
} }
uint8_t nic3com_chip_readb(const chipaddr addr) static uint8_t nic3com_chip_readb(const struct flashctx *flash,
const chipaddr addr)
{ {
OUTL((uint32_t)addr, io_base_addr + BIOS_ROM_ADDR); OUTL((uint32_t)addr, io_base_addr + BIOS_ROM_ADDR);
return INB(io_base_addr + BIOS_ROM_DATA); return INB(io_base_addr + BIOS_ROM_DATA);
......
...@@ -43,6 +43,10 @@ const struct pcidev_status nics_intel[] = { ...@@ -43,6 +43,10 @@ const struct pcidev_status nics_intel[] = {
#define CSR_FCR 0x0c #define CSR_FCR 0x0c
static void nicintel_chip_writeb(const struct flashctx *flash, uint8_t val,
chipaddr addr);
static uint8_t nicintel_chip_readb(const struct flashctx *flash,
const chipaddr addr);
static const struct par_programmer par_programmer_nicintel = { static const struct par_programmer par_programmer_nicintel = {
.chip_readb = nicintel_chip_readb, .chip_readb = nicintel_chip_readb,
.chip_readw = fallback_chip_readw, .chip_readw = fallback_chip_readw,
...@@ -117,12 +121,14 @@ error_out: ...@@ -117,12 +121,14 @@ error_out:
return 1; return 1;
} }
void nicintel_chip_writeb(uint8_t val, chipaddr addr) static void nicintel_chip_writeb(const struct flashctx *flash, uint8_t val,
chipaddr addr)
{ {
pci_mmio_writeb(val, nicintel_bar + (addr & NICINTEL_MEMMAP_MASK)); pci_mmio_writeb(val, nicintel_bar + (addr & NICINTEL_MEMMAP_MASK));
} }
uint8_t nicintel_chip_readb(const chipaddr addr) static uint8_t nicintel_chip_readb(const struct flashctx *flash,
const chipaddr addr)
{ {
return pci_mmio_readb(nicintel_bar + (addr & NICINTEL_MEMMAP_MASK)); return pci_mmio_readb(nicintel_bar + (addr & NICINTEL_MEMMAP_MASK));
} }
...@@ -35,6 +35,10 @@ const struct pcidev_status nics_natsemi[] = { ...@@ -35,6 +35,10 @@ const struct pcidev_status nics_natsemi[] = {
{}, {},
}; };
static void nicnatsemi_chip_writeb(const struct flashctx *flash, uint8_t val,
chipaddr addr);
static uint8_t nicnatsemi_chip_readb(const struct flashctx *flash,
const chipaddr addr);
static const struct par_programmer par_programmer_nicnatsemi = { static const struct par_programmer par_programmer_nicnatsemi = {
.chip_readb = nicnatsemi_chip_readb, .chip_readb = nicnatsemi_chip_readb,
.chip_readw = fallback_chip_readw, .chip_readw = fallback_chip_readw,
...@@ -74,7 +78,8 @@ int nicnatsemi_init(void) ...@@ -74,7 +78,8 @@ int nicnatsemi_init(void)
return 0; return 0;
} }
void nicnatsemi_chip_writeb(uint8_t val, chipaddr addr) static void nicnatsemi_chip_writeb(const struct flashctx *flash, uint8_t val,
chipaddr addr)
{ {
OUTL((uint32_t)addr & 0x0001FFFF, io_base_addr + BOOT_ROM_ADDR); OUTL((uint32_t)addr & 0x0001FFFF, io_base_addr + BOOT_ROM_ADDR);
/* /*
...@@ -88,7 +93,8 @@ void nicnatsemi_chip_writeb(uint8_t val, chipaddr addr) ...@@ -88,7 +93,8 @@ void nicnatsemi_chip_writeb(uint8_t val, chipaddr addr)
OUTB(val, io_base_addr + BOOT_ROM_DATA); OUTB(val, io_base_addr + BOOT_ROM_DATA);
} }
uint8_t nicnatsemi_chip_readb(const chipaddr addr) static uint8_t nicnatsemi_chip_readb(const struct flashctx *flash,
const chipaddr addr)
{ {
OUTL(((uint32_t)addr & 0x0001FFFF), io_base_addr + BOOT_ROM_ADDR); OUTL(((uint32_t)addr & 0x0001FFFF), io_base_addr + BOOT_ROM_ADDR);
/* /*
......
...@@ -36,6 +36,10 @@ const struct pcidev_status nics_realtek[] = { ...@@ -36,6 +36,10 @@ const struct pcidev_status nics_realtek[] = {
{}, {},
}; };
static void nicrealtek_chip_writeb(const struct flashctx *flash, uint8_t val,
chipaddr addr);
static uint8_t nicrealtek_chip_readb(const struct flashctx *flash,
const chipaddr addr);
static const struct par_programmer par_programmer_nicrealtek = { static const struct par_programmer par_programmer_nicrealtek = {
.chip_readb = nicrealtek_chip_readb, .chip_readb = nicrealtek_chip_readb,
.chip_readw = fallback_chip_readw, .chip_readw = fallback_chip_readw,
...@@ -69,7 +73,8 @@ int nicrealtek_init(void) ...@@ -69,7 +73,8 @@ int nicrealtek_init(void)
return 0; return 0;
} }
void nicrealtek_chip_writeb(uint8_t val, chipaddr addr) static void nicrealtek_chip_writeb(const struct flashctx *flash, uint8_t val,
chipaddr addr)
{ {
/* Output addr and data, set WE to 0, set OE to 1, set CS to 0, /* Output addr and data, set WE to 0, set OE to 1, set CS to 0,
* enable software access. * enable software access.
...@@ -83,7 +88,8 @@ void nicrealtek_chip_writeb(uint8_t val, chipaddr addr) ...@@ -83,7 +88,8 @@ void nicrealtek_chip_writeb(uint8_t val, chipaddr addr)
io_base_addr + BIOS_ROM_ADDR); io_base_addr + BIOS_ROM_ADDR);
} }
uint8_t nicrealtek_chip_readb(const chipaddr addr) static uint8_t nicrealtek_chip_readb(const struct flashctx *flash,
const chipaddr addr)
{ {
uint8_t val; uint8_t val;
......
...@@ -22,28 +22,32 @@ ...@@ -22,28 +22,32 @@
#include "flash.h" #include "flash.h"
static void write_lockbits_49fl00x(chipaddr bios, unsigned int size, static void write_lockbits_49fl00x(const struct flashctx *flash,
unsigned char bits, unsigned int block_size) unsigned int size, unsigned char bits,
unsigned int block_size)
{ {
unsigned int i, left = size; unsigned int i, left = size;
chipaddr bios = flash->virtual_registers;
for (i = 0; left >= block_size; i++, left -= block_size) { for (i = 0; left >= block_size; i++, left -= block_size) {
/* pm49fl002 */ /* pm49fl002 */
if (block_size == 16384 && i % 2) if (block_size == 16384 && i % 2)
continue; continue;
chip_writeb(bits, bios + (i * block_size) + 2); chip_writeb(flash, bits, bios + (i * block_size) + 2);
} }
} }
int unlock_49fl00x(struct flashctx *flash) int unlock_49fl00x(struct flashctx *flash)
{ {
write_lockbits_49fl00x(flash->virtual_registers, flash->total_size * 1024, 0, flash->page_size); write_lockbits_49fl00x(flash, flash->total_size * 1024, 0,
flash->page_size);
return 0; return 0;
} }
int lock_49fl00x(struct flashctx *flash) int lock_49fl00x(struct flashctx *flash)
{ {
write_lockbits_49fl00x(flash->virtual_registers, flash->total_size * 1024, 1, flash->page_size); write_lockbits_49fl00x(flash, flash->total_size * 1024, 1,
flash->page_size);
return 0; return 0;
} }
/* /*
* This file is part of the flashrom project. * This file is part of the flashrom project.
* *
* Copyright (C) 2009,2010 Carl-Daniel Hailfinger * Copyright (C) 2009,2010,2011 Carl-Daniel Hailfinger
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
...@@ -53,61 +53,65 @@ void fallback_unmap(void *virt_addr, size_t len) ...@@ -53,61 +53,65 @@ void fallback_unmap(void *virt_addr, size_t len)
} }
/* No-op chip_writeb() for drivers not supporting addr/data pair accesses */ /* No-op chip_writeb() for drivers not supporting addr/data pair accesses */
uint8_t noop_chip_readb(const chipaddr addr) uint8_t noop_chip_readb(const struct flashctx *flash, const chipaddr addr)
{ {
return 0xff; return 0xff;
} }
/* No-op chip_writeb() for drivers not supporting addr/data pair accesses */ /* No-op chip_writeb() for drivers not supporting addr/data pair accesses */
void noop_chip_writeb(uint8_t val, chipaddr addr) void noop_chip_writeb(const struct flashctx *flash, uint8_t val, chipaddr addr)
{ {
} }
/* Little-endian fallback for drivers not supporting 16 bit accesses */ /* Little-endian fallback for drivers not supporting 16 bit accesses */
void fallback_chip_writew(uint16_t val, chipaddr addr) void fallback_chip_writew(const struct flashctx *flash, uint16_t val,
chipaddr addr)
{ {
chip_writeb(val & 0xff, addr); chip_writeb(flash, val & 0xff, addr);
chip_writeb((val >> 8) & 0xff, addr + 1); chip_writeb(flash, (val >> 8) & 0xff, addr + 1);
} }
/* Little-endian fallback for drivers not supporting 16 bit accesses */ /* Little-endian fallback for drivers not supporting 16 bit accesses */
uint16_t fallback_chip_readw(const chipaddr addr) uint16_t fallback_chip_readw(const struct flashctx *flash, const chipaddr addr)
{ {
uint16_t val; uint16_t val;
val = chip_readb(addr); val = chip_readb(flash, addr);
val |= chip_readb(addr + 1) << 8; val |= chip_readb(flash, addr + 1) << 8;
return val; return val;
} }
/* Little-endian fallback for drivers not supporting 32 bit accesses */ /* Little-endian fallback for drivers not supporting 32 bit accesses */
void fallback_chip_writel(uint32_t val, chipaddr addr) void fallback_chip_writel(const struct flashctx *flash, uint32_t val,
chipaddr addr)
{ {
chip_writew(val & 0xffff, addr); chip_writew(flash, val & 0xffff, addr);
chip_writew((val >> 16) & 0xffff, addr + 2); chip_writew(flash, (val >> 16) & 0xffff, addr + 2);
} }
/* Little-endian fallback for drivers not supporting 32 bit accesses */ /* Little-endian fallback for drivers not supporting 32 bit accesses */
uint32_t fallback_chip_readl(const chipaddr addr) uint32_t fallback_chip_readl(const struct flashctx *flash, const chipaddr addr)
{ {
uint32_t val; uint32_t val;
val = chip_readw(addr); val = chip_readw(flash, addr);
val |= chip_readw(addr + 2) << 16; val |= chip_readw(flash, addr + 2) << 16;
return val; return val;
} }
void fallback_chip_writen(uint8_t *buf, chipaddr addr, size_t len) void fallback_chip_writen(const struct flashctx *flash, uint8_t *buf,
chipaddr addr, size_t len)
{ {
size_t i; size_t i;
for (i = 0; i < len; i++) for (i = 0; i < len; i++)
chip_writeb(buf[i], addr + i); chip_writeb(flash, buf[i], addr + i);
return; return;
} }
void fallback_chip_readn(uint8_t *buf, chipaddr addr, size_t len) void fallback_chip_readn(const struct flashctx *flash, uint8_t *buf,
chipaddr addr, size_t len)
{ {
size_t i; size_t i;
for (i = 0; i < len; i++) for (i = 0; i < len; i++)
buf[i] = chip_readb(addr + i); buf[i] = chip_readb(flash, addr + i);
return; return;
} }
......
...@@ -93,8 +93,8 @@ struct programmer_entry { ...@@ -93,8 +93,8 @@ struct programmer_entry {
int (*init) (void); int (*init) (void);
void * (*map_flash_region) (const char *descr, unsigned long phys_addr, void *(*map_flash_region) (const char *descr, unsigned long phys_addr,
size_t len); size_t len);
void (*unmap_flash_region) (void *virt_addr, size_t len); void (*unmap_flash_region) (void *virt_addr, size_t len);
void (*delay) (int usecs); void (*delay) (int usecs);
...@@ -300,13 +300,6 @@ void probe_superio(void); ...@@ -300,13 +300,6 @@ void probe_superio(void);
int register_superio(struct superio s); int register_superio(struct superio s);
extern enum chipbustype internal_buses_supported; extern enum chipbustype internal_buses_supported;
int internal_init(void); int internal_init(void);
void internal_chip_writeb(uint8_t val, chipaddr addr);
void internal_chip_writew(uint16_t val, chipaddr addr);
void internal_chip_writel(uint32_t val, chipaddr addr);
uint8_t internal_chip_readb(const chipaddr addr);
uint16_t internal_chip_readw(const chipaddr addr);
uint32_t internal_chip_readl(const chipaddr addr);
void internal_chip_readn(uint8_t *buf, const chipaddr addr, size_t len);
#endif #endif
/* hwaccess.c */ /* hwaccess.c */
...@@ -341,91 +334,46 @@ void rmmio_valb(void *addr); ...@@ -341,91 +334,46 @@ void rmmio_valb(void *addr);
void rmmio_valw(void *addr); void rmmio_valw(void *addr);
void rmmio_vall(void *addr); void rmmio_vall(void *addr);
/* programmer.c */
int noop_shutdown(void);
void *fallback_map(const char *descr, unsigned long phys_addr, size_t len);
void fallback_unmap(void *virt_addr, size_t len);
uint8_t noop_chip_readb(const chipaddr addr);
void noop_chip_writeb(uint8_t val, chipaddr addr);
void fallback_chip_writew(uint16_t val, chipaddr addr);
void fallback_chip_writel(uint32_t val, chipaddr addr);
void fallback_chip_writen(uint8_t *buf, chipaddr addr, size_t len);
uint16_t fallback_chip_readw(const chipaddr addr);
uint32_t fallback_chip_readl(const chipaddr addr);
void fallback_chip_readn(uint8_t *buf, const chipaddr addr, size_t len);
struct par_programmer {
void (*chip_writeb) (uint8_t val, chipaddr addr);
void (*chip_writew) (uint16_t val, chipaddr addr);
void (*chip_writel) (uint32_t val, chipaddr addr);
void (*chip_writen) (uint8_t *buf, chipaddr addr, size_t len);
uint8_t (*chip_readb) (const chipaddr addr);
uint16_t (*chip_readw) (const chipaddr addr);
uint32_t (*chip_readl) (const chipaddr addr);
void (*chip_readn) (uint8_t *buf, const chipaddr addr, size_t len);
};
extern const struct par_programmer *par_programmer;
void register_par_programmer(const struct par_programmer *pgm, const enum chipbustype buses);
/* dummyflasher.c */ /* dummyflasher.c */
#if CONFIG_DUMMY == 1 #if CONFIG_DUMMY == 1
int dummy_init(void); int dummy_init(void);
void *dummy_map(const char *descr, unsigned long phys_addr, size_t len); void *dummy_map(const char *descr, unsigned long phys_addr, size_t len);
void dummy_unmap(void *virt_addr, size_t len); void dummy_unmap(void *virt_addr, size_t len);
void dummy_chip_writeb(uint8_t val, chipaddr addr);
void dummy_chip_writew(uint16_t val, chipaddr addr);
void dummy_chip_writel(uint32_t val, chipaddr addr);
void dummy_chip_writen(uint8_t *buf, chipaddr addr, size_t len);
uint8_t dummy_chip_readb(const chipaddr addr);
uint16_t dummy_chip_readw(const chipaddr addr);
uint32_t dummy_chip_readl(const chipaddr addr);
void dummy_chip_readn(uint8_t *buf, const chipaddr addr, size_t len);
#endif #endif
/* nic3com.c */ /* nic3com.c */
#if CONFIG_NIC3COM == 1 #if CONFIG_NIC3COM == 1
int nic3com_init(void); int nic3com_init(void);
void nic3com_chip_writeb(uint8_t val, chipaddr addr);
uint8_t nic3com_chip_readb(const chipaddr addr);
extern const struct pcidev_status nics_3com[]; extern const struct pcidev_status nics_3com[];
#endif #endif
/* gfxnvidia.c */ /* gfxnvidia.c */
#if CONFIG_GFXNVIDIA == 1 #if CONFIG_GFXNVIDIA == 1
int gfxnvidia_init(void); int gfxnvidia_init(void);
void gfxnvidia_chip_writeb(uint8_t val, chipaddr addr);
uint8_t gfxnvidia_chip_readb(const chipaddr addr);
extern const struct pcidev_status gfx_nvidia[]; extern const struct pcidev_status gfx_nvidia[];
#endif #endif
/* drkaiser.c */ /* drkaiser.c */
#if CONFIG_DRKAISER == 1 #if CONFIG_DRKAISER == 1
int drkaiser_init(void); int drkaiser_init(void);
void drkaiser_chip_writeb(uint8_t val, chipaddr addr);
uint8_t drkaiser_chip_readb(const chipaddr addr);
extern const struct pcidev_status drkaiser_pcidev[]; extern const struct pcidev_status drkaiser_pcidev[];
#endif #endif
/* nicrealtek.c */ /* nicrealtek.c */
#if CONFIG_NICREALTEK == 1 #if CONFIG_NICREALTEK == 1
int nicrealtek_init(void); int nicrealtek_init(void);
void nicrealtek_chip_writeb(uint8_t val, chipaddr addr);
uint8_t nicrealtek_chip_readb(const chipaddr addr);
extern const struct pcidev_status nics_realtek[]; extern const struct pcidev_status nics_realtek[];
#endif #endif
/* nicnatsemi.c */ /* nicnatsemi.c */
#if CONFIG_NICNATSEMI == 1 #if CONFIG_NICNATSEMI == 1
int nicnatsemi_init(void); int nicnatsemi_init(void);
void nicnatsemi_chip_writeb(uint8_t val, chipaddr addr);
uint8_t nicnatsemi_chip_readb(const chipaddr addr);
extern const struct pcidev_status nics_natsemi[]; extern const struct pcidev_status nics_natsemi[];
#endif #endif
/* nicintel.c */ /* nicintel.c */
#if CONFIG_NICINTEL == 1 #if CONFIG_NICINTEL == 1
int nicintel_init(void); int nicintel_init(void);
void nicintel_chip_writeb(uint8_t val, chipaddr addr);
uint8_t nicintel_chip_readb(const chipaddr addr);
extern const struct pcidev_status nics_intel[]; extern const struct pcidev_status nics_intel[];
#endif #endif
...@@ -444,24 +392,18 @@ extern const struct pcidev_status ogp_spi[]; ...@@ -444,24 +392,18 @@ extern const struct pcidev_status ogp_spi[];
/* satamv.c */ /* satamv.c */
#if CONFIG_SATAMV == 1 #if CONFIG_SATAMV == 1
int satamv_init(void); int satamv_init(void);
void satamv_chip_writeb(uint8_t val, chipaddr addr);
uint8_t satamv_chip_readb(const chipaddr addr);
extern const struct pcidev_status satas_mv[]; extern const struct pcidev_status satas_mv[];
#endif #endif
/* satasii.c */ /* satasii.c */
#if CONFIG_SATASII == 1 #if CONFIG_SATASII == 1
int satasii_init(void); int satasii_init(void);
void satasii_chip_writeb(uint8_t val, chipaddr addr);
uint8_t satasii_chip_readb(const chipaddr addr);
extern const struct pcidev_status satas_sii[]; extern const struct pcidev_status satas_sii[];
#endif #endif
/* atahpt.c */ /* atahpt.c */
#if CONFIG_ATAHPT == 1 #if CONFIG_ATAHPT == 1
int atahpt_init(void); int atahpt_init(void);
void atahpt_chip_writeb(uint8_t val, chipaddr addr);
uint8_t atahpt_chip_readb(const chipaddr addr);
extern const struct pcidev_status ata_hpt[]; extern const struct pcidev_status ata_hpt[];
#endif #endif
...@@ -565,9 +507,9 @@ struct spi_programmer { ...@@ -565,9 +507,9 @@ struct spi_programmer {
enum spi_controller type; enum spi_controller type;
unsigned int max_data_read; unsigned int max_data_read;
unsigned int max_data_write; unsigned int max_data_write;
int (*command)(unsigned int writecnt, unsigned int readcnt, int (*command)(struct flashctx *flash, unsigned int writecnt, unsigned int readcnt,
const unsigned char *writearr, unsigned char *readarr); const unsigned char *writearr, unsigned char *readarr);
int (*multicommand)(struct spi_command *cmds); int (*multicommand)(struct flashctx *flash, struct spi_command *cmds);
/* Optimized functions for this programmer */ /* Optimized functions for this programmer */
int (*read)(struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len); int (*read)(struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len);
...@@ -575,9 +517,9 @@ struct spi_programmer { ...@@ -575,9 +517,9 @@ struct spi_programmer {
}; };
extern const struct spi_programmer *spi_programmer; extern const struct spi_programmer *spi_programmer;
int default_spi_send_command(unsigned int writecnt, unsigned int readcnt, int default_spi_send_command(struct flashctx *flash, unsigned int writecnt, unsigned int readcnt,
const unsigned char *writearr, unsigned char *readarr); const unsigned char *writearr, unsigned char *readarr);
int default_spi_send_multicommand(struct spi_command *cmds); int default_spi_send_multicommand(struct flashctx *flash, struct spi_command *cmds);
int default_spi_read(struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len); int default_spi_read(struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len);
int default_spi_write_256(struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len); int default_spi_write_256(struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len);
void register_spi_programmer(const struct spi_programmer *programmer); void register_spi_programmer(const struct spi_programmer *programmer);
...@@ -632,12 +574,34 @@ struct opaque_programmer { ...@@ -632,12 +574,34 @@ struct opaque_programmer {
extern const struct opaque_programmer *opaque_programmer; extern const struct opaque_programmer *opaque_programmer;
void register_opaque_programmer(const struct opaque_programmer *pgm); void register_opaque_programmer(const struct opaque_programmer *pgm);
/* programmer.c */
int noop_shutdown(void);
void *fallback_map(const char *descr, unsigned long phys_addr, size_t len);
void fallback_unmap(void *virt_addr, size_t len);
uint8_t noop_chip_readb(const struct flashctx *flash, const chipaddr addr);
void noop_chip_writeb(const struct flashctx *flash, uint8_t val, chipaddr addr);
void fallback_chip_writew(const struct flashctx *flash, uint16_t val, chipaddr addr);
void fallback_chip_writel(const struct flashctx *flash, uint32_t val, chipaddr addr);
void fallback_chip_writen(const struct flashctx *flash, uint8_t *buf, chipaddr addr, size_t len);
uint16_t fallback_chip_readw(const struct flashctx *flash, const chipaddr addr);
uint32_t fallback_chip_readl(const struct flashctx *flash, const chipaddr addr);
void fallback_chip_readn(const struct flashctx *flash, uint8_t *buf, const chipaddr addr, size_t len);
struct par_programmer {
void (*chip_writeb) (const struct flashctx *flash, uint8_t val, chipaddr addr);
void (*chip_writew) (const struct flashctx *flash, uint16_t val, chipaddr addr);
void (*chip_writel) (const struct flashctx *flash, uint32_t val, chipaddr addr);
void (*chip_writen) (const struct flashctx *flash, uint8_t *buf, chipaddr addr, size_t len);
uint8_t (*chip_readb) (const struct flashctx *flash, const chipaddr addr);
uint16_t (*chip_readw) (const struct flashctx *flash, const chipaddr addr);
uint32_t (*chip_readl) (const struct flashctx *flash, const chipaddr addr);
void (*chip_readn) (const struct flashctx *flash, uint8_t *buf, const chipaddr addr, size_t len);
};
extern const struct par_programmer *par_programmer;
void register_par_programmer(const struct par_programmer *pgm, const enum chipbustype buses);
/* serprog.c */ /* serprog.c */
#if CONFIG_SERPROG == 1 #if CONFIG_SERPROG == 1
int serprog_init(void); int serprog_init(void);
void serprog_chip_writeb(uint8_t val, chipaddr addr);
uint8_t serprog_chip_readb(const chipaddr addr);
void serprog_chip_readn(uint8_t *buf, const chipaddr addr, size_t len);
void serprog_delay(int usecs); void serprog_delay(int usecs);
#endif #endif
......
...@@ -41,6 +41,10 @@ const struct pcidev_status satas_mv[] = { ...@@ -41,6 +41,10 @@ const struct pcidev_status satas_mv[] = {
#define PCI_BAR2_CONTROL 0x00c08 #define PCI_BAR2_CONTROL 0x00c08
#define GPIO_PORT_CONTROL 0x104f0 #define GPIO_PORT_CONTROL 0x104f0
static void satamv_chip_writeb(const struct flashctx *flash, uint8_t val,
chipaddr addr);
static uint8_t satamv_chip_readb(const struct flashctx *flash,
const chipaddr addr);
static const struct par_programmer par_programmer_satamv = { static const struct par_programmer par_programmer_satamv = {
.chip_readb = satamv_chip_readb, .chip_readb = satamv_chip_readb,
.chip_readw = fallback_chip_readw, .chip_readw = fallback_chip_readw,
...@@ -183,13 +187,15 @@ static uint8_t satamv_indirect_chip_readb(const chipaddr addr) ...@@ -183,13 +187,15 @@ static uint8_t satamv_indirect_chip_readb(const chipaddr addr)
} }
/* FIXME: Prefer direct access to BAR2 if BAR2 is active. */ /* FIXME: Prefer direct access to BAR2 if BAR2 is active. */
void satamv_chip_writeb(uint8_t val, chipaddr addr) static void satamv_chip_writeb(const struct flashctx *flash, uint8_t val,
chipaddr addr)
{ {
satamv_indirect_chip_writeb(val, addr); satamv_indirect_chip_writeb(val, addr);
} }
/* FIXME: Prefer direct access to BAR2 if BAR2 is active. */ /* FIXME: Prefer direct access to BAR2 if BAR2 is active. */
uint8_t satamv_chip_readb(const chipaddr addr) static uint8_t satamv_chip_readb(const struct flashctx *flash,
const chipaddr addr)
{ {
return satamv_indirect_chip_readb(addr); return satamv_indirect_chip_readb(addr);
} }
......
...@@ -42,6 +42,10 @@ const struct pcidev_status satas_sii[] = { ...@@ -42,6 +42,10 @@ const struct pcidev_status satas_sii[] = {
{}, {},
}; };
static void satasii_chip_writeb(const struct flashctx *flash, uint8_t val,
chipaddr addr);
static uint8_t satasii_chip_readb(const struct flashctx *flash,
const chipaddr addr);
static const struct par_programmer par_programmer_satasii = { static const struct par_programmer par_programmer_satasii = {
.chip_readb = satasii_chip_readb, .chip_readb = satasii_chip_readb,
.chip_readw = fallback_chip_readw, .chip_readw = fallback_chip_readw,
...@@ -95,7 +99,8 @@ int satasii_init(void) ...@@ -95,7 +99,8 @@ int satasii_init(void)
return 0; return 0;
} }
void satasii_chip_writeb(uint8_t val, chipaddr addr) static void satasii_chip_writeb(const struct flashctx *flash, uint8_t val,
chipaddr addr)
{ {
uint32_t ctrl_reg, data_reg; uint32_t ctrl_reg, data_reg;
...@@ -112,7 +117,8 @@ void satasii_chip_writeb(uint8_t val, chipaddr addr) ...@@ -112,7 +117,8 @@ void satasii_chip_writeb(uint8_t val, chipaddr addr)
while (pci_mmio_readl(sii_bar) & (1 << 25)) ; while (pci_mmio_readl(sii_bar) & (1 << 25)) ;
} }
uint8_t satasii_chip_readb(const chipaddr addr) static uint8_t satasii_chip_readb(const struct flashctx *flash,
const chipaddr addr)
{ {
uint32_t ctrl_reg; uint32_t ctrl_reg;
......
...@@ -88,8 +88,10 @@ static void execute_command(void) ...@@ -88,8 +88,10 @@ static void execute_command(void)
; ;
} }
static int sb600_spi_send_command(unsigned int writecnt, unsigned int readcnt, static int sb600_spi_send_command(struct flashctx *flash, unsigned int writecnt,
const unsigned char *writearr, unsigned char *readarr) unsigned int readcnt,
const unsigned char *writearr,
unsigned char *readarr)
{ {
int count; int count;
/* First byte is cmd which can not being sent through FIFO. */ /* First byte is cmd which can not being sent through FIFO. */
......
...@@ -299,7 +299,8 @@ static int sp_stream_buffer_op(uint8_t cmd, uint32_t parmlen, uint8_t * parms) ...@@ -299,7 +299,8 @@ static int sp_stream_buffer_op(uint8_t cmd, uint32_t parmlen, uint8_t * parms)
return 0; return 0;
} }
static int serprog_spi_send_command(unsigned int writecnt, unsigned int readcnt, static int serprog_spi_send_command(struct flashctx *flash,
unsigned int writecnt, unsigned int readcnt,
const unsigned char *writearr, const unsigned char *writearr,
unsigned char *readarr); unsigned char *readarr);
static int serprog_spi_read(struct flashctx *flash, uint8_t *buf, static int serprog_spi_read(struct flashctx *flash, uint8_t *buf,
...@@ -314,6 +315,12 @@ static struct spi_programmer spi_programmer_serprog = { ...@@ -314,6 +315,12 @@ static struct spi_programmer spi_programmer_serprog = {
.write_256 = default_spi_write_256, .write_256 = default_spi_write_256,
}; };
static void serprog_chip_writeb(const struct flashctx *flash, uint8_t val,
chipaddr addr);
static uint8_t serprog_chip_readb(const struct flashctx *flash,
const chipaddr addr);
static void serprog_chip_readn(const struct flashctx *flash, uint8_t *buf,
const chipaddr addr, size_t len);
static const struct par_programmer par_programmer_serprog = { static const struct par_programmer par_programmer_serprog = {
.chip_readb = serprog_chip_readb, .chip_readb = serprog_chip_readb,
.chip_readw = fallback_chip_readw, .chip_readw = fallback_chip_readw,
...@@ -680,7 +687,8 @@ static void sp_check_opbuf_usage(int bytes_to_be_added) ...@@ -680,7 +687,8 @@ static void sp_check_opbuf_usage(int bytes_to_be_added)
} }
} }
void serprog_chip_writeb(uint8_t val, chipaddr addr) static void serprog_chip_writeb(const struct flashctx *flash, uint8_t val,
chipaddr addr)
{ {
msg_pspew("%s\n", __func__); msg_pspew("%s\n", __func__);
if (sp_max_write_n) { if (sp_max_write_n) {
...@@ -711,7 +719,8 @@ void serprog_chip_writeb(uint8_t val, chipaddr addr) ...@@ -711,7 +719,8 @@ void serprog_chip_writeb(uint8_t val, chipaddr addr)
} }
} }
uint8_t serprog_chip_readb(const chipaddr addr) static uint8_t serprog_chip_readb(const struct flashctx *flash,
const chipaddr addr)
{ {
unsigned char c; unsigned char c;
unsigned char buf[3]; unsigned char buf[3];
...@@ -757,7 +766,8 @@ static void sp_do_read_n(uint8_t * buf, const chipaddr addr, size_t len) ...@@ -757,7 +766,8 @@ static void sp_do_read_n(uint8_t * buf, const chipaddr addr, size_t len)
} }
/* The externally called version that makes sure that max_read_n is obeyed. */ /* The externally called version that makes sure that max_read_n is obeyed. */
void serprog_chip_readn(uint8_t * buf, const chipaddr addr, size_t len) static void serprog_chip_readn(const struct flashctx *flash, uint8_t * buf,
const chipaddr addr, size_t len)
{ {
size_t lenm = len; size_t lenm = len;
chipaddr addrm = addr; chipaddr addrm = addr;
...@@ -792,9 +802,10 @@ void serprog_delay(int usecs) ...@@ -792,9 +802,10 @@ void serprog_delay(int usecs)
sp_prev_was_write = 0; sp_prev_was_write = 0;
} }
static int serprog_spi_send_command(unsigned int writecnt, unsigned int readcnt, static int serprog_spi_send_command(struct flashctx *flash,
const unsigned char *writearr, unsigned int writecnt, unsigned int readcnt,
unsigned char *readarr) const unsigned char *writearr,
unsigned char *readarr)
{ {
unsigned char *parmbuf; unsigned char *parmbuf;
int ret; int ret;
...@@ -822,14 +833,15 @@ static int serprog_spi_send_command(unsigned int writecnt, unsigned int readcnt, ...@@ -822,14 +833,15 @@ static int serprog_spi_send_command(unsigned int writecnt, unsigned int readcnt,
* the advantage that it is much faster for most chips, but breaks those with * the advantage that it is much faster for most chips, but breaks those with
* non-contiguous address space (like AT45DB161D). When spi_read_chunked is * non-contiguous address space (like AT45DB161D). When spi_read_chunked is
* fixed this method can be removed. */ * fixed this method can be removed. */
static int serprog_spi_read(struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len) static int serprog_spi_read(struct flashctx *flash, uint8_t *buf,
unsigned int start, unsigned int len)
{ {
unsigned int i, cur_len; unsigned int i, cur_len;
const unsigned int max_read = spi_programmer_serprog.max_data_read; const unsigned int max_read = spi_programmer_serprog.max_data_read;
for (i = 0; i < len; i += cur_len) { for (i = 0; i < len; i += cur_len) {
int ret; int ret;
cur_len = min(max_read, (len - i)); cur_len = min(max_read, (len - i));
ret = spi_nbyte_read(start + i, buf + i, cur_len); ret = spi_nbyte_read(flash, start + i, buf + i, cur_len);
if (ret) if (ret)
return ret; return ret;
} }
......
...@@ -26,25 +26,26 @@ ...@@ -26,25 +26,26 @@
* FIXME: This file is unused. * FIXME: This file is unused.
*/ */
int erase_lhf00l04_block(struct flashctx *flash, unsigned int blockaddr, unsigned int blocklen) int erase_lhf00l04_block(struct flashctx *flash, unsigned int blockaddr,
unsigned int blocklen)
{ {
chipaddr bios = flash->virtual_memory + blockaddr; chipaddr bios = flash->virtual_memory + blockaddr;
chipaddr wrprotect = flash->virtual_registers + blockaddr + 2; chipaddr wrprotect = flash->virtual_registers + blockaddr + 2;
uint8_t status; uint8_t status;
// clear status register // clear status register
chip_writeb(0x50, bios); chip_writeb(flash, 0x50, bios);
status = wait_82802ab(flash); status = wait_82802ab(flash);
print_status_82802ab(status); print_status_82802ab(status);
// clear write protect // clear write protect
msg_cspew("write protect is at 0x%lx\n", (wrprotect)); msg_cspew("write protect is at 0x%lx\n", (wrprotect));
msg_cspew("write protect is 0x%x\n", chip_readb(wrprotect)); msg_cspew("write protect is 0x%x\n", chip_readb(flash, wrprotect));
chip_writeb(0, wrprotect); chip_writeb(flash, 0, wrprotect);
msg_cspew("write protect is 0x%x\n", chip_readb(wrprotect)); msg_cspew("write protect is 0x%x\n", chip_readb(flash, wrprotect));
// now start it // now start it
chip_writeb(0x20, bios); chip_writeb(flash, 0x20, bios);
chip_writeb(0xd0, bios); chip_writeb(flash, 0xd0, bios);
programmer_delay(10); programmer_delay(10);
// now let's see what the register is // now let's see what the register is
status = wait_82802ab(flash); status = wait_82802ab(flash);
......
...@@ -42,8 +42,9 @@ const struct spi_programmer spi_programmer_none = { ...@@ -42,8 +42,9 @@ const struct spi_programmer spi_programmer_none = {
const struct spi_programmer *spi_programmer = &spi_programmer_none; const struct spi_programmer *spi_programmer = &spi_programmer_none;
int spi_send_command(unsigned int writecnt, unsigned int readcnt, int spi_send_command(struct flashctx *flash, unsigned int writecnt,
const unsigned char *writearr, unsigned char *readarr) unsigned int readcnt, const unsigned char *writearr,
unsigned char *readarr)
{ {
if (!spi_programmer->command) { if (!spi_programmer->command) {
msg_perr("%s called, but SPI is unsupported on this " msg_perr("%s called, but SPI is unsupported on this "
...@@ -52,11 +53,11 @@ int spi_send_command(unsigned int writecnt, unsigned int readcnt, ...@@ -52,11 +53,11 @@ int spi_send_command(unsigned int writecnt, unsigned int readcnt,
return 1; return 1;
} }
return spi_programmer->command(writecnt, readcnt, return spi_programmer->command(flash, writecnt, readcnt, writearr,
writearr, readarr); readarr);
} }
int spi_send_multicommand(struct spi_command *cmds) int spi_send_multicommand(struct flashctx *flash, struct spi_command *cmds)
{ {
if (!spi_programmer->multicommand) { if (!spi_programmer->multicommand) {
msg_perr("%s called, but SPI is unsupported on this " msg_perr("%s called, but SPI is unsupported on this "
...@@ -65,11 +66,13 @@ int spi_send_multicommand(struct spi_command *cmds) ...@@ -65,11 +66,13 @@ int spi_send_multicommand(struct spi_command *cmds)
return 1; return 1;
} }
return spi_programmer->multicommand(cmds); return spi_programmer->multicommand(flash, cmds);
} }
int default_spi_send_command(unsigned int writecnt, unsigned int readcnt, int default_spi_send_command(struct flashctx *flash, unsigned int writecnt,
const unsigned char *writearr, unsigned char *readarr) unsigned int readcnt,
const unsigned char *writearr,
unsigned char *readarr)
{ {
struct spi_command cmd[] = { struct spi_command cmd[] = {
{ {
...@@ -84,20 +87,22 @@ int default_spi_send_command(unsigned int writecnt, unsigned int readcnt, ...@@ -84,20 +87,22 @@ int default_spi_send_command(unsigned int writecnt, unsigned int readcnt,
.readarr = NULL, .readarr = NULL,
}}; }};
return spi_send_multicommand(cmd); return spi_send_multicommand(flash, cmd);
} }
int default_spi_send_multicommand(struct spi_command *cmds) int default_spi_send_multicommand(struct flashctx *flash,
struct spi_command *cmds)
{ {
int result = 0; int result = 0;
for (; (cmds->writecnt || cmds->readcnt) && !result; cmds++) { for (; (cmds->writecnt || cmds->readcnt) && !result; cmds++) {
result = spi_send_command(cmds->writecnt, cmds->readcnt, result = spi_send_command(flash, cmds->writecnt, cmds->readcnt,
cmds->writearr, cmds->readarr); cmds->writearr, cmds->readarr);
} }
return result; return result;
} }
int default_spi_read(struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len) int default_spi_read(struct flashctx *flash, uint8_t *buf, unsigned int start,
unsigned int len)
{ {
unsigned int max_data = spi_programmer->max_data_read; unsigned int max_data = spi_programmer->max_data_read;
if (max_data == MAX_DATA_UNSPECIFIED) { if (max_data == MAX_DATA_UNSPECIFIED) {
...@@ -109,7 +114,8 @@ int default_spi_read(struct flashctx *flash, uint8_t *buf, unsigned int start, u ...@@ -109,7 +114,8 @@ int default_spi_read(struct flashctx *flash, uint8_t *buf, unsigned int start, u
return spi_read_chunked(flash, buf, start, len, max_data); return spi_read_chunked(flash, buf, start, len, max_data);
} }
int default_spi_write_256(struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len) int default_spi_write_256(struct flashctx *flash, uint8_t *buf,
unsigned int start, unsigned int len)
{ {
unsigned int max_data = spi_programmer->max_data_write; unsigned int max_data = spi_programmer->max_data_write;
if (max_data == MAX_DATA_UNSPECIFIED) { if (max_data == MAX_DATA_UNSPECIFIED) {
...@@ -121,7 +127,8 @@ int default_spi_write_256(struct flashctx *flash, uint8_t *buf, unsigned int sta ...@@ -121,7 +127,8 @@ int default_spi_write_256(struct flashctx *flash, uint8_t *buf, unsigned int sta
return spi_write_chunked(flash, buf, start, len, max_data); return spi_write_chunked(flash, buf, start, len, max_data);
} }
int spi_chip_read(struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len) int spi_chip_read(struct flashctx *flash, uint8_t *buf, unsigned int start,
unsigned int len)
{ {
unsigned int addrbase = 0; unsigned int addrbase = 0;
if (!spi_programmer->read) { if (!spi_programmer->read) {
...@@ -135,7 +142,7 @@ int spi_chip_read(struct flashctx *flash, uint8_t *buf, unsigned int start, unsi ...@@ -135,7 +142,7 @@ int spi_chip_read(struct flashctx *flash, uint8_t *buf, unsigned int start, unsi
* address. Highest possible address with the current SPI implementation * address. Highest possible address with the current SPI implementation
* means 0xffffff, the highest unsigned 24bit number. * means 0xffffff, the highest unsigned 24bit number.
*/ */
addrbase = spi_get_valid_read_addr(); addrbase = spi_get_valid_read_addr(flash);
if (addrbase + flash->total_size * 1024 > (1 << 24)) { if (addrbase + flash->total_size * 1024 > (1 << 24)) {
msg_perr("Flash chip size exceeds the allowed access window. "); msg_perr("Flash chip size exceeds the allowed access window. ");
msg_perr("Read will probably fail.\n"); msg_perr("Read will probably fail.\n");
...@@ -160,7 +167,8 @@ int spi_chip_read(struct flashctx *flash, uint8_t *buf, unsigned int start, unsi ...@@ -160,7 +167,8 @@ int spi_chip_read(struct flashctx *flash, uint8_t *buf, unsigned int start, unsi
* .write_256 = spi_chip_write_1 * .write_256 = spi_chip_write_1
*/ */
/* real chunksize is up to 256, logical chunksize is 256 */ /* real chunksize is up to 256, logical chunksize is 256 */
int spi_chip_write_256(struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len) int spi_chip_write_256(struct flashctx *flash, uint8_t *buf, unsigned int start,
unsigned int len)
{ {
if (!spi_programmer->write_256) { if (!spi_programmer->write_256) {
msg_perr("%s called, but SPI page write is unsupported on this " msg_perr("%s called, but SPI page write is unsupported on this "
...@@ -177,7 +185,7 @@ int spi_chip_write_256(struct flashctx *flash, uint8_t *buf, unsigned int start, ...@@ -177,7 +185,7 @@ int spi_chip_write_256(struct flashctx *flash, uint8_t *buf, unsigned int start,
* be the lowest allowed address for all commands which take an address. * be the lowest allowed address for all commands which take an address.
* This is a programmer limitation. * This is a programmer limitation.
*/ */
uint32_t spi_get_valid_read_addr(void) uint32_t spi_get_valid_read_addr(struct flashctx *flash)
{ {
switch (spi_programmer->type) { switch (spi_programmer->type) {
#if CONFIG_INTERNAL == 1 #if CONFIG_INTERNAL == 1
......
This diff is collapsed.
...@@ -34,13 +34,13 @@ int protect_28sf040(struct flashctx *flash) ...@@ -34,13 +34,13 @@ int protect_28sf040(struct flashctx *flash)
{ {
chipaddr bios = flash->virtual_memory; chipaddr bios = flash->virtual_memory;
chip_readb(bios + 0x1823); chip_readb(flash, bios + 0x1823);
chip_readb(bios + 0x1820); chip_readb(flash, bios + 0x1820);
chip_readb(bios + 0x1822); chip_readb(flash, bios + 0x1822);
chip_readb(bios + 0x0418); chip_readb(flash, bios + 0x0418);
chip_readb(bios + 0x041B); chip_readb(flash, bios + 0x041B);
chip_readb(bios + 0x0419); chip_readb(flash, bios + 0x0419);
chip_readb(bios + 0x040A); chip_readb(flash, bios + 0x040A);
return 0; return 0;
} }
...@@ -49,34 +49,36 @@ int unprotect_28sf040(struct flashctx *flash) ...@@ -49,34 +49,36 @@ int unprotect_28sf040(struct flashctx *flash)
{ {
chipaddr bios = flash->virtual_memory; chipaddr bios = flash->virtual_memory;
chip_readb(bios + 0x1823); chip_readb(flash, bios + 0x1823);
chip_readb(bios + 0x1820); chip_readb(flash, bios + 0x1820);
chip_readb(bios + 0x1822); chip_readb(flash, bios + 0x1822);
chip_readb(bios + 0x0418); chip_readb(flash, bios + 0x0418);
chip_readb(bios + 0x041B); chip_readb(flash, bios + 0x041B);
chip_readb(bios + 0x0419); chip_readb(flash, bios + 0x0419);
chip_readb(bios + 0x041A); chip_readb(flash, bios + 0x041A);
return 0; return 0;
} }
int erase_sector_28sf040(struct flashctx *flash, unsigned int address, unsigned int sector_size) int erase_sector_28sf040(struct flashctx *flash, unsigned int address,
unsigned int sector_size)
{ {
chipaddr bios = flash->virtual_memory; chipaddr bios = flash->virtual_memory;
/* This command sequence is very similar to erase_block_82802ab. */ /* This command sequence is very similar to erase_block_82802ab. */
chip_writeb(AUTO_PG_ERASE1, bios); chip_writeb(flash, AUTO_PG_ERASE1, bios);
chip_writeb(AUTO_PG_ERASE2, bios + address); chip_writeb(flash, AUTO_PG_ERASE2, bios + address);
/* wait for Toggle bit ready */ /* wait for Toggle bit ready */
toggle_ready_jedec(bios); toggle_ready_jedec(flash, bios);
/* FIXME: Check the status register for errors. */ /* FIXME: Check the status register for errors. */
return 0; return 0;
} }
/* chunksize is 1 */ /* chunksize is 1 */
int write_28sf040(struct flashctx *flash, uint8_t *src, unsigned int start, unsigned int len) int write_28sf040(struct flashctx *flash, uint8_t *src, unsigned int start,
unsigned int len)
{ {
int i; int i;
chipaddr bios = flash->virtual_memory; chipaddr bios = flash->virtual_memory;
...@@ -90,11 +92,11 @@ int write_28sf040(struct flashctx *flash, uint8_t *src, unsigned int start, unsi ...@@ -90,11 +92,11 @@ int write_28sf040(struct flashctx *flash, uint8_t *src, unsigned int start, unsi
continue; continue;
} }
/*issue AUTO PROGRAM command */ /*issue AUTO PROGRAM command */
chip_writeb(AUTO_PGRM, dst); chip_writeb(flash, AUTO_PGRM, dst);
chip_writeb(*src++, dst++); chip_writeb(flash, *src++, dst++);
/* wait for Toggle bit ready */ /* wait for Toggle bit ready */
toggle_ready_jedec(bios); toggle_ready_jedec(flash, bios);
} }
return 0; return 0;
...@@ -104,17 +106,18 @@ static int erase_28sf040(struct flashctx *flash) ...@@ -104,17 +106,18 @@ static int erase_28sf040(struct flashctx *flash)
{ {
chipaddr bios = flash->virtual_memory; chipaddr bios = flash->virtual_memory;
chip_writeb(CHIP_ERASE, bios); chip_writeb(flash, CHIP_ERASE, bios);
chip_writeb(CHIP_ERASE, bios); chip_writeb(flash, CHIP_ERASE, bios);
programmer_delay(10); programmer_delay(10);
toggle_ready_jedec(bios); toggle_ready_jedec(flash, bios);
/* FIXME: Check the status register for errors. */ /* FIXME: Check the status register for errors. */
return 0; return 0;
} }
int erase_chip_28sf040(struct flashctx *flash, unsigned int addr, unsigned int blocklen) int erase_chip_28sf040(struct flashctx *flash, unsigned int addr,
unsigned int blocklen)
{ {
if ((addr != 0) || (blocklen != flash->total_size * 1024)) { if ((addr != 0) || (blocklen != flash->total_size * 1024)) {
msg_cerr("%s called with incorrect arguments\n", msg_cerr("%s called with incorrect arguments\n",
......
...@@ -23,11 +23,14 @@ ...@@ -23,11 +23,14 @@
#include "flash.h" #include "flash.h"
#include "chipdrivers.h" #include "chipdrivers.h"
static int write_lockbits_block_49lfxxxc(struct flashctx *flash, unsigned long address, unsigned char bits) static int write_lockbits_block_49lfxxxc(struct flashctx *flash,
unsigned long address,
unsigned char bits)
{ {
unsigned long lock = flash->virtual_registers + address + 2; unsigned long lock = flash->virtual_registers + address + 2;
msg_cdbg("lockbits at address=0x%08lx is 0x%01x\n", lock, chip_readb(lock)); msg_cdbg("lockbits at address=0x%08lx is 0x%01x\n", lock,
chip_writeb(bits, lock); chip_readb(flash, lock));
chip_writeb(flash, bits, lock);
return 0; return 0;
} }
...@@ -59,13 +62,14 @@ int unlock_49lfxxxc(struct flashctx *flash) ...@@ -59,13 +62,14 @@ int unlock_49lfxxxc(struct flashctx *flash)
return write_lockbits_49lfxxxc(flash, 0); return write_lockbits_49lfxxxc(flash, 0);
} }
int erase_sector_49lfxxxc(struct flashctx *flash, unsigned int address, unsigned int sector_size) int erase_sector_49lfxxxc(struct flashctx *flash, unsigned int address,
unsigned int sector_size)
{ {
uint8_t status; uint8_t status;
chipaddr bios = flash->virtual_memory; chipaddr bios = flash->virtual_memory;
chip_writeb(0x30, bios); chip_writeb(flash, 0x30, bios);
chip_writeb(0xD0, bios + address); chip_writeb(flash, 0xD0, bios + address);
status = wait_82802ab(flash); status = wait_82802ab(flash);
print_status_82802ab(status); print_status_82802ab(status);
......
...@@ -29,7 +29,7 @@ static int check_sst_fwhub_block_lock(struct flashctx *flash, int offset) ...@@ -29,7 +29,7 @@ static int check_sst_fwhub_block_lock(struct flashctx *flash, int offset)
chipaddr registers = flash->virtual_registers; chipaddr registers = flash->virtual_registers;
uint8_t blockstatus; uint8_t blockstatus;
blockstatus = chip_readb(registers + offset + 2); blockstatus = chip_readb(flash, registers + offset + 2);
msg_cdbg("Lock status for 0x%06x (size 0x%06x) is %02x, ", msg_cdbg("Lock status for 0x%06x (size 0x%06x) is %02x, ",
offset, flash->page_size, blockstatus); offset, flash->page_size, blockstatus);
switch (blockstatus & 0x3) { switch (blockstatus & 0x3) {
...@@ -59,7 +59,7 @@ static int clear_sst_fwhub_block_lock(struct flashctx *flash, int offset) ...@@ -59,7 +59,7 @@ static int clear_sst_fwhub_block_lock(struct flashctx *flash, int offset)
if (blockstatus) { if (blockstatus) {
msg_cdbg("Trying to clear lock for 0x%06x... ", offset); msg_cdbg("Trying to clear lock for 0x%06x... ", offset);
chip_writeb(0, registers + offset + 2); chip_writeb(flash, 0, registers + offset + 2);
blockstatus = check_sst_fwhub_block_lock(flash, offset); blockstatus = check_sst_fwhub_block_lock(flash, offset);
msg_cdbg("%s\n", (blockstatus) ? "failed" : "OK"); msg_cdbg("%s\n", (blockstatus) ? "failed" : "OK");
......
...@@ -60,8 +60,10 @@ static int unlock_block_stm50flw0x0x(struct flashctx *flash, int offset) ...@@ -60,8 +60,10 @@ static int unlock_block_stm50flw0x0x(struct flashctx *flash, int offset)
// unlock each 4k-sector // unlock each 4k-sector
for (j = 0; j < 0x10000; j += 0x1000) { for (j = 0; j < 0x10000; j += 0x1000) {
msg_cdbg("unlocking at 0x%x\n", offset + j); msg_cdbg("unlocking at 0x%x\n", offset + j);
chip_writeb(unlock_sector, wrprotect + offset + j); chip_writeb(flash, unlock_sector,
if (chip_readb(wrprotect + offset + j) != unlock_sector) { wrprotect + offset + j);
if (chip_readb(flash, wrprotect + offset + j) !=
unlock_sector) {
msg_cerr("Cannot unlock sector @ 0x%x\n", msg_cerr("Cannot unlock sector @ 0x%x\n",
offset + j); offset + j);
return -1; return -1;
...@@ -69,8 +71,8 @@ static int unlock_block_stm50flw0x0x(struct flashctx *flash, int offset) ...@@ -69,8 +71,8 @@ static int unlock_block_stm50flw0x0x(struct flashctx *flash, int offset)
} }
} else { } else {
msg_cdbg("unlocking at 0x%x\n", offset); msg_cdbg("unlocking at 0x%x\n", offset);
chip_writeb(unlock_sector, wrprotect + offset); chip_writeb(flash, unlock_sector, wrprotect + offset);
if (chip_readb(wrprotect + offset) != unlock_sector) { if (chip_readb(flash, wrprotect + offset) != unlock_sector) {
msg_cerr("Cannot unlock sector @ 0x%x\n", offset); msg_cerr("Cannot unlock sector @ 0x%x\n", offset);
return -1; return -1;
} }
...@@ -94,15 +96,16 @@ int unlock_stm50flw0x0x(struct flashctx *flash) ...@@ -94,15 +96,16 @@ int unlock_stm50flw0x0x(struct flashctx *flash)
} }
/* This function is unused. */ /* This function is unused. */
int erase_sector_stm50flw0x0x(struct flashctx *flash, unsigned int sector, unsigned int sectorsize) int erase_sector_stm50flw0x0x(struct flashctx *flash, unsigned int sector,
unsigned int sectorsize)
{ {
chipaddr bios = flash->virtual_memory + sector; chipaddr bios = flash->virtual_memory + sector;
// clear status register // clear status register
chip_writeb(0x50, bios); chip_writeb(flash, 0x50, bios);
// now start it // now start it
chip_writeb(0x32, bios); chip_writeb(flash, 0x32, bios);
chip_writeb(0xd0, bios); chip_writeb(flash, 0xd0, bios);
programmer_delay(10); programmer_delay(10);
wait_82802ab(flash); wait_82802ab(flash);
......
...@@ -38,29 +38,29 @@ int probe_w29ee011(struct flashctx *flash) ...@@ -38,29 +38,29 @@ int probe_w29ee011(struct flashctx *flash)
} }
/* Issue JEDEC Product ID Entry command */ /* Issue JEDEC Product ID Entry command */
chip_writeb(0xAA, bios + 0x5555); chip_writeb(flash, 0xAA, bios + 0x5555);
programmer_delay(10); programmer_delay(10);
chip_writeb(0x55, bios + 0x2AAA); chip_writeb(flash, 0x55, bios + 0x2AAA);
programmer_delay(10); programmer_delay(10);
chip_writeb(0x80, bios + 0x5555); chip_writeb(flash, 0x80, bios + 0x5555);
programmer_delay(10); programmer_delay(10);
chip_writeb(0xAA, bios + 0x5555); chip_writeb(flash, 0xAA, bios + 0x5555);
programmer_delay(10); programmer_delay(10);
chip_writeb(0x55, bios + 0x2AAA); chip_writeb(flash, 0x55, bios + 0x2AAA);
programmer_delay(10); programmer_delay(10);
chip_writeb(0x60, bios + 0x5555); chip_writeb(flash, 0x60, bios + 0x5555);
programmer_delay(10); programmer_delay(10);
/* Read product ID */ /* Read product ID */
id1 = chip_readb(bios); id1 = chip_readb(flash, bios);
id2 = chip_readb(bios + 0x01); id2 = chip_readb(flash, bios + 0x01);
/* Issue JEDEC Product ID Exit command */ /* Issue JEDEC Product ID Exit command */
chip_writeb(0xAA, bios + 0x5555); chip_writeb(flash, 0xAA, bios + 0x5555);
programmer_delay(10); programmer_delay(10);
chip_writeb(0x55, bios + 0x2AAA); chip_writeb(flash, 0x55, bios + 0x2AAA);
programmer_delay(10); programmer_delay(10);
chip_writeb(0xF0, bios + 0x5555); chip_writeb(flash, 0xF0, bios + 0x5555);
programmer_delay(10); programmer_delay(10);
msg_cdbg("%s: id1 0x%02x, id2 0x%02x\n", __func__, id1, id2); msg_cdbg("%s: id1 0x%02x, id2 0x%02x\n", __func__, id1, id2);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment