diff options
author | Theo de Raadt <deraadt@cvs.openbsd.org> | 2004-11-22 04:14:19 +0000 |
---|---|---|
committer | Theo de Raadt <deraadt@cvs.openbsd.org> | 2004-11-22 04:14:19 +0000 |
commit | 6ee6acfa8168c437f5ad8391f65ad242f602f948 (patch) | |
tree | 234c9d50734dbd3d751ddb92d4018377e7ea7e40 /sys | |
parent | fd1bca9f1c86cc5219219f16e78d6a1e89827c14 (diff) |
build a tigon firmware file. Saves 150KB or so in GENERIC kernels
Diffstat (limited to 'sys')
-rw-r--r-- | sys/dev/microcode/tigon/Makefile | 25 | ||||
-rw-r--r-- | sys/dev/microcode/tigon/build.c | 116 | ||||
-rw-r--r-- | sys/dev/pci/if_ti.c | 81 |
3 files changed, 178 insertions, 44 deletions
diff --git a/sys/dev/microcode/tigon/Makefile b/sys/dev/microcode/tigon/Makefile new file mode 100644 index 00000000000..56a42b4d599 --- /dev/null +++ b/sys/dev/microcode/tigon/Makefile @@ -0,0 +1,25 @@ +# $OpenBSD: Makefile,v 1.1 2004/11/22 04:14:18 deraadt Exp $ + +NOPROG= +NOMAN= + +# PCI capable systems only +.if (${MACHINE} == "i386") || (${MACHINE} == "amd64") || \ + (${MACHINE} == "alpha") || (${MACHINE} == "sparc64") || \ + (${MACHINE_ARCH} == "powerpc") || (${MACHINE} == "cats") || \ + (${MACHINE} == "hppa") || (${MACHINE} == "sgi") + +FIRM= tigon1 tigon2 + +CLEANFILES+= ${FIRM} build + +all: build + ${.OBJDIR}/build + +afterinstall: + ${INSTALL} -c -o ${BINOWN} -g ${BINGRP} -m 644 \ + ${FIRM} ${DESTDIR}/etc/firmware +.endif + +.include <bsd.prog.mk> + diff --git a/sys/dev/microcode/tigon/build.c b/sys/dev/microcode/tigon/build.c new file mode 100644 index 00000000000..d7082b6975b --- /dev/null +++ b/sys/dev/microcode/tigon/build.c @@ -0,0 +1,116 @@ +/* $OpenBSD: build.c,v 1.1 2004/11/22 04:14:18 deraadt Exp $ */ + +/* + * Copyright (c) 2004 Theo de Raadt <deraadt@openbsd.org> + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ +#include <sys/types.h> +#include <dev/pci/if_tivar.h> +#include <fcntl.h> + +#include "ti_fw.h" +#include "ti_fw2.h" + +static void +output(const char *name, + const int FwReleaseMajor, const int FwReleaseMinor, + const int FwReleaseFix, const u_int32_t FwStartAddr, + const u_int32_t FwTextAddr, const int FwTextLen, + const u_int32_t FwRodataAddr, const int FwRodataLen, + const u_int32_t FwDataAddr, const int FwDataLen, + const u_int32_t FwSbssAddr, const int FwSbssLen, + const u_int32_t FwBssAddr, const int FwBssLen, + const u_int32_t *FwText, int sizetext, + const u_int32_t *FwRodata, int sizerodata, + const u_int32_t *FwData, int sizedata) +{ + struct tigon_firmware tfproto, *tf; + int len, fd, i; + + len = sizeof tf - sizeof(tfproto.data) + sizetext + sizerodata + + sizedata; + tf = (struct tigon_firmware *)malloc(len); + bzero(tf, len); + + tf->FwReleaseMajor = FwReleaseMajor; + tf->FwReleaseMinor = FwReleaseMinor; + tf->FwReleaseFix = FwReleaseFix; + tf->FwStartAddr = FwStartAddr; + + tf->FwTextAddr = FwTextAddr; + tf->FwTextLen = FwTextLen; + + tf->FwRodataAddr = FwRodataAddr; + tf->FwRodataLen = FwRodataLen; + + tf->FwDataAddr = FwDataAddr; + tf->FwDataLen = FwDataLen; + + tf->FwSbssAddr = FwSbssAddr; + tf->FwSbssLen = FwSbssLen; + + tf->FwBssAddr = FwBssAddr; + tf->FwBssLen = FwBssLen; + + tf->FwTextOffset = 0; + tf->FwRodataOffset = sizetext; + tf->FwDataOffset = sizetext + sizerodata; + + bcopy(FwText, &tf->data[tf->FwTextOffset], FwTextLen); + bcopy(FwRodata, &tf->data[tf->FwRodataOffset], FwRodataLen); + bcopy(FwData, &tf->data[tf->FwDataOffset], FwDataLen); + + printf("creating %s length %d [%d+%d+%d] [%d+%d+%d]\n", + name, len, FwTextLen, FwRodataLen, FwDataLen, + sizetext, sizerodata, sizedata); + fd = open(name, O_WRONLY|O_CREAT|O_TRUNC, 0644); + if (fd == -1) + err(1, "%s", name); + + write(fd, tf, len); + free(tf); + close(fd); +} + + +int +main(int argc, char *argv[]) +{ + + output("tigon1", + tigonFwReleaseMajor, tigonFwReleaseMinor, + tigonFwReleaseFix, tigonFwStartAddr, + tigonFwTextAddr, tigonFwTextLen, + tigonFwRodataAddr, tigonFwRodataLen, + tigonFwDataAddr, tigonFwDataLen, + tigonFwSbssAddr, tigonFwSbssLen, + tigonFwBssAddr, tigonFwBssLen, + tigonFwText, sizeof tigonFwText, + tigonFwRodata, sizeof tigonFwRodata, + tigonFwData, sizeof tigonFwData); + + output("tigon2", + tigon2FwReleaseMajor, tigon2FwReleaseMinor, + tigon2FwReleaseFix, tigon2FwStartAddr, + tigon2FwTextAddr, tigon2FwTextLen, + tigon2FwRodataAddr, tigon2FwRodataLen, + tigon2FwDataAddr, tigon2FwDataLen, + tigon2FwSbssAddr, tigon2FwSbssLen, + tigon2FwBssAddr, tigon2FwBssLen, + tigon2FwText, sizeof tigon2FwText, + tigon2FwRodata, sizeof tigon2FwRodata, + tigon2FwData, sizeof tigon2FwData); + + return 0; +} diff --git a/sys/dev/pci/if_ti.c b/sys/dev/pci/if_ti.c index 7bfa0533c02..c3ba3275af1 100644 --- a/sys/dev/pci/if_ti.c +++ b/sys/dev/pci/if_ti.c @@ -1,4 +1,4 @@ -/* $OpenBSD: if_ti.c,v 1.56 2004/09/23 17:45:16 brad Exp $ */ +/* $OpenBSD: if_ti.c,v 1.57 2004/11/22 04:14:17 deraadt Exp $ */ /* * Copyright (c) 1997, 1998, 1999 @@ -121,8 +121,7 @@ #include <dev/pci/pcidevs.h> #include <dev/pci/if_tireg.h> -#include <dev/microcode/tigon/ti_fw.h> -#include <dev/microcode/tigon/ti_fw2.h> +#include <dev/pci/if_tivar.h> #ifdef M_HWCKSUM /*#define TI_CSUM_OFFLOAD*/ @@ -425,56 +424,50 @@ void ti_mem_set(sc, addr, len) void ti_loadfw(sc) struct ti_softc *sc; { + struct tigon_firmware *tf; + u_char *buf = NULL; + size_t buflen; + char *name; + int error; + switch(sc->ti_hwrev) { case TI_HWREV_TIGON: - if (tigonFwReleaseMajor != TI_FIRMWARE_MAJOR || - tigonFwReleaseMinor != TI_FIRMWARE_MINOR || - tigonFwReleaseFix != TI_FIRMWARE_FIX) { - printf("%s: firmware revision mismatch; want " - "%d.%d.%d, got %d.%d.%d\n", sc->sc_dv.dv_xname, - TI_FIRMWARE_MAJOR, TI_FIRMWARE_MINOR, - TI_FIRMWARE_FIX, tigonFwReleaseMajor, - tigonFwReleaseMinor, tigonFwReleaseFix); - return; - } - ti_mem_write(sc, tigonFwTextAddr, tigonFwTextLen, - (caddr_t)tigonFwText); - ti_mem_write(sc, tigonFwDataAddr, tigonFwDataLen, - (caddr_t)tigonFwData); - ti_mem_write(sc, tigonFwRodataAddr, tigonFwRodataLen, - (caddr_t)tigonFwRodata); - ti_mem_set(sc, tigonFwBssAddr, tigonFwBssLen); - ti_mem_set(sc, tigonFwSbssAddr, tigonFwSbssLen); - CSR_WRITE_4(sc, TI_CPU_PROGRAM_COUNTER, tigonFwStartAddr); + name = "tigon1"; break; case TI_HWREV_TIGON_II: - if (tigon2FwReleaseMajor != TI_FIRMWARE_MAJOR || - tigon2FwReleaseMinor != TI_FIRMWARE_MINOR || - tigon2FwReleaseFix != TI_FIRMWARE_FIX) { - printf("%s: firmware revision mismatch; want " - "%d.%d.%d, got %d.%d.%d\n", sc->sc_dv.dv_xname, - TI_FIRMWARE_MAJOR, TI_FIRMWARE_MINOR, - TI_FIRMWARE_FIX, tigon2FwReleaseMajor, - tigon2FwReleaseMinor, tigon2FwReleaseFix); - return; - } - ti_mem_write(sc, tigon2FwTextAddr, tigon2FwTextLen, - (caddr_t)tigon2FwText); - ti_mem_write(sc, tigon2FwDataAddr, tigon2FwDataLen, - (caddr_t)tigon2FwData); - ti_mem_write(sc, tigon2FwRodataAddr, tigon2FwRodataLen, - (caddr_t)tigon2FwRodata); - ti_mem_set(sc, tigon2FwBssAddr, tigon2FwBssLen); - ti_mem_set(sc, tigon2FwSbssAddr, tigon2FwSbssLen); - CSR_WRITE_4(sc, TI_CPU_PROGRAM_COUNTER, tigon2FwStartAddr); + name = "tigon2"; break; default: printf("%s: can't load firmware: unknown hardware rev\n", sc->sc_dv.dv_xname); - break; + return; } - - return; + + error = loadfirmware(name, &buf, &buflen); + if (error) + return; + tf = (struct tigon_firmware *)buf; + if (tf->FwReleaseMajor != TI_FIRMWARE_MAJOR || + tf->FwReleaseMinor != TI_FIRMWARE_MINOR || + tf->FwReleaseFix != TI_FIRMWARE_FIX) { + printf("%s: firmware revision mismatch; want " + "%d.%d.%d, got %d.%d.%d\n", sc->sc_dv.dv_xname, + TI_FIRMWARE_MAJOR, TI_FIRMWARE_MINOR, + TI_FIRMWARE_FIX, tf->FwReleaseMajor, + tf->FwReleaseMinor, tf->FwReleaseFix); + free(buf, M_DEVBUF); + return; + } + ti_mem_write(sc, tf->FwTextAddr, tf->FwTextLen, + (caddr_t)&tf->data[tf->FwTextOffset]); + ti_mem_write(sc, tf->FwRodataAddr, tf->FwRodataLen, + (caddr_t)&tf->data[tf->FwRodataOffset]); + ti_mem_write(sc, tf->FwDataAddr, tf->FwDataLen, + (caddr_t)&tf->data[tf->FwDataOffset]); + ti_mem_set(sc, tf->FwBssAddr, tf->FwBssLen); + ti_mem_set(sc, tf->FwSbssAddr, tf->FwSbssLen); + CSR_WRITE_4(sc, TI_CPU_PROGRAM_COUNTER, tf->FwStartAddr); + free(buf, M_DEVBUF); } /* |