From b1a740bc28ec1c7d21f7b084080a1d006d2931f8 Mon Sep 17 00:00:00 2001 From: "Eric W. Biederman" Date: Thu, 10 Oct 2002 19:46:47 +0000 Subject: [PATCH] AUTHORS - Add myself src/cpu/p5/delay_tsc.c - Fix the indentation - Don't have the new calibrate_tsc function directly update global variables. src/include/smp/start_stop.h - Change #ifdef SMP to #if SMP == 1 src/include/string.h - Declare sprintf src/lib/elfboot.c - Minor fixes to verify_loaded_image - Change all of the new debugging messages to printk_spew src/lib/inflate.c - Remove sensless warning message fixes src/lib/linuxpci.c - move declaration of sprintf to string.h - Better detection of read only bars in pci_get_resource - Remove pci_noop - Remove warning about set_pci_dev_ops not being finished src/lib/src.c - change #ifdef SERIAL_POST to #if SERIAL_POST in post_code --- AUTHORS | 1 + src/cpu/p5/delay_tsc.c | 74 +++++++++++++++++------------------- src/include/smp/start_stop.h | 2 +- src/include/string.h | 1 + src/lib/elfboot.c | 10 ++--- src/lib/inflate.c | 6 +-- src/lib/linuxpci.c | 22 ++++------- src/lib/subr.c | 2 +- 8 files changed, 53 insertions(+), 65 deletions(-) diff --git a/AUTHORS b/AUTHORS index 604c628354..d4b8e92155 100644 --- a/AUTHORS +++ b/AUTHORS @@ -1,6 +1,7 @@ Contributors (in alpha order): +Eric Biederman - 440GX SPD, elfboot, mkelfImage, Athlon SMP, P4 Xeon, etc Jeff Garzik - The essential /dev/fb! First freebios James Hendricks - SMP for 440GX among many other things Ollie Lho - SIS 630 diff --git a/src/cpu/p5/delay_tsc.c b/src/cpu/p5/delay_tsc.c index 39facd81a1..062eb30e99 100644 --- a/src/cpu/p5/delay_tsc.c +++ b/src/cpu/p5/delay_tsc.c @@ -98,45 +98,39 @@ bad_ctc: */ static unsigned long long calibrate_tsc(void) { - unsigned long long retval, start, end, delta; - unsigned long allones = (unsigned long) -1, result; - unsigned long startlow, starthigh; - unsigned long endlow, endhigh; - unsigned long count; - - rdtsc(startlow,starthigh); - // no udivdi3, dammit. - // so we count to 1<< 20 and then right shift 20 - for(count = 0; count < (1<<20); count ++) - outb(0x80, 0x80); - rdtsc(endlow,endhigh); - - // make delta be (endhigh - starthigh) + (endlow - startlow) - // but >> 20 - // do it this way to avoid gcc warnings. - start = starthigh; - start <<= 32; - start |= startlow; - end = endhigh; - end <<= 32; - end |= endlow; - delta = end - start; - // at this point we have a delta for 1,000,000 outbs. Now rescale for one microsecond. - delta >>= 20; - // save this for microsecond timing. - clocks_per_usec = delta; -#define DEBUG -#ifdef DEBUG - printk_notice("end %x:%x, start %x:%x\n", - endhigh, endlow, starthigh, startlow); - printk_notice("32-bit delta %d\n", (unsigned long) delta); -#endif - - retval = clocks_per_usec; -#ifdef DEBUG - printk_notice(__FUNCTION__ " 32-bit result is %d\n", result); -#endif - return retval; + unsigned long long retval, start, end, delta; + unsigned long allones = (unsigned long) -1, result; + unsigned long startlow, starthigh; + unsigned long endlow, endhigh; + unsigned long count; + + rdtsc(startlow,starthigh); + // no udivdi3, dammit. + // so we count to 1<< 20 and then right shift 20 + for(count = 0; count < (1<<20); count ++) + outb(0x80, 0x80); + rdtsc(endlow,endhigh); + + // make delta be (endhigh - starthigh) + (endlow - startlow) + // but >> 20 + // do it this way to avoid gcc warnings. + start = starthigh; + start <<= 32; + start |= startlow; + end = endhigh; + end <<= 32; + end |= endlow; + delta = end - start; + // at this point we have a delta for 1,000,000 outbs. Now rescale for one microsecond. + delta >>= 20; + // save this for microsecond timing. + result = delta; + printk_spew("end %x:%x, start %x:%x\n", + endhigh, endlow, starthigh, startlow); + printk_spew("32-bit delta %d\n", (unsigned long) delta); + + printk_spew(__FUNCTION__ " 32-bit result is %d\n", result); + return retval; } @@ -149,7 +143,7 @@ void udelay(unsigned long us) unsigned long long clocks; if (!clocks_per_usec) { - calibrate_tsc(); + clocks_per_usec = calibrate_tsc(); printk_info("clocks_per_usec: %u\n", clocks_per_usec); } clocks = us; diff --git a/src/include/smp/start_stop.h b/src/include/smp/start_stop.h index 8ffcba1fe1..c0eebd0e2c 100644 --- a/src/include/smp/start_stop.h +++ b/src/include/smp/start_stop.h @@ -1,7 +1,7 @@ #ifndef SMP_START_STOP_H #define SMP_START_STOP_H -#ifdef SMP +#if SMP == 1 #include unsigned long this_processors_id(void); int processor_index(unsigned long processor_id); diff --git a/src/include/string.h b/src/include/string.h index dbb67751e4..cf9bbb14d2 100644 --- a/src/include/string.h +++ b/src/include/string.h @@ -32,4 +32,5 @@ extern void *memcpy(void *dest, const void *src, size_t n); extern void *memset(void *s, int c, size_t n); extern int memcmp(const void *s1, const void *s2, size_t n); +extern int sprintf(char * buf, const char *fmt, ...); #endif /* STRING_H */ diff --git a/src/lib/elfboot.c b/src/lib/elfboot.c index eabe0f5d96..5decacd3c8 100644 --- a/src/lib/elfboot.c +++ b/src/lib/elfboot.c @@ -67,7 +67,7 @@ int verify_ip_checksum( bytes += sizeof(*ehdr); checksum = add_ip_checksums(bytes, checksum, compute_ip_checksum(phdr, ehdr->e_phnum*sizeof(*phdr))); - bytes += sizeof(*phdr); + bytes += ehdr->e_phnum*sizeof(*phdr); for(ptr = head->phdr_next; ptr != head; ptr = ptr->phdr_next) { checksum = add_ip_checksums(bytes, checksum, compute_ip_checksum((void *)ptr->s_addr, ptr->s_memsz)); @@ -574,8 +574,6 @@ int elfload(struct stream *stream, struct lb_memory *mem, /* Verify the loaded image */ if (!verify_loaded_image(cb_chain, ehdr, phdr, &head)) goto out; -/* - */ printk_info("verified segments\n"); /* Shutdown the stream device */ @@ -626,7 +624,7 @@ int elfboot(struct stream *stream, struct lb_memory *mem) for(i = 0; i < ELF_HEAD_SIZE - (sizeof(Elf_ehdr) + sizeof(Elf_phdr)); i+=16) { ehdr = (Elf_ehdr *)(&header[i]); if (memcmp(ehdr->e_ident, ELFMAG, 4) != 0) { - printk_debug("NO header at %d\n", i); + printk_spew("NO header at %d\n", i); continue; } printk_debug("Found ELF candiate at offset %d\n", i); @@ -645,12 +643,12 @@ int elfboot(struct stream *stream, struct lb_memory *mem) } ehdr = 0; } - printk_debug("header_offset is %d\n", header_offset); + printk_spew("header_offset is %d\n", header_offset); if (header_offset == -1) { goto out; } - printk_debug("Try to load at offset 0x%x\n", header_offset); + printk_spew("Try to load at offset 0x%x\n", header_offset); result = elfload(stream, mem, header + header_offset , ELF_HEAD_SIZE - header_offset); out: diff --git a/src/lib/inflate.c b/src/lib/inflate.c index 707ce8339f..36af6b6e7c 100644 --- a/src/lib/inflate.c +++ b/src/lib/inflate.c @@ -1097,9 +1097,9 @@ int gunzip(void) return -1; } (ulg)get_byte(); /* Get timestamp */ - ((ulg)get_byte());// << 8; - ((ulg)get_byte());// << 16; - ((ulg)get_byte());// << 24; + ((ulg)get_byte()) << 8; + ((ulg)get_byte()) << 16; + ((ulg)get_byte()) << 24; (void)get_byte(); /* Ignore extra flags for the moment */ (void)get_byte(); /* Ignore OS type for the moment */ diff --git a/src/lib/linuxpci.c b/src/lib/linuxpci.c index b9e07d1c4c..7c767f4f0d 100644 --- a/src/lib/linuxpci.c +++ b/src/lib/linuxpci.c @@ -23,8 +23,7 @@ static char rcsid[] = "$Id$"; #include #include -// yes we could do Yet Another Include File, but ... -int sprintf(char * buf, const char *fmt, ...); + /** * This is the root of the PCI tree. A PCI tree always has @@ -119,7 +118,7 @@ void pci_set_master(struct pci_dev *dev) */ static void pci_get_resource(struct pci_dev *dev, struct resource *resource, unsigned long index) { - uint32_t addr, size; + uint32_t addr, size, base; unsigned long type; /* Initialize the resources to nothing */ @@ -143,6 +142,10 @@ static void pci_get_resource(struct pci_dev *dev, struct resource *resource, uns pci_write_config_dword(dev, index, ~0); pci_read_config_dword(dev, index, &size); + /* get the minimum value the bar can be set to */ + pci_write_config_dword(dev, index, 0); + pci_read_config_dword(dev, index, &base); + /* restore addr */ pci_write_config_dword(dev, index, addr); @@ -157,7 +160,7 @@ static void pci_get_resource(struct pci_dev *dev, struct resource *resource, uns * This incidentally catches the common case where registers * read back as 0 for both address and size. */ - if (addr == size) { + if ((addr == size) && (addr == base)) { if (size != 0) { printk_debug( "PCI: %02x:%02x.%01x register %02x(%08x), read-only ignoring it\n", @@ -318,7 +321,7 @@ static void pci_bus_read_resources(struct pci_dev *dev) static void pci_set_resource(struct pci_dev *dev, struct resource *resource) { unsigned long base, limit; - unsigned long bridge_align = MEM_BRIDGE_ALIGN; // stupid warnings. + unsigned long bridge_align = MEM_BRIDGE_ALIGN; unsigned char buf[10]; /* Make certain the resource has actually been set */ @@ -447,14 +450,6 @@ static void pci_dev_set_resources(struct pci_dev *dev) pci_write_config_byte(dev, PCI_CACHE_LINE_SIZE, 64 >> 2); } - -// probably dead. -#if 0 -static void pci_noop(struct pci_dev *dev) -{ - return; -} -#endif struct pci_dev_operations default_pci_ops_dev = { .read_resources = pci_dev_read_resources, .set_resources = pci_dev_set_resources, @@ -483,7 +478,6 @@ static void set_pci_ops(struct pci_dev *dev) break; } } -#warning set_pci_dev_ops not yet finished /* If I don't have a specific driver use the default operations */ switch(dev->hdr_type & 0x7f) { /* header type */ case PCI_HEADER_TYPE_NORMAL: /* standard header */ diff --git a/src/lib/subr.c b/src/lib/subr.c index c11ed6196b..2d96ceed37 100644 --- a/src/lib/subr.c +++ b/src/lib/subr.c @@ -89,7 +89,7 @@ void error(char errmsg[]) */ void post_code(uint8_t value) { -#ifdef SERIAL_POST +#if SERIAL_POST unsigned long hi, lo; // DAMMIT! This just broke! //rdtsc(lo, hi);