Trivial (cosmetic) cleanup:
* Only open /dev/mem once and do it early. * Drop extern for function prototypes. * Minimize ts5300 impact in probe_flash() This cleanup will making ICH7 SPI support quite some easier. Signed-off-by: Stefan Reinauer <stepan@coresystems.de> Acked-by: Stefan Reinauer <stepan@coresystems.de> git-svn-id: svn://svn.coreboot.org/coreboot/trunk@2585 2b7e53f0-3cfb-0310-b3e9-8179ed1497e1
This commit is contained in:
parent
8944499617
commit
03cafbfdfe
|
@ -79,7 +79,7 @@ int probe_82802ab(struct flashchip *flash)
|
||||||
size_t size = flash->total_size * 1024;
|
size_t size = flash->total_size * 1024;
|
||||||
// we need to mmap the write-protect space.
|
// we need to mmap the write-protect space.
|
||||||
bios = mmap(0, size, PROT_WRITE | PROT_READ, MAP_SHARED,
|
bios = mmap(0, size, PROT_WRITE | PROT_READ, MAP_SHARED,
|
||||||
flash->fd_mem, (off_t) (0 - 0x400000 - size));
|
fd_mem, (off_t) (0 - 0x400000 - size));
|
||||||
if (bios == MAP_FAILED) {
|
if (bios == MAP_FAILED) {
|
||||||
// it's this part but we can't map it ...
|
// it's this part but we can't map it ...
|
||||||
perror("Error MMAP memory using " MEM_DEV );
|
perror("Error MMAP memory using " MEM_DEV );
|
||||||
|
|
|
@ -45,7 +45,6 @@ struct flashchip {
|
||||||
int (*write) (struct flashchip *flash, uint8_t *buf);
|
int (*write) (struct flashchip *flash, uint8_t *buf);
|
||||||
int (*read) (struct flashchip *flash, uint8_t *buf);
|
int (*read) (struct flashchip *flash, uint8_t *buf);
|
||||||
|
|
||||||
int fd_mem;
|
|
||||||
volatile uint8_t *virt_addr_2;
|
volatile uint8_t *virt_addr_2;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -126,17 +125,17 @@ extern struct flashchip flashchips[];
|
||||||
|
|
||||||
/* function prototypes from udelay.h */
|
/* function prototypes from udelay.h */
|
||||||
|
|
||||||
extern void myusec_delay(int time);
|
void myusec_delay(int time);
|
||||||
extern void myusec_calibrate_delay();
|
void myusec_calibrate_delay();
|
||||||
|
|
||||||
/* pci handling for board/chipset_enable */
|
/* pci handling for board/chipset_enable */
|
||||||
extern struct pci_access *pacc; /* For board and chipset_enable */
|
struct pci_access *pacc; /* For board and chipset_enable */
|
||||||
extern struct pci_dev *pci_dev_find(uint16_t vendor, uint16_t device);
|
struct pci_dev *pci_dev_find(uint16_t vendor, uint16_t device);
|
||||||
extern struct pci_dev *pci_card_find(uint16_t vendor, uint16_t device,
|
struct pci_dev *pci_card_find(uint16_t vendor, uint16_t device,
|
||||||
uint16_t card_vendor, uint16_t card_device);
|
uint16_t card_vendor, uint16_t card_device);
|
||||||
|
|
||||||
extern int board_flash_enable(char *vendor, char *part); /* board_enable.c */
|
int board_flash_enable(char *vendor, char *part); /* board_enable.c */
|
||||||
extern int chipset_flash_enable(void); /* chipset_enable.c */
|
int chipset_flash_enable(void); /* chipset_enable.c */
|
||||||
|
|
||||||
/* physical memory mapping device */
|
/* physical memory mapping device */
|
||||||
|
|
||||||
|
@ -146,4 +145,6 @@ extern int chipset_flash_enable(void); /* chipset_enable.c */
|
||||||
# define MEM_DEV "/dev/mem"
|
# define MEM_DEV "/dev/mem"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
extern int fd_mem;
|
||||||
|
|
||||||
#endif /* !__FLASH_H__ */
|
#endif /* !__FLASH_H__ */
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
* Copyright 2000 Silicon Integrated System Corporation
|
* Copyright 2000 Silicon Integrated System Corporation
|
||||||
* Copyright 2004 Tyan Corp
|
* Copyright 2004 Tyan Corp
|
||||||
* yhlu yhlu@tyan.com add exclude start and end option
|
* yhlu yhlu@tyan.com add exclude start and end option
|
||||||
* Copyright 2005-2006 coresystems GmbH
|
* Copyright 2005-2007 coresystems GmbH
|
||||||
* Stefan Reinauer <stepan@coresystems.de> added rom layout
|
* Stefan Reinauer <stepan@coresystems.de> added rom layout
|
||||||
* support, and checking for suitable rom image, various fixes
|
* support, and checking for suitable rom image, various fixes
|
||||||
* support for flashing the Technologic Systems 5300.
|
* support for flashing the Technologic Systems 5300.
|
||||||
|
@ -55,6 +55,8 @@ struct pci_access *pacc; /* For board and chipset_enable */
|
||||||
int exclude_start_page, exclude_end_page;
|
int exclude_start_page, exclude_end_page;
|
||||||
int force=0, verbose=0;
|
int force=0, verbose=0;
|
||||||
|
|
||||||
|
int fd_mem;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
@ -101,66 +103,53 @@ pci_card_find(uint16_t vendor, uint16_t device,
|
||||||
|
|
||||||
struct flashchip *probe_flash(struct flashchip *flash)
|
struct flashchip *probe_flash(struct flashchip *flash)
|
||||||
{
|
{
|
||||||
int fd_mem;
|
|
||||||
volatile uint8_t *bios;
|
volatile uint8_t *bios;
|
||||||
unsigned long size;
|
unsigned long flash_baseaddr, size;
|
||||||
|
|
||||||
if ((fd_mem = open(MEM_DEV, O_RDWR)) < 0) {
|
|
||||||
perror("Error: Can not access memory using " MEM_DEV ". You need to be root.");
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
while (flash->name != NULL) {
|
while (flash->name != NULL) {
|
||||||
if (chip_to_probe && strcmp(flash->name, chip_to_probe) != 0) {
|
if (chip_to_probe && strcmp(flash->name, chip_to_probe) != 0) {
|
||||||
flash++;
|
flash++;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
printf_debug("Trying %s, %d KB\n", flash->name, flash->total_size);
|
printf_debug("Probing for %s, %d KB\n",
|
||||||
|
flash->name, flash->total_size);
|
||||||
|
|
||||||
size = flash->total_size * 1024;
|
size = flash->total_size * 1024;
|
||||||
/* BUG? what happens if getpagesize() > size!?
|
|
||||||
-> ``Error MMAP /dev/mem: Invalid argument'' NIKI */
|
#ifdef TS5300
|
||||||
|
// FIXME: Wrong place for this decision
|
||||||
|
flash_baseaddr = 0x9400000;
|
||||||
|
#else
|
||||||
|
flash_baseaddr = (0xffffffff - size + 1);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* If getpagesize() > size ->
|
||||||
|
* `Error MMAP /dev/mem: Invalid argument'
|
||||||
|
* This should never happen as we don't support any flash chips
|
||||||
|
* smaller than 4k or 8k yet.
|
||||||
|
*/
|
||||||
|
|
||||||
if (getpagesize() > size) {
|
if (getpagesize() > size) {
|
||||||
size = getpagesize();
|
size = getpagesize();
|
||||||
printf("%s: warning: size: %d -> %ld\n",
|
printf("WARNING: size: %d -> %ld (page size)\n",
|
||||||
__FUNCTION__, flash->total_size * 1024,
|
flash->total_size * 1024, (unsigned long) size);
|
||||||
(unsigned long) size);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bios = mmap(0, size, PROT_WRITE | PROT_READ, MAP_SHARED,
|
bios = mmap(0, size, PROT_WRITE | PROT_READ, MAP_SHARED,
|
||||||
fd_mem, (off_t) (0xffffffff - size + 1));
|
fd_mem, (off_t)flash_baseaddr );
|
||||||
if (bios == MAP_FAILED) {
|
if (bios == MAP_FAILED) {
|
||||||
perror("Error: Can't mmap " MEM_DEV ".");
|
perror("Error: Can't mmap " MEM_DEV ".");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
flash->virt_addr = bios;
|
flash->virt_addr = bios;
|
||||||
flash->fd_mem = fd_mem;
|
|
||||||
|
|
||||||
if (flash->probe(flash) == 1) {
|
if (flash->probe(flash) == 1) {
|
||||||
printf("%s found at physical address: 0x%lx\n",
|
printf("%s found at physical address: 0x%lx\n",
|
||||||
flash->name, (0xffffffff - size + 1));
|
flash->name, flash_baseaddr);
|
||||||
return flash;
|
return flash;
|
||||||
}
|
}
|
||||||
munmap((void *) bios, size);
|
munmap((void *) bios, size);
|
||||||
#ifdef TS5300
|
|
||||||
/* TS-5300 */
|
|
||||||
bios = mmap(0, size, PROT_WRITE | PROT_READ, MAP_SHARED,
|
|
||||||
fd_mem, (off_t) (0x9400000));
|
|
||||||
if (bios == MAP_FAILED) {
|
|
||||||
perror("Error: Can't mmap " MEM_DEV ".");
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
flash->virt_addr = bios;
|
|
||||||
flash->fd_mem = fd_mem;
|
|
||||||
|
|
||||||
if (flash->probe(flash) == 1) {
|
|
||||||
printf("TS-5300 %s found at physical address: 0x%lx\n",
|
|
||||||
flash->name, 0x9400000UL);
|
|
||||||
return flash;
|
|
||||||
}
|
|
||||||
munmap((void *) bios, size);
|
|
||||||
/* TS-5300 */
|
|
||||||
#endif
|
|
||||||
|
|
||||||
flash++;
|
flash++;
|
||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -351,9 +340,13 @@ int main(int argc, char *argv[])
|
||||||
pci_init(pacc); /* Initialize the PCI library */
|
pci_init(pacc); /* Initialize the PCI library */
|
||||||
pci_scan_bus(pacc); /* We want to get the list of devices */
|
pci_scan_bus(pacc); /* We want to get the list of devices */
|
||||||
|
|
||||||
printf("Calibrating delay loop... ");
|
/* Open the memory device. A lot of functions need it */
|
||||||
|
if ((fd_mem = open(MEM_DEV, O_RDWR)) < 0) {
|
||||||
|
perror("Error: Can not access memory using " MEM_DEV ". You need to be root.");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
myusec_calibrate_delay();
|
myusec_calibrate_delay();
|
||||||
printf("ok\n");
|
|
||||||
|
|
||||||
/* We look at the lbtable first to see if we need a
|
/* We look at the lbtable first to see if we need a
|
||||||
* mainboard specific flash enable sequence.
|
* mainboard specific flash enable sequence.
|
||||||
|
|
|
@ -158,14 +158,8 @@ int linuxbios_init(void)
|
||||||
struct lb_header *lb_table;
|
struct lb_header *lb_table;
|
||||||
struct lb_record *rec, *last;
|
struct lb_record *rec, *last;
|
||||||
|
|
||||||
int fd;
|
low_1MB = mmap(0, 1024*1024, PROT_READ, MAP_SHARED, fd_mem, 0x00000000);
|
||||||
fd = open(MEM_DEV, O_RDONLY);
|
if (low_1MB == MAP_FAILED) {
|
||||||
if (fd < 0) {
|
|
||||||
fprintf(stderr, "Can not access memory using " MEM_DEV "\n");
|
|
||||||
exit(-1);
|
|
||||||
}
|
|
||||||
low_1MB = mmap(0, 1024*1024, PROT_READ, MAP_SHARED, fd, 0x00000000);
|
|
||||||
if (low_1MB == ((void *) -1)) {
|
|
||||||
fprintf(stderr, "Can not mmap " MEM_DEV " at %08lx errno(%d):%s\n",
|
fprintf(stderr, "Can not mmap " MEM_DEV " at %08lx errno(%d):%s\n",
|
||||||
0x00000000UL, errno, strerror(errno));
|
0x00000000UL, errno, strerror(errno));
|
||||||
exit(-2);
|
exit(-2);
|
||||||
|
|
|
@ -78,7 +78,7 @@ int probe_lhf00l04(struct flashchip *flash)
|
||||||
size_t size = flash->total_size * 1024;
|
size_t size = flash->total_size * 1024;
|
||||||
// we need to mmap the write-protect space.
|
// we need to mmap the write-protect space.
|
||||||
bios = mmap(0, size, PROT_WRITE | PROT_READ, MAP_SHARED,
|
bios = mmap(0, size, PROT_WRITE | PROT_READ, MAP_SHARED,
|
||||||
flash->fd_mem, (off_t) (0 - 0x400000 - size));
|
fd_mem, (off_t) (0 - 0x400000 - size));
|
||||||
if (bios == MAP_FAILED) {
|
if (bios == MAP_FAILED) {
|
||||||
// it's this part but we can't map it ...
|
// it's this part but we can't map it ...
|
||||||
perror("Error MMAP /dev/mem");
|
perror("Error MMAP /dev/mem");
|
||||||
|
|
|
@ -151,7 +151,7 @@ int probe_49lfxxxc(struct flashchip *flash)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
bios = mmap(0, size, PROT_WRITE | PROT_READ, MAP_SHARED,
|
bios = mmap(0, size, PROT_WRITE | PROT_READ, MAP_SHARED,
|
||||||
flash->fd_mem, (off_t) (0xFFFFFFFF - 0x400000 - size + 1));
|
fd_mem, (off_t) (0xFFFFFFFF - 0x400000 - size + 1));
|
||||||
if (bios == MAP_FAILED) {
|
if (bios == MAP_FAILED) {
|
||||||
// it's this part but we can't map it ...
|
// it's this part but we can't map it ...
|
||||||
perror("Error MMAP /dev/mem");
|
perror("Error MMAP /dev/mem");
|
||||||
|
|
|
@ -53,7 +53,7 @@ int probe_sst_fwhub(struct flashchip *flash)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
bios = mmap(0, size, PROT_WRITE | PROT_READ, MAP_SHARED,
|
bios = mmap(0, size, PROT_WRITE | PROT_READ, MAP_SHARED,
|
||||||
flash->fd_mem, (off_t) (0xFFFFFFFF - 0x400000 - size + 1));
|
fd_mem, (off_t) (0xFFFFFFFF - 0x400000 - size + 1));
|
||||||
if (bios == MAP_FAILED) {
|
if (bios == MAP_FAILED) {
|
||||||
// it's this part but we can't map it ...
|
// it's this part but we can't map it ...
|
||||||
perror("Error MMAP /dev/mem");
|
perror("Error MMAP /dev/mem");
|
||||||
|
|
|
@ -18,7 +18,8 @@ void myusec_calibrate_delay()
|
||||||
struct timeval start, end;
|
struct timeval start, end;
|
||||||
int ok = 0;
|
int ok = 0;
|
||||||
|
|
||||||
printf_debug("Setting up microsecond timing loop\n");
|
printf("Calibrating delay loop... ");
|
||||||
|
|
||||||
while (!ok) {
|
while (!ok) {
|
||||||
gettimeofday(&start, 0);
|
gettimeofday(&start, 0);
|
||||||
myusec_delay(count);
|
myusec_delay(count);
|
||||||
|
@ -34,5 +35,6 @@ void myusec_calibrate_delay()
|
||||||
// compute one microsecond. That will be count / time
|
// compute one microsecond. That will be count / time
|
||||||
micro = count / timeusec;
|
micro = count / timeusec;
|
||||||
|
|
||||||
printf_debug("%ldM loops per second\n", (unsigned long)micro);
|
printf_debug("%ldM loops per second. ", (unsigned long)micro);
|
||||||
|
printf("ok\n");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue