static int isavga_suspend(device_t dev) { vga_softc_t *sc; int err, nbytes; sc = device_get_softc(dev); err = bus_generic_suspend(dev); if (err) return (err); /* Save the video state across the suspend. */ if (sc->state_buf != NULL) { free(sc->state_buf, M_TEMP); sc->state_buf = NULL; } nbytes = vidd_save_state(sc->adp, NULL, 0); if (nbytes <= 0) return (0); sc->state_buf = malloc(nbytes, M_TEMP, M_NOWAIT | M_ZERO); if (sc->state_buf == NULL) return (0); if (bootverbose) device_printf(dev, "saving %d bytes of video state\n", nbytes); if (vidd_save_state(sc->adp, sc->state_buf, nbytes) != 0) { device_printf(dev, "failed to save state (nbytes=%d)\n", nbytes); free(sc->state_buf, M_TEMP); sc->state_buf = NULL; } return (0); }
static void vga_suspend(device_t dev) { vga_softc_t *sc; int nbytes; sc = device_get_softc(dev); /* Save the video state across the suspend. */ if (sc->state_buf != NULL) goto save_palette; nbytes = vidd_save_state(sc->adp, NULL, 0); if (nbytes <= 0) goto save_palette; sc->state_buf = malloc(nbytes, M_TEMP, M_NOWAIT); if (sc->state_buf == NULL) goto save_palette; if (bootverbose) device_printf(dev, "saving %d bytes of video state\n", nbytes); if (vidd_save_state(sc->adp, sc->state_buf, nbytes) != 0) { device_printf(dev, "failed to save state (nbytes=%d)\n", nbytes); free(sc->state_buf, M_TEMP); sc->state_buf = NULL; } save_palette: /* Save the color palette across the suspend. */ if (sc->pal_buf != NULL) return; sc->pal_buf = malloc(256 * 3, M_TEMP, M_NOWAIT); if (sc->pal_buf == NULL) return; if (bootverbose) device_printf(dev, "saving color palette\n"); if (vidd_save_palette(sc->adp, sc->pal_buf) != 0) { device_printf(dev, "failed to save palette\n"); free(sc->pal_buf, M_TEMP); sc->pal_buf = NULL; } }