Index: stable/8/sys/amd64/include/xen =================================================================== --- stable/8/sys/amd64/include/xen (revision 208450) +++ stable/8/sys/amd64/include/xen (revision 208451) Property changes on: stable/8/sys/amd64/include/xen ___________________________________________________________________ Modified: svn:mergeinfo ## -0,0 +0,1 ## Merged /head/sys/amd64/include/xen:r208349 Index: stable/8/sys/cam/ata/ata_da.c =================================================================== --- stable/8/sys/cam/ata/ata_da.c (revision 208450) +++ stable/8/sys/cam/ata/ata_da.c (revision 208451) @@ -1,1218 +1,1227 @@ /*- * Copyright (c) 2009 Alexander Motin * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer, * without modification, immediately at the beginning of the file. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include __FBSDID("$FreeBSD$"); #include #ifdef _KERNEL #include #include #include #include #include #include #include #include #include #include #include #include #include #endif /* _KERNEL */ #ifndef _KERNEL #include #include #endif /* _KERNEL */ #include #include #include #include #include #include +#include /* geometry translation */ + #ifdef _KERNEL #define ATA_MAX_28BIT_LBA 268435455UL typedef enum { ADA_STATE_NORMAL } ada_state; typedef enum { ADA_FLAG_PACK_INVALID = 0x001, ADA_FLAG_CAN_48BIT = 0x002, ADA_FLAG_CAN_FLUSHCACHE = 0x004, ADA_FLAG_CAN_NCQ = 0x008, ADA_FLAG_CAN_DMA = 0x010, ADA_FLAG_NEED_OTAG = 0x020, ADA_FLAG_WENT_IDLE = 0x040, ADA_FLAG_CAN_TRIM = 0x080, ADA_FLAG_OPEN = 0x100, ADA_FLAG_SCTX_INIT = 0x200, ADA_FLAG_CAN_CFA = 0x400 } ada_flags; typedef enum { ADA_Q_NONE = 0x00 } ada_quirks; typedef enum { ADA_CCB_BUFFER_IO = 0x03, ADA_CCB_WAITING = 0x04, ADA_CCB_DUMP = 0x05, ADA_CCB_TRIM = 0x06, ADA_CCB_TYPE_MASK = 0x0F, } ada_ccb_state; /* Offsets into our private area for storing information */ #define ccb_state ppriv_field0 #define ccb_bp ppriv_ptr1 struct disk_params { u_int8_t heads; u_int8_t secs_per_track; u_int32_t cylinders; u_int32_t secsize; /* Number of bytes/logical sector */ u_int64_t sectors; /* Total number sectors */ }; #define TRIM_MAX_BLOCKS 4 #define TRIM_MAX_RANGES TRIM_MAX_BLOCKS * 64 struct trim_request { uint8_t data[TRIM_MAX_RANGES * 8]; struct bio *bps[TRIM_MAX_RANGES]; }; struct ada_softc { struct bio_queue_head bio_queue; struct bio_queue_head trim_queue; ada_state state; ada_flags flags; ada_quirks quirks; int ordered_tag_count; int outstanding_cmds; int trim_max_ranges; int trim_running; struct disk_params params; struct disk *disk; struct task sysctl_task; struct sysctl_ctx_list sysctl_ctx; struct sysctl_oid *sysctl_tree; struct callout sendordered_c; struct trim_request trim_req; }; struct ada_quirk_entry { struct scsi_inquiry_pattern inq_pat; ada_quirks quirks; }; static struct ada_quirk_entry ada_quirk_table[] = { { /* Default */ { T_ANY, SIP_MEDIA_REMOVABLE|SIP_MEDIA_FIXED, /*vendor*/"*", /*product*/"*", /*revision*/"*" }, /*quirks*/0 }, }; static disk_strategy_t adastrategy; static dumper_t adadump; static periph_init_t adainit; static void adaasync(void *callback_arg, u_int32_t code, struct cam_path *path, void *arg); static void adasysctlinit(void *context, int pending); static periph_ctor_t adaregister; static periph_dtor_t adacleanup; static periph_start_t adastart; static periph_oninv_t adaoninvalidate; static void adadone(struct cam_periph *periph, union ccb *done_ccb); static int adaerror(union ccb *ccb, u_int32_t cam_flags, u_int32_t sense_flags); static void adagetparams(struct cam_periph *periph, struct ccb_getdev *cgd); static timeout_t adasendorderedtag; static void adashutdown(void *arg, int howto); #ifndef ADA_DEFAULT_TIMEOUT #define ADA_DEFAULT_TIMEOUT 30 /* Timeout in seconds */ #endif #ifndef ADA_DEFAULT_RETRY #define ADA_DEFAULT_RETRY 4 #endif #ifndef ADA_DEFAULT_SEND_ORDERED #define ADA_DEFAULT_SEND_ORDERED 1 #endif +/* + * Most platforms map firmware geometry to actual, but some don't. If + * not overridden, default to nothing. + */ +#ifndef ata_disk_firmware_geom_adjust +#define ata_disk_firmware_geom_adjust(disk) +#endif static int ada_retry_count = ADA_DEFAULT_RETRY; static int ada_default_timeout = ADA_DEFAULT_TIMEOUT; static int ada_send_ordered = ADA_DEFAULT_SEND_ORDERED; SYSCTL_NODE(_kern_cam, OID_AUTO, ada, CTLFLAG_RD, 0, "CAM Direct Access Disk driver"); SYSCTL_INT(_kern_cam_ada, OID_AUTO, retry_count, CTLFLAG_RW, &ada_retry_count, 0, "Normal I/O retry count"); TUNABLE_INT("kern.cam.ada.retry_count", &ada_retry_count); SYSCTL_INT(_kern_cam_ada, OID_AUTO, default_timeout, CTLFLAG_RW, &ada_default_timeout, 0, "Normal I/O timeout (in seconds)"); TUNABLE_INT("kern.cam.ada.default_timeout", &ada_default_timeout); SYSCTL_INT(_kern_cam_ada, OID_AUTO, ada_send_ordered, CTLFLAG_RW, &ada_send_ordered, 0, "Send Ordered Tags"); TUNABLE_INT("kern.cam.ada.ada_send_ordered", &ada_send_ordered); /* * ADA_ORDEREDTAG_INTERVAL determines how often, relative * to the default timeout, we check to see whether an ordered * tagged transaction is appropriate to prevent simple tag * starvation. Since we'd like to ensure that there is at least * 1/2 of the timeout length left for a starved transaction to * complete after we've sent an ordered tag, we must poll at least * four times in every timeout period. This takes care of the worst * case where a starved transaction starts during an interval that * meets the requirement "don't send an ordered tag" test so it takes * us two intervals to determine that a tag must be sent. */ #ifndef ADA_ORDEREDTAG_INTERVAL #define ADA_ORDEREDTAG_INTERVAL 4 #endif static struct periph_driver adadriver = { adainit, "ada", TAILQ_HEAD_INITIALIZER(adadriver.units), /* generation */ 0 }; PERIPHDRIVER_DECLARE(ada, adadriver); MALLOC_DEFINE(M_ATADA, "ata_da", "ata_da buffers"); static int adaopen(struct disk *dp) { struct cam_periph *periph; struct ada_softc *softc; int unit; int error; periph = (struct cam_periph *)dp->d_drv1; if (periph == NULL) { return (ENXIO); } if (cam_periph_acquire(periph) != CAM_REQ_CMP) { return(ENXIO); } cam_periph_lock(periph); if ((error = cam_periph_hold(periph, PRIBIO|PCATCH)) != 0) { cam_periph_unlock(periph); cam_periph_release(periph); return (error); } unit = periph->unit_number; softc = (struct ada_softc *)periph->softc; softc->flags |= ADA_FLAG_OPEN; CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("adaopen: disk=%s%d (unit %d)\n", dp->d_name, dp->d_unit, unit)); if ((softc->flags & ADA_FLAG_PACK_INVALID) != 0) { /* Invalidate our pack information. */ softc->flags &= ~ADA_FLAG_PACK_INVALID; } cam_periph_unhold(periph); cam_periph_unlock(periph); return (0); } static int adaclose(struct disk *dp) { struct cam_periph *periph; struct ada_softc *softc; union ccb *ccb; int error; periph = (struct cam_periph *)dp->d_drv1; if (periph == NULL) return (ENXIO); cam_periph_lock(periph); if ((error = cam_periph_hold(periph, PRIBIO)) != 0) { cam_periph_unlock(periph); cam_periph_release(periph); return (error); } softc = (struct ada_softc *)periph->softc; /* We only sync the cache if the drive is capable of it. */ if (softc->flags & ADA_FLAG_CAN_FLUSHCACHE) { ccb = cam_periph_getccb(periph, CAM_PRIORITY_NORMAL); cam_fill_ataio(&ccb->ataio, 1, adadone, CAM_DIR_NONE, 0, NULL, 0, ada_default_timeout*1000); if (softc->flags & ADA_FLAG_CAN_48BIT) ata_48bit_cmd(&ccb->ataio, ATA_FLUSHCACHE48, 0, 0, 0); else ata_28bit_cmd(&ccb->ataio, ATA_FLUSHCACHE, 0, 0, 0); cam_periph_runccb(ccb, /*error_routine*/NULL, /*cam_flags*/0, /*sense_flags*/0, softc->disk->d_devstat); if ((ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) xpt_print(periph->path, "Synchronize cache failed\n"); if ((ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) cam_release_devq(ccb->ccb_h.path, /*relsim_flags*/0, /*reduction*/0, /*timeout*/0, /*getcount_only*/0); xpt_release_ccb(ccb); } softc->flags &= ~ADA_FLAG_OPEN; cam_periph_unhold(periph); cam_periph_unlock(periph); cam_periph_release(periph); return (0); } static void adaschedule(struct cam_periph *periph) { struct ada_softc *softc = (struct ada_softc *)periph->softc; if (bioq_first(&softc->bio_queue) || (!softc->trim_running && bioq_first(&softc->trim_queue))) { /* Have more work to do, so ensure we stay scheduled */ xpt_schedule(periph, CAM_PRIORITY_NORMAL); } } /* * Actually translate the requested transfer into one the physical driver * can understand. The transfer is described by a buf and will include * only one physical transfer. */ static void adastrategy(struct bio *bp) { struct cam_periph *periph; struct ada_softc *softc; periph = (struct cam_periph *)bp->bio_disk->d_drv1; if (periph == NULL) { biofinish(bp, NULL, ENXIO); return; } softc = (struct ada_softc *)periph->softc; cam_periph_lock(periph); /* * If the device has been made invalid, error out */ if ((softc->flags & ADA_FLAG_PACK_INVALID)) { cam_periph_unlock(periph); biofinish(bp, NULL, ENXIO); return; } /* * Place it in the queue of disk activities for this disk */ if (bp->bio_cmd == BIO_DELETE && (softc->flags & ADA_FLAG_CAN_TRIM)) bioq_disksort(&softc->trim_queue, bp); else bioq_disksort(&softc->bio_queue, bp); /* * Schedule ourselves for performing the work. */ adaschedule(periph); cam_periph_unlock(periph); return; } static int adadump(void *arg, void *virtual, vm_offset_t physical, off_t offset, size_t length) { struct cam_periph *periph; struct ada_softc *softc; u_int secsize; union ccb ccb; struct disk *dp; uint64_t lba; uint16_t count; dp = arg; periph = dp->d_drv1; if (periph == NULL) return (ENXIO); softc = (struct ada_softc *)periph->softc; cam_periph_lock(periph); secsize = softc->params.secsize; lba = offset / secsize; count = length / secsize; if ((softc->flags & ADA_FLAG_PACK_INVALID) != 0) { cam_periph_unlock(periph); return (ENXIO); } if (length > 0) { xpt_setup_ccb(&ccb.ccb_h, periph->path, CAM_PRIORITY_NORMAL); ccb.ccb_h.ccb_state = ADA_CCB_DUMP; cam_fill_ataio(&ccb.ataio, 0, adadone, CAM_DIR_OUT, 0, (u_int8_t *) virtual, length, ada_default_timeout*1000); if ((softc->flags & ADA_FLAG_CAN_48BIT) && (lba + count >= ATA_MAX_28BIT_LBA || count >= 256)) { ata_48bit_cmd(&ccb.ataio, ATA_WRITE_DMA48, 0, lba, count); } else { ata_28bit_cmd(&ccb.ataio, ATA_WRITE_DMA, 0, lba, count); } xpt_polled_action(&ccb); if ((ccb.ataio.ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) { printf("Aborting dump due to I/O error.\n"); cam_periph_unlock(periph); return(EIO); } cam_periph_unlock(periph); return(0); } if (softc->flags & ADA_FLAG_CAN_FLUSHCACHE) { xpt_setup_ccb(&ccb.ccb_h, periph->path, CAM_PRIORITY_NORMAL); ccb.ccb_h.ccb_state = ADA_CCB_DUMP; cam_fill_ataio(&ccb.ataio, 1, adadone, CAM_DIR_NONE, 0, NULL, 0, ada_default_timeout*1000); if (softc->flags & ADA_FLAG_CAN_48BIT) ata_48bit_cmd(&ccb.ataio, ATA_FLUSHCACHE48, 0, 0, 0); else ata_28bit_cmd(&ccb.ataio, ATA_FLUSHCACHE, 0, 0, 0); xpt_polled_action(&ccb); if ((ccb.ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) xpt_print(periph->path, "Synchronize cache failed\n"); if ((ccb.ccb_h.status & CAM_DEV_QFRZN) != 0) cam_release_devq(ccb.ccb_h.path, /*relsim_flags*/0, /*reduction*/0, /*timeout*/0, /*getcount_only*/0); } cam_periph_unlock(periph); return (0); } static void adainit(void) { cam_status status; /* * Install a global async callback. This callback will * receive async callbacks like "new device found". */ status = xpt_register_async(AC_FOUND_DEVICE, adaasync, NULL, NULL); if (status != CAM_REQ_CMP) { printf("ada: Failed to attach master async callback " "due to status 0x%x!\n", status); } else if (ada_send_ordered) { /* Register our shutdown event handler */ if ((EVENTHANDLER_REGISTER(shutdown_post_sync, adashutdown, NULL, SHUTDOWN_PRI_DEFAULT)) == NULL) printf("adainit: shutdown event registration failed!\n"); } } static void adaoninvalidate(struct cam_periph *periph) { struct ada_softc *softc; softc = (struct ada_softc *)periph->softc; /* * De-register any async callbacks. */ xpt_register_async(0, adaasync, periph, periph->path); softc->flags |= ADA_FLAG_PACK_INVALID; /* * Return all queued I/O with ENXIO. * XXX Handle any transactions queued to the card * with XPT_ABORT_CCB. */ bioq_flush(&softc->bio_queue, NULL, ENXIO); bioq_flush(&softc->trim_queue, NULL, ENXIO); disk_gone(softc->disk); xpt_print(periph->path, "lost device\n"); } static void adacleanup(struct cam_periph *periph) { struct ada_softc *softc; softc = (struct ada_softc *)periph->softc; xpt_print(periph->path, "removing device entry\n"); cam_periph_unlock(periph); /* * If we can't free the sysctl tree, oh well... */ if ((softc->flags & ADA_FLAG_SCTX_INIT) != 0 && sysctl_ctx_free(&softc->sysctl_ctx) != 0) { xpt_print(periph->path, "can't remove sysctl context\n"); } disk_destroy(softc->disk); callout_drain(&softc->sendordered_c); free(softc, M_DEVBUF); cam_periph_lock(periph); } static void adaasync(void *callback_arg, u_int32_t code, struct cam_path *path, void *arg) { struct cam_periph *periph; periph = (struct cam_periph *)callback_arg; switch (code) { case AC_FOUND_DEVICE: { struct ccb_getdev *cgd; cam_status status; cgd = (struct ccb_getdev *)arg; if (cgd == NULL) break; if (cgd->protocol != PROTO_ATA) break; /* * Allocate a peripheral instance for * this device and start the probe * process. */ status = cam_periph_alloc(adaregister, adaoninvalidate, adacleanup, adastart, "ada", CAM_PERIPH_BIO, cgd->ccb_h.path, adaasync, AC_FOUND_DEVICE, cgd); if (status != CAM_REQ_CMP && status != CAM_REQ_INPROG) printf("adaasync: Unable to attach to new device " "due to status 0x%x\n", status); break; } default: cam_periph_async(periph, code, path, arg); break; } } static void adasysctlinit(void *context, int pending) { struct cam_periph *periph; struct ada_softc *softc; char tmpstr[80], tmpstr2[80]; periph = (struct cam_periph *)context; if (cam_periph_acquire(periph) != CAM_REQ_CMP) return; softc = (struct ada_softc *)periph->softc; snprintf(tmpstr, sizeof(tmpstr), "CAM ADA unit %d", periph->unit_number); snprintf(tmpstr2, sizeof(tmpstr2), "%d", periph->unit_number); sysctl_ctx_init(&softc->sysctl_ctx); softc->flags |= ADA_FLAG_SCTX_INIT; softc->sysctl_tree = SYSCTL_ADD_NODE(&softc->sysctl_ctx, SYSCTL_STATIC_CHILDREN(_kern_cam_ada), OID_AUTO, tmpstr2, CTLFLAG_RD, 0, tmpstr); if (softc->sysctl_tree == NULL) { printf("adasysctlinit: unable to allocate sysctl tree\n"); cam_periph_release(periph); return; } cam_periph_release(periph); } static cam_status adaregister(struct cam_periph *periph, void *arg) { struct ada_softc *softc; struct ccb_pathinq cpi; struct ccb_getdev *cgd; char announce_buf[80]; struct disk_params *dp; caddr_t match; u_int maxio; cgd = (struct ccb_getdev *)arg; if (periph == NULL) { printf("adaregister: periph was NULL!!\n"); return(CAM_REQ_CMP_ERR); } if (cgd == NULL) { printf("adaregister: no getdev CCB, can't register device\n"); return(CAM_REQ_CMP_ERR); } softc = (struct ada_softc *)malloc(sizeof(*softc), M_DEVBUF, M_NOWAIT|M_ZERO); if (softc == NULL) { printf("adaregister: Unable to probe new device. " "Unable to allocate softc\n"); return(CAM_REQ_CMP_ERR); } bioq_init(&softc->bio_queue); bioq_init(&softc->trim_queue); if (cgd->ident_data.capabilities1 & ATA_SUPPORT_DMA) softc->flags |= ADA_FLAG_CAN_DMA; if (cgd->ident_data.support.command2 & ATA_SUPPORT_ADDRESS48) softc->flags |= ADA_FLAG_CAN_48BIT; if (cgd->ident_data.support.command2 & ATA_SUPPORT_FLUSHCACHE) softc->flags |= ADA_FLAG_CAN_FLUSHCACHE; if (cgd->ident_data.satacapabilities & ATA_SUPPORT_NCQ && cgd->inq_flags & SID_CmdQue) softc->flags |= ADA_FLAG_CAN_NCQ; if (cgd->ident_data.support_dsm & ATA_SUPPORT_DSM_TRIM) { softc->flags |= ADA_FLAG_CAN_TRIM; softc->trim_max_ranges = TRIM_MAX_RANGES; if (cgd->ident_data.max_dsm_blocks != 0) { softc->trim_max_ranges = min(cgd->ident_data.max_dsm_blocks * 64, softc->trim_max_ranges); } } if (cgd->ident_data.support.command2 & ATA_SUPPORT_CFA) softc->flags |= ADA_FLAG_CAN_CFA; softc->state = ADA_STATE_NORMAL; periph->softc = softc; /* * See if this device has any quirks. */ match = cam_quirkmatch((caddr_t)&cgd->ident_data, (caddr_t)ada_quirk_table, sizeof(ada_quirk_table)/sizeof(*ada_quirk_table), sizeof(*ada_quirk_table), ata_identify_match); if (match != NULL) softc->quirks = ((struct ada_quirk_entry *)match)->quirks; else softc->quirks = ADA_Q_NONE; bzero(&cpi, sizeof(cpi)); xpt_setup_ccb(&cpi.ccb_h, periph->path, CAM_PRIORITY_NONE); cpi.ccb_h.func_code = XPT_PATH_INQ; xpt_action((union ccb *)&cpi); TASK_INIT(&softc->sysctl_task, 0, adasysctlinit, periph); /* * Register this media as a disk */ mtx_unlock(periph->sim->mtx); adagetparams(periph, cgd); softc->disk = disk_alloc(); softc->disk->d_open = adaopen; softc->disk->d_close = adaclose; softc->disk->d_strategy = adastrategy; softc->disk->d_dump = adadump; softc->disk->d_name = "ada"; softc->disk->d_drv1 = periph; maxio = cpi.maxio; /* Honor max I/O size of SIM */ if (maxio == 0) maxio = DFLTPHYS; /* traditional default */ else if (maxio > MAXPHYS) maxio = MAXPHYS; /* for safety */ if (softc->flags & ADA_FLAG_CAN_48BIT) maxio = min(maxio, 65536 * softc->params.secsize); else /* 28bit ATA command limit */ maxio = min(maxio, 256 * softc->params.secsize); softc->disk->d_maxsize = maxio; softc->disk->d_unit = periph->unit_number; softc->disk->d_flags = 0; if (softc->flags & ADA_FLAG_CAN_FLUSHCACHE) softc->disk->d_flags |= DISKFLAG_CANFLUSHCACHE; if ((softc->flags & ADA_FLAG_CAN_TRIM) || ((softc->flags & ADA_FLAG_CAN_CFA) && !(softc->flags & ADA_FLAG_CAN_48BIT))) softc->disk->d_flags |= DISKFLAG_CANDELETE; strlcpy(softc->disk->d_ident, cgd->serial_num, MIN(sizeof(softc->disk->d_ident), cgd->serial_num_len + 1)); softc->disk->d_sectorsize = softc->params.secsize; softc->disk->d_mediasize = (off_t)softc->params.sectors * softc->params.secsize; if (ata_physical_sector_size(&cgd->ident_data) != softc->params.secsize) { softc->disk->d_stripesize = ata_physical_sector_size(&cgd->ident_data); softc->disk->d_stripeoffset = (softc->disk->d_stripesize - ata_logical_sector_offset(&cgd->ident_data)) % softc->disk->d_stripesize; } - /* XXX: these are not actually "firmware" values, so they may be wrong */ softc->disk->d_fwsectors = softc->params.secs_per_track; softc->disk->d_fwheads = softc->params.heads; + ata_disk_firmware_geom_adjust(softc->disk); disk_create(softc->disk, DISK_VERSION); mtx_lock(periph->sim->mtx); dp = &softc->params; snprintf(announce_buf, sizeof(announce_buf), "%juMB (%ju %u byte sectors: %dH %dS/T %dC)", (uintmax_t)(((uintmax_t)dp->secsize * dp->sectors) / (1024*1024)), (uintmax_t)dp->sectors, dp->secsize, dp->heads, dp->secs_per_track, dp->cylinders); xpt_announce_periph(periph, announce_buf); /* * Add async callbacks for bus reset and * bus device reset calls. I don't bother * checking if this fails as, in most cases, * the system will function just fine without * them and the only alternative would be to * not attach the device on failure. */ xpt_register_async(AC_LOST_DEVICE, adaasync, periph, periph->path); /* * Schedule a periodic event to occasionally send an * ordered tag to a device. */ callout_init_mtx(&softc->sendordered_c, periph->sim->mtx, 0); callout_reset(&softc->sendordered_c, (ADA_DEFAULT_TIMEOUT * hz) / ADA_ORDEREDTAG_INTERVAL, adasendorderedtag, softc); return(CAM_REQ_CMP); } static void adastart(struct cam_periph *periph, union ccb *start_ccb) { struct ada_softc *softc = (struct ada_softc *)periph->softc; struct ccb_ataio *ataio = &start_ccb->ataio; switch (softc->state) { case ADA_STATE_NORMAL: { struct bio *bp; u_int8_t tag_code; /* Execute immediate CCB if waiting. */ if (periph->immediate_priority <= periph->pinfo.priority) { CAM_DEBUG_PRINT(CAM_DEBUG_SUBTRACE, ("queuing for immediate ccb\n")); start_ccb->ccb_h.ccb_state = ADA_CCB_WAITING; SLIST_INSERT_HEAD(&periph->ccb_list, &start_ccb->ccb_h, periph_links.sle); periph->immediate_priority = CAM_PRIORITY_NONE; wakeup(&periph->ccb_list); /* Have more work to do, so ensure we stay scheduled */ adaschedule(periph); break; } /* Run TRIM if not running yet. */ if (!softc->trim_running && (bp = bioq_first(&softc->trim_queue)) != 0) { struct trim_request *req = &softc->trim_req; struct bio *bp1; int bps = 0, ranges = 0; softc->trim_running = 1; bzero(req, sizeof(*req)); bp1 = bp; do { uint64_t lba = bp1->bio_pblkno; int count = bp1->bio_bcount / softc->params.secsize; bioq_remove(&softc->trim_queue, bp1); while (count > 0) { int c = min(count, 0xffff); int off = ranges * 8; req->data[off + 0] = lba & 0xff; req->data[off + 1] = (lba >> 8) & 0xff; req->data[off + 2] = (lba >> 16) & 0xff; req->data[off + 3] = (lba >> 24) & 0xff; req->data[off + 4] = (lba >> 32) & 0xff; req->data[off + 5] = (lba >> 40) & 0xff; req->data[off + 6] = c & 0xff; req->data[off + 7] = (c >> 8) & 0xff; lba += c; count -= c; ranges++; } req->bps[bps++] = bp1; bp1 = bioq_first(&softc->trim_queue); if (bp1 == NULL || bp1->bio_bcount / softc->params.secsize > (softc->trim_max_ranges - ranges) * 0xffff) break; } while (1); cam_fill_ataio(ataio, ada_retry_count, adadone, CAM_DIR_OUT, 0, req->data, ((ranges + 63) / 64) * 512, ada_default_timeout * 1000); ata_48bit_cmd(ataio, ATA_DATA_SET_MANAGEMENT, ATA_DSM_TRIM, 0, (ranges + 63) / 64); start_ccb->ccb_h.ccb_state = ADA_CCB_TRIM; goto out; } /* Run regular command. */ bp = bioq_first(&softc->bio_queue); if (bp == NULL) { xpt_release_ccb(start_ccb); break; } bioq_remove(&softc->bio_queue, bp); if ((softc->flags & ADA_FLAG_NEED_OTAG) != 0) { softc->flags &= ~ADA_FLAG_NEED_OTAG; softc->ordered_tag_count++; tag_code = 0; } else { tag_code = 1; } switch (bp->bio_cmd) { case BIO_READ: case BIO_WRITE: { uint64_t lba = bp->bio_pblkno; uint16_t count = bp->bio_bcount / softc->params.secsize; cam_fill_ataio(ataio, ada_retry_count, adadone, bp->bio_cmd == BIO_READ ? CAM_DIR_IN : CAM_DIR_OUT, tag_code, bp->bio_data, bp->bio_bcount, ada_default_timeout*1000); if ((softc->flags & ADA_FLAG_CAN_NCQ) && tag_code) { if (bp->bio_cmd == BIO_READ) { ata_ncq_cmd(ataio, ATA_READ_FPDMA_QUEUED, lba, count); } else { ata_ncq_cmd(ataio, ATA_WRITE_FPDMA_QUEUED, lba, count); } } else if ((softc->flags & ADA_FLAG_CAN_48BIT) && (lba + count >= ATA_MAX_28BIT_LBA || count > 256)) { if (softc->flags & ADA_FLAG_CAN_DMA) { if (bp->bio_cmd == BIO_READ) { ata_48bit_cmd(ataio, ATA_READ_DMA48, 0, lba, count); } else { ata_48bit_cmd(ataio, ATA_WRITE_DMA48, 0, lba, count); } } else { if (bp->bio_cmd == BIO_READ) { ata_48bit_cmd(ataio, ATA_READ_MUL48, 0, lba, count); } else { ata_48bit_cmd(ataio, ATA_WRITE_MUL48, 0, lba, count); } } } else { if (count == 256) count = 0; if (softc->flags & ADA_FLAG_CAN_DMA) { if (bp->bio_cmd == BIO_READ) { ata_28bit_cmd(ataio, ATA_READ_DMA, 0, lba, count); } else { ata_28bit_cmd(ataio, ATA_WRITE_DMA, 0, lba, count); } } else { if (bp->bio_cmd == BIO_READ) { ata_28bit_cmd(ataio, ATA_READ_MUL, 0, lba, count); } else { ata_28bit_cmd(ataio, ATA_WRITE_MUL, 0, lba, count); } } } break; } case BIO_DELETE: { uint64_t lba = bp->bio_pblkno; uint16_t count = bp->bio_bcount / softc->params.secsize; cam_fill_ataio(ataio, ada_retry_count, adadone, CAM_DIR_NONE, 0, NULL, 0, ada_default_timeout*1000); if (count >= 256) count = 0; ata_28bit_cmd(ataio, ATA_CFA_ERASE, 0, lba, count); break; } case BIO_FLUSH: cam_fill_ataio(ataio, 1, adadone, CAM_DIR_NONE, 0, NULL, 0, ada_default_timeout*1000); if (softc->flags & ADA_FLAG_CAN_48BIT) ata_48bit_cmd(ataio, ATA_FLUSHCACHE48, 0, 0, 0); else ata_28bit_cmd(ataio, ATA_FLUSHCACHE, 0, 0, 0); break; } start_ccb->ccb_h.ccb_state = ADA_CCB_BUFFER_IO; out: start_ccb->ccb_h.ccb_bp = bp; softc->outstanding_cmds++; xpt_action(start_ccb); /* May have more work to do, so ensure we stay scheduled */ adaschedule(periph); break; } } } static void adadone(struct cam_periph *periph, union ccb *done_ccb) { struct ada_softc *softc; struct ccb_ataio *ataio; softc = (struct ada_softc *)periph->softc; ataio = &done_ccb->ataio; switch (ataio->ccb_h.ccb_state & ADA_CCB_TYPE_MASK) { case ADA_CCB_BUFFER_IO: case ADA_CCB_TRIM: { struct bio *bp; bp = (struct bio *)done_ccb->ccb_h.ccb_bp; if ((done_ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) { int error; error = adaerror(done_ccb, 0, 0); if (error == ERESTART) { /* A retry was scheduled, so just return. */ return; } if (error != 0) { if (error == ENXIO) { /* * Catastrophic error. Mark our pack as * invalid. */ /* * XXX See if this is really a media * XXX change first? */ xpt_print(periph->path, "Invalidating pack\n"); softc->flags |= ADA_FLAG_PACK_INVALID; } bp->bio_error = error; bp->bio_resid = bp->bio_bcount; bp->bio_flags |= BIO_ERROR; } else { bp->bio_resid = ataio->resid; bp->bio_error = 0; if (bp->bio_resid != 0) bp->bio_flags |= BIO_ERROR; } if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) cam_release_devq(done_ccb->ccb_h.path, /*relsim_flags*/0, /*reduction*/0, /*timeout*/0, /*getcount_only*/0); } else { if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) panic("REQ_CMP with QFRZN"); bp->bio_resid = ataio->resid; if (ataio->resid > 0) bp->bio_flags |= BIO_ERROR; } softc->outstanding_cmds--; if (softc->outstanding_cmds == 0) softc->flags |= ADA_FLAG_WENT_IDLE; if ((ataio->ccb_h.ccb_state & ADA_CCB_TYPE_MASK) == ADA_CCB_TRIM) { struct trim_request *req = (struct trim_request *)ataio->data_ptr; int i; for (i = 1; i < softc->trim_max_ranges && req->bps[i]; i++) { struct bio *bp1 = req->bps[i]; bp1->bio_resid = bp->bio_resid; bp1->bio_error = bp->bio_error; if (bp->bio_flags & BIO_ERROR) bp1->bio_flags |= BIO_ERROR; biodone(bp1); } softc->trim_running = 0; biodone(bp); adaschedule(periph); } else biodone(bp); break; } case ADA_CCB_WAITING: { /* Caller will release the CCB */ wakeup(&done_ccb->ccb_h.cbfcnp); return; } case ADA_CCB_DUMP: /* No-op. We're polling */ return; default: break; } xpt_release_ccb(done_ccb); } static int adaerror(union ccb *ccb, u_int32_t cam_flags, u_int32_t sense_flags) { struct ada_softc *softc; struct cam_periph *periph; periph = xpt_path_periph(ccb->ccb_h.path); softc = (struct ada_softc *)periph->softc; return(cam_periph_error(ccb, cam_flags, sense_flags, NULL)); } static void adagetparams(struct cam_periph *periph, struct ccb_getdev *cgd) { struct ada_softc *softc = (struct ada_softc *)periph->softc; struct disk_params *dp = &softc->params; u_int64_t lbasize48; u_int32_t lbasize; dp->secsize = ata_logical_sector_size(&cgd->ident_data); if ((cgd->ident_data.atavalid & ATA_FLAG_54_58) && cgd->ident_data.current_heads && cgd->ident_data.current_sectors) { dp->heads = cgd->ident_data.current_heads; dp->secs_per_track = cgd->ident_data.current_sectors; dp->cylinders = cgd->ident_data.cylinders; dp->sectors = (u_int32_t)cgd->ident_data.current_size_1 | ((u_int32_t)cgd->ident_data.current_size_2 << 16); } else { dp->heads = cgd->ident_data.heads; dp->secs_per_track = cgd->ident_data.sectors; dp->cylinders = cgd->ident_data.cylinders; dp->sectors = cgd->ident_data.cylinders * dp->heads * dp->secs_per_track; } lbasize = (u_int32_t)cgd->ident_data.lba_size_1 | ((u_int32_t)cgd->ident_data.lba_size_2 << 16); /* use the 28bit LBA size if valid or bigger than the CHS mapping */ if (cgd->ident_data.cylinders == 16383 || dp->sectors < lbasize) dp->sectors = lbasize; /* use the 48bit LBA size if valid */ lbasize48 = ((u_int64_t)cgd->ident_data.lba_size48_1) | ((u_int64_t)cgd->ident_data.lba_size48_2 << 16) | ((u_int64_t)cgd->ident_data.lba_size48_3 << 32) | ((u_int64_t)cgd->ident_data.lba_size48_4 << 48); if ((cgd->ident_data.support.command2 & ATA_SUPPORT_ADDRESS48) && lbasize48 > ATA_MAX_28BIT_LBA) dp->sectors = lbasize48; } static void adasendorderedtag(void *arg) { struct ada_softc *softc = arg; if (ada_send_ordered) { if ((softc->ordered_tag_count == 0) && ((softc->flags & ADA_FLAG_WENT_IDLE) == 0)) { softc->flags |= ADA_FLAG_NEED_OTAG; } if (softc->outstanding_cmds > 0) softc->flags &= ~ADA_FLAG_WENT_IDLE; softc->ordered_tag_count = 0; } /* Queue us up again */ callout_reset(&softc->sendordered_c, (ADA_DEFAULT_TIMEOUT * hz) / ADA_ORDEREDTAG_INTERVAL, adasendorderedtag, softc); } /* * Step through all ADA peripheral drivers, and if the device is still open, * sync the disk cache to physical media. */ static void adashutdown(void * arg, int howto) { struct cam_periph *periph; struct ada_softc *softc; TAILQ_FOREACH(periph, &adadriver.units, unit_links) { union ccb ccb; /* If we paniced with lock held - not recurse here. */ if (cam_periph_owned(periph)) continue; cam_periph_lock(periph); softc = (struct ada_softc *)periph->softc; /* * We only sync the cache if the drive is still open, and * if the drive is capable of it.. */ if (((softc->flags & ADA_FLAG_OPEN) == 0) || (softc->flags & ADA_FLAG_CAN_FLUSHCACHE) == 0) { cam_periph_unlock(periph); continue; } xpt_setup_ccb(&ccb.ccb_h, periph->path, CAM_PRIORITY_NORMAL); ccb.ccb_h.ccb_state = ADA_CCB_DUMP; cam_fill_ataio(&ccb.ataio, 1, adadone, CAM_DIR_NONE, 0, NULL, 0, ada_default_timeout*1000); if (softc->flags & ADA_FLAG_CAN_48BIT) ata_48bit_cmd(&ccb.ataio, ATA_FLUSHCACHE48, 0, 0, 0); else ata_28bit_cmd(&ccb.ataio, ATA_FLUSHCACHE, 0, 0, 0); xpt_polled_action(&ccb); if ((ccb.ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) xpt_print(periph->path, "Synchronize cache failed\n"); if ((ccb.ccb_h.status & CAM_DEV_QFRZN) != 0) cam_release_devq(ccb.ccb_h.path, /*relsim_flags*/0, /*reduction*/0, /*timeout*/0, /*getcount_only*/0); cam_periph_unlock(periph); } } #endif /* _KERNEL */ Index: stable/8/sys/cddl/contrib/opensolaris =================================================================== --- stable/8/sys/cddl/contrib/opensolaris (revision 208450) +++ stable/8/sys/cddl/contrib/opensolaris (revision 208451) Property changes on: stable/8/sys/cddl/contrib/opensolaris ___________________________________________________________________ Modified: svn:mergeinfo ## -0,0 +0,1 ## Merged /head/sys/cddl/contrib/opensolaris:r208349 Index: stable/8/sys/conf/files.sparc64 =================================================================== --- stable/8/sys/conf/files.sparc64 (revision 208450) +++ stable/8/sys/conf/files.sparc64 (revision 208451) @@ -1,140 +1,140 @@ # This file tells config what files go into building a kernel, # files marked standard are always included. # # $FreeBSD$ # # The long compile-with and dependency lines are required because of # limitations in config: backslash-newline doesn't work in strings, and # dependency lines other than the first are silently ignored. # atkbdmap.h optional atkbd_dflt_keymap \ compile-with "/usr/sbin/kbdcontrol -L ${ATKBD_DFLT_KEYMAP} | sed -e 's/^static keymap_t.* = /static keymap_t key_map = /' -e 's/^static accentmap_t.* = /static accentmap_t accent_map = /' > atkbdmap.h" \ no-obj no-implicit-rule before-depend \ clean "atkbdmap.h" # sunkbdmap.h optional sunkbd_dflt_keymap \ compile-with "/usr/sbin/kbdcontrol -L ${SUNKBD_DFLT_KEYMAP} | sed -e 's/^static keymap_t.* = /static keymap_t key_map = /' -e 's/^static accentmap_t.* = /static accentmap_t accent_map = /' > sunkbdmap.h" \ no-obj no-implicit-rule before-depend \ clean "sunkbdmap.h" # ukbdmap.h optional ukbd_dflt_keymap \ compile-with "/usr/sbin/kbdcontrol -L ${UKBD_DFLT_KEYMAP} | sed -e 's/^static keymap_t.* = /static keymap_t key_map = /' -e 's/^static accentmap_t.* = /static accentmap_t accent_map = /' > ukbdmap.h" \ no-obj no-implicit-rule before-depend \ clean "ukbdmap.h" # crypto/blowfish/bf_enc.c optional crypto | ipsec crypto/des/des_enc.c optional crypto | ipsec | netsmb dev/atkbdc/atkbd.c optional atkbd atkbdc dev/atkbdc/atkbd_atkbdc.c optional atkbd atkbdc dev/atkbdc/atkbdc.c optional atkbdc dev/atkbdc/atkbdc_ebus.c optional atkbdc ebus dev/atkbdc/atkbdc_isa.c optional atkbdc isa dev/atkbdc/atkbdc_subr.c optional atkbdc dev/atkbdc/psm.c optional psm atkbdc dev/auxio/auxio.c optional auxio sbus | auxio ebus dev/esp/esp_sbus.c optional esp sbus dev/fb/creator.c optional creator sc dev/fb/fb.c optional sc dev/fb/gallant12x22.c optional sc dev/fb/machfb.c optional machfb sc dev/hwpmc/hwpmc_sparc64.c optional hwpmc dev/kbd/kbd.c optional atkbd | sc | ukbd dev/le/if_le_lebuffer.c optional le sbus dev/le/if_le_ledma.c optional le sbus dev/le/lebuffer_sbus.c optional le sbus dev/ofw/ofw_if.m standard dev/ofw/ofw_bus_if.m standard dev/ofw/ofw_bus_subr.c standard dev/ofw/ofw_standard.c standard dev/ofw/ofw_console.c optional ofw_console dev/ofw/openfirm.c standard dev/ofw/openfirmio.c standard dev/ofw/openpromio.c standard dev/pcf/envctrl.c optional pcf ebus dev/pcf/pcf_ebus.c optional pcf ebus dev/sound/sbus/cs4231.c optional snd_audiocs ebus | \ snd_audiocs sbus dev/syscons/scgfbrndr.c optional sc dev/syscons/scterm-teken.c optional sc dev/syscons/scvtb.c optional sc dev/syscons/teken/teken.c optional sc dev/uart/uart_cpu_sparc64.c optional uart dev/uart/uart_kbd_sun.c optional uart sc kern/syscalls.c optional ktr libkern/ffs.c standard libkern/ffsl.c standard libkern/fls.c standard libkern/flsl.c standard libkern/memmove.c standard sparc64/central/central.c optional central sparc64/ebus/ebus.c optional ebus sparc64/ebus/epic.c optional epic ebus sparc64/fhc/clkbrd.c optional fhc sparc64/fhc/fhc.c optional fhc sparc64/isa/isa.c optional isa sparc64/isa/isa_dma.c optional isa sparc64/isa/ofw_isa.c optional ebus | isa sparc64/pci/apb.c optional pci sparc64/pci/fire.c optional pci sparc64/pci/ofw_pcib.c optional pci sparc64/pci/ofw_pcib_subr.c optional pci sparc64/pci/ofw_pcibus.c optional pci sparc64/pci/psycho.c optional pci sparc64/pci/schizo.c optional pci sparc64/sbus/dma_sbus.c optional sbus sparc64/sbus/sbus.c optional sbus sparc64/sbus/lsi64854.c optional sbus -sparc64/sparc64/ata_machdep.c optional atadisk +sparc64/sparc64/ata_machdep.c optional ada | atadisk | da sparc64/sparc64/autoconf.c standard sparc64/sparc64/bus_machdep.c standard sparc64/sparc64/cache.c standard sparc64/sparc64/cheetah.c standard sparc64/sparc64/clock.c standard sparc64/sparc64/counter.c standard sparc64/sparc64/db_disasm.c optional ddb sparc64/sparc64/db_interface.c optional ddb sparc64/sparc64/db_trace.c optional ddb sparc64/sparc64/db_hwwatch.c optional ddb sparc64/sparc64/dump_machdep.c standard sparc64/sparc64/elf_machdep.c standard sparc64/sparc64/exception.S standard no-obj \ compile-with "${NORMAL_S} -mcpu=ultrasparc" sparc64/sparc64/eeprom.c optional eeprom ebus | eeprom fhc | \ eeprom sbus sparc64/sparc64/gdb_machdep.c optional gdb sparc64/sparc64/identcpu.c standard sparc64/sparc64/in_cksum.c optional inet sparc64/sparc64/interrupt.S standard no-obj \ compile-with "${NORMAL_S} -mcpu=ultrasparc" sparc64/sparc64/intr_machdep.c standard sparc64/sparc64/iommu.c standard sparc64/sparc64/jbusppm.c standard sparc64/sparc64/locore.S standard no-obj sparc64/sparc64/machdep.c standard sparc64/sparc64/mem.c optional mem sparc64/sparc64/mp_exception.S optional smp \ compile-with "${NORMAL_S} -mcpu=ultrasparc" sparc64/sparc64/mp_locore.S optional smp sparc64/sparc64/mp_machdep.c optional smp sparc64/sparc64/nexus.c standard sparc64/sparc64/ofw_machdep.c standard sparc64/sparc64/pmap.c standard sparc64/sparc64/prof_machdep.c optional profiling-routine sparc64/sparc64/rtc.c optional rtc ebus | rtc isa sparc64/sparc64/rwindow.c standard sparc64/sparc64/sc_machdep.c optional sc sparc64/sparc64/schppm.c standard sparc64/sparc64/spitfire.c standard sparc64/sparc64/stack_machdep.c optional ddb | stack sparc64/sparc64/support.S standard \ compile-with "${NORMAL_S} -mcpu=ultrasparc" sparc64/sparc64/sys_machdep.c standard sparc64/sparc64/swtch.S standard sparc64/sparc64/tick.c standard sparc64/sparc64/tlb.c standard sparc64/sparc64/trap.c standard sparc64/sparc64/tsb.c standard sparc64/sparc64/uio_machdep.c standard sparc64/sparc64/upa.c optional creator sparc64/sparc64/vm_machdep.c standard sparc64/sparc64/zeus.c standard Index: stable/8/sys/contrib/dev/acpica =================================================================== --- stable/8/sys/contrib/dev/acpica (revision 208450) +++ stable/8/sys/contrib/dev/acpica (revision 208451) Property changes on: stable/8/sys/contrib/dev/acpica ___________________________________________________________________ Modified: svn:mergeinfo ## -0,0 +0,1 ## Merged /head/sys/contrib/dev/acpica:r208349 Index: stable/8/sys/contrib/pf =================================================================== --- stable/8/sys/contrib/pf (revision 208450) +++ stable/8/sys/contrib/pf (revision 208451) Property changes on: stable/8/sys/contrib/pf ___________________________________________________________________ Modified: svn:mergeinfo ## -0,0 +0,1 ## Merged /head/sys/contrib/pf:r208349 Index: stable/8/sys/dev/ata/ata-disk.c =================================================================== --- stable/8/sys/dev/ata/ata-disk.c (revision 208450) +++ stable/8/sys/dev/ata/ata-disk.c (revision 208451) @@ -1,592 +1,592 @@ /*- * Copyright (c) 1998 - 2008 Søren Schmidt * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer, * without modification, immediately at the beginning of the file. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include __FBSDID("$FreeBSD$"); #include "opt_ata.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include /* prototypes */ static void ad_init(device_t dev); static void ad_get_geometry(device_t dev); static void ad_set_geometry(device_t dev); static void ad_done(struct ata_request *request); static void ad_describe(device_t dev); static int ad_version(u_int16_t version); static disk_strategy_t ad_strategy; static disk_ioctl_t ad_ioctl; static dumper_t ad_dump; /* * Most platforms map firmware geom to actual, but some don't. If * not overridden, default to nothing. */ -#ifndef ad_firmware_geom_adjust -#define ad_firmware_geom_adjust(dev, disk) +#ifndef ata_disk_firmware_geom_adjust +#define ata_disk_firmware_geom_adjust(disk) #endif /* local vars */ static MALLOC_DEFINE(M_AD, "ad_driver", "ATA disk driver"); static int ad_probe(device_t dev) { struct ata_device *atadev = device_get_softc(dev); if (!(atadev->param.config & ATA_PROTO_ATAPI) || (atadev->param.config == ATA_CFA_MAGIC1) || (atadev->param.config == ATA_CFA_MAGIC2) || (atadev->param.config == ATA_CFA_MAGIC3)) return 0; else return ENXIO; } static int ad_attach(device_t dev) { struct ata_channel *ch = device_get_softc(device_get_parent(dev)); struct ata_device *atadev = device_get_softc(dev); struct ad_softc *adp; /* check that we have a virgin disk to attach */ if (device_get_ivars(dev)) return EEXIST; if (!(adp = malloc(sizeof(struct ad_softc), M_AD, M_NOWAIT | M_ZERO))) { device_printf(dev, "out of memory\n"); return ENOMEM; } device_set_ivars(dev, adp); /* get device geometry into internal structs */ ad_get_geometry(dev); /* set the max size if configured */ if (ata_setmax) ad_set_geometry(dev); /* init device parameters */ ad_init(dev); /* announce we are here */ ad_describe(dev); /* create the disk device */ adp->disk = disk_alloc(); adp->disk->d_strategy = ad_strategy; adp->disk->d_ioctl = ad_ioctl; adp->disk->d_dump = ad_dump; adp->disk->d_name = "ad"; adp->disk->d_drv1 = dev; adp->disk->d_maxsize = ch->dma.max_iosize ? ch->dma.max_iosize : DFLTPHYS; if (atadev->param.support.command2 & ATA_SUPPORT_ADDRESS48) adp->disk->d_maxsize = min(adp->disk->d_maxsize, 65536 * DEV_BSIZE); else /* 28bit ATA command limit */ adp->disk->d_maxsize = min(adp->disk->d_maxsize, 256 * DEV_BSIZE); adp->disk->d_sectorsize = DEV_BSIZE; adp->disk->d_mediasize = DEV_BSIZE * (off_t)adp->total_secs; adp->disk->d_fwsectors = adp->sectors; adp->disk->d_fwheads = adp->heads; adp->disk->d_unit = device_get_unit(dev); if (atadev->param.support.command2 & ATA_SUPPORT_FLUSHCACHE) adp->disk->d_flags |= DISKFLAG_CANFLUSHCACHE; if ((atadev->param.support.command2 & ATA_SUPPORT_CFA) || atadev->param.config == ATA_PROTO_CFA) adp->disk->d_flags |= DISKFLAG_CANDELETE; strlcpy(adp->disk->d_ident, atadev->param.serial, sizeof(adp->disk->d_ident)); + ata_disk_firmware_geom_adjust(adp->disk); disk_create(adp->disk, DISK_VERSION); device_add_child(dev, "subdisk", device_get_unit(dev)); - ad_firmware_geom_adjust(dev, adp->disk); bus_generic_attach(dev); callout_init(&atadev->spindown_timer, 1); return 0; } static int ad_detach(device_t dev) { struct ad_softc *adp = device_get_ivars(dev); struct ata_device *atadev = device_get_softc(dev); device_t *children; int nchildren, i; /* check that we have a valid disk to detach */ if (!device_get_ivars(dev)) return ENXIO; /* destroy the power timeout */ callout_drain(&atadev->spindown_timer); /* detach & delete all children */ if (!device_get_children(dev, &children, &nchildren)) { for (i = 0; i < nchildren; i++) if (children[i]) device_delete_child(dev, children[i]); free(children, M_TEMP); } /* detroy disk from the system so we dont get any further requests */ disk_destroy(adp->disk); /* fail requests on the queue and any thats "in flight" for this device */ ata_fail_requests(dev); /* dont leave anything behind */ device_set_ivars(dev, NULL); free(adp, M_AD); return 0; } static int ad_shutdown(device_t dev) { struct ata_device *atadev = device_get_softc(dev); if (atadev->param.support.command2 & ATA_SUPPORT_FLUSHCACHE) ata_controlcmd(dev, ATA_FLUSHCACHE, 0, 0, 0); return 0; } static int ad_reinit(device_t dev) { struct ata_channel *ch = device_get_softc(device_get_parent(dev)); struct ata_device *atadev = device_get_softc(dev); /* if detach pending, return error */ if (!(ch->devices & (ATA_ATA_MASTER << atadev->unit))) return 1; ad_init(dev); return 0; } static void ad_power_callback(struct ata_request *request) { device_printf(request->dev, "drive spun down.\n"); ata_free_request(request); } static void ad_spindown(void *priv) { device_t dev = priv; struct ata_device *atadev = device_get_softc(dev); struct ata_request *request; if (!atadev->spindown) return; device_printf(dev, "Idle, spin down\n"); atadev->spindown_state = 1; if (!(request = ata_alloc_request())) { device_printf(dev, "FAILURE - out of memory in ad_spindown\n"); return; } request->dev = dev; request->flags = ATA_R_CONTROL; request->timeout = ATA_REQUEST_TIMEOUT; request->retries = 1; request->callback = ad_power_callback; request->u.ata.command = ATA_STANDBY_IMMEDIATE; ata_queue_request(request); } static void ad_strategy(struct bio *bp) { device_t dev = bp->bio_disk->d_drv1; struct ata_device *atadev = device_get_softc(dev); struct ata_request *request; if (atadev->spindown) callout_reset(&atadev->spindown_timer, hz * atadev->spindown, ad_spindown, dev); if (!(request = ata_alloc_request())) { device_printf(dev, "FAILURE - out of memory in start\n"); biofinish(bp, NULL, ENOMEM); return; } /* setup request */ request->dev = dev; request->bio = bp; request->callback = ad_done; if (atadev->spindown_state) { device_printf(dev, "request while spun down, starting.\n"); atadev->spindown_state = 0; request->timeout = MAX(ATA_REQUEST_TIMEOUT, 31); } else { request->timeout = ATA_REQUEST_TIMEOUT; } request->retries = 2; request->data = bp->bio_data; request->bytecount = bp->bio_bcount; request->u.ata.lba = bp->bio_pblkno; request->u.ata.count = request->bytecount / DEV_BSIZE; request->transfersize = min(bp->bio_bcount, atadev->max_iosize); switch (bp->bio_cmd) { case BIO_READ: request->flags = ATA_R_READ; if (atadev->mode >= ATA_DMA) { request->u.ata.command = ATA_READ_DMA; request->flags |= ATA_R_DMA; } else if (request->transfersize > DEV_BSIZE) request->u.ata.command = ATA_READ_MUL; else request->u.ata.command = ATA_READ; break; case BIO_WRITE: request->flags = ATA_R_WRITE; if (atadev->mode >= ATA_DMA) { request->u.ata.command = ATA_WRITE_DMA; request->flags |= ATA_R_DMA; } else if (request->transfersize > DEV_BSIZE) request->u.ata.command = ATA_WRITE_MUL; else request->u.ata.command = ATA_WRITE; break; case BIO_DELETE: request->flags = ATA_R_CONTROL; request->u.ata.command = ATA_CFA_ERASE; request->transfersize = 0; request->donecount = bp->bio_bcount; break; case BIO_FLUSH: request->u.ata.lba = 0; request->u.ata.count = 0; request->u.ata.feature = 0; request->bytecount = 0; request->transfersize = 0; request->flags = ATA_R_CONTROL; request->u.ata.command = ATA_FLUSHCACHE; break; default: device_printf(dev, "FAILURE - unknown BIO operation\n"); ata_free_request(request); biofinish(bp, NULL, EIO); return; } request->flags |= ATA_R_ORDERED; ata_queue_request(request); } static void ad_done(struct ata_request *request) { struct bio *bp = request->bio; /* finish up transfer */ if ((bp->bio_error = request->result)) bp->bio_flags |= BIO_ERROR; bp->bio_resid = bp->bio_bcount - request->donecount; biodone(bp); ata_free_request(request); } static int ad_ioctl(struct disk *disk, u_long cmd, void *data, int flag, struct thread *td) { return ata_device_ioctl(disk->d_drv1, cmd, data); } static int ad_dump(void *arg, void *virtual, vm_offset_t physical, off_t offset, size_t length) { struct disk *dp = arg; device_t dev = dp->d_drv1; struct bio bp; /* XXX: Drop pre-dump request queue. Long request queue processing * causes stack overflow in ATA working in dumping (interruptless) mode. * Conter-XXX: To make dump coherent we should avoid doing anything * else while dumping. */ ata_drop_requests(dev); /* length zero is special and really means flush buffers to media */ if (!length) { struct ata_device *atadev = device_get_softc(dev); int error = 0; if (atadev->param.support.command2 & ATA_SUPPORT_FLUSHCACHE) error = ata_controlcmd(dev, ATA_FLUSHCACHE, 0, 0, 0); return error; } bzero(&bp, sizeof(struct bio)); bp.bio_disk = dp; bp.bio_pblkno = offset / DEV_BSIZE; bp.bio_bcount = length; bp.bio_data = virtual; bp.bio_cmd = BIO_WRITE; ad_strategy(&bp); return bp.bio_error; } static void ad_init(device_t dev) { struct ata_device *atadev = device_get_softc(dev); ata_setmode(dev); /* enable readahead caching */ if (atadev->param.support.command1 & ATA_SUPPORT_LOOKAHEAD) ata_controlcmd(dev, ATA_SETFEATURES, ATA_SF_ENAB_RCACHE, 0, 0); /* enable write caching if supported and configured */ if (atadev->param.support.command1 & ATA_SUPPORT_WRITECACHE) { if (ata_wc) ata_controlcmd(dev, ATA_SETFEATURES, ATA_SF_ENAB_WCACHE, 0, 0); else ata_controlcmd(dev, ATA_SETFEATURES, ATA_SF_DIS_WCACHE, 0, 0); } /* use multiple sectors/interrupt if device supports it */ if (ad_version(atadev->param.version_major)) { int secsperint = max(1, min(atadev->param.sectors_intr & 0xff, 16)); if (!ata_controlcmd(dev, ATA_SET_MULTI, 0, 0, secsperint)) atadev->max_iosize = secsperint * DEV_BSIZE; } else atadev->max_iosize = DEV_BSIZE; } static void ad_get_geometry(device_t dev) { struct ata_device *atadev = device_get_softc(dev); struct ad_softc *adp = device_get_ivars(dev); u_int64_t lbasize48; u_int32_t lbasize; if ((atadev->param.atavalid & ATA_FLAG_54_58) && atadev->param.current_heads && atadev->param.current_sectors) { adp->heads = atadev->param.current_heads; adp->sectors = atadev->param.current_sectors; adp->total_secs = (u_int32_t)atadev->param.current_size_1 | ((u_int32_t)atadev->param.current_size_2 << 16); } else { adp->heads = atadev->param.heads; adp->sectors = atadev->param.sectors; adp->total_secs = atadev->param.cylinders * adp->heads * adp->sectors; } lbasize = (u_int32_t)atadev->param.lba_size_1 | ((u_int32_t)atadev->param.lba_size_2 << 16); /* does this device need oldstyle CHS addressing */ if (!ad_version(atadev->param.version_major) || !lbasize) atadev->flags |= ATA_D_USE_CHS; /* use the 28bit LBA size if valid or bigger than the CHS mapping */ if (atadev->param.cylinders == 16383 || adp->total_secs < lbasize) adp->total_secs = lbasize; /* use the 48bit LBA size if valid */ lbasize48 = ((u_int64_t)atadev->param.lba_size48_1) | ((u_int64_t)atadev->param.lba_size48_2 << 16) | ((u_int64_t)atadev->param.lba_size48_3 << 32) | ((u_int64_t)atadev->param.lba_size48_4 << 48); if ((atadev->param.support.command2 & ATA_SUPPORT_ADDRESS48) && lbasize48 > ATA_MAX_28BIT_LBA) adp->total_secs = lbasize48; } static void ad_set_geometry(device_t dev) { struct ad_softc *adp = device_get_ivars(dev); struct ata_request *request; if (1 | bootverbose) device_printf(dev, "ORG %ju sectors [%juC/%dH/%dS]\n", adp->total_secs, adp->total_secs / (adp->heads * adp->sectors), adp->heads, adp->sectors); if (!(request = ata_alloc_request())) return; /* get the max native size the device supports */ request->dev = dev; request->u.ata.command = ATA_READ_NATIVE_MAX_ADDRESS; request->u.ata.lba = 0; request->u.ata.count = 0; request->u.ata.feature = 0; request->flags = ATA_R_CONTROL | ATA_R_QUIET; request->timeout = ATA_REQUEST_TIMEOUT; request->retries = 0; ata_queue_request(request); if (request->status & ATA_S_ERROR) goto out; if (1 | bootverbose) device_printf(dev, "MAX %ju sectors\n", request->u.ata.lba + 1); /* if original size equals max size nothing more todo */ if (adp->total_secs >= request->u.ata.lba) goto out; /* set the max native size to its max */ request->dev = dev; request->u.ata.command = ATA_SET_MAX_ADDRESS; request->u.ata.count = 1; request->u.ata.feature = 0; request->flags = ATA_R_CONTROL; request->timeout = ATA_REQUEST_TIMEOUT; request->retries = 0; ata_queue_request(request); if (request->status & ATA_S_ERROR) goto out; /* refresh geometry from drive */ ata_getparam(device_get_softc(dev), 0); ad_get_geometry(dev); if (1 | bootverbose) device_printf(dev, "NEW %ju sectors [%juC/%dH/%dS]\n", adp->total_secs, adp->total_secs / (adp->heads * adp->sectors), adp->heads, adp->sectors); out: ata_free_request(request); } static void ad_describe(device_t dev) { struct ata_channel *ch = device_get_softc(device_get_parent(dev)); struct ata_device *atadev = device_get_softc(dev); struct ad_softc *adp = device_get_ivars(dev); u_int8_t *marker, vendor[64], product[64]; /* try to seperate the ATA model string into vendor and model parts */ if ((marker = index(atadev->param.model, ' ')) || (marker = index(atadev->param.model, '-'))) { int len = (marker - atadev->param.model); strncpy(vendor, atadev->param.model, len); vendor[len++] = 0; strcat(vendor, " "); strncpy(product, atadev->param.model + len, 40 - len); vendor[40 - len] = 0; } else { if (!strncmp(atadev->param.model, "ST", 2)) strcpy(vendor, "Seagate "); else if (!strncmp(atadev->param.model, "HDS", 3)) strcpy(vendor, "Hitachi "); else strcpy(vendor, ""); strncpy(product, atadev->param.model, 40); } device_printf(dev, "%juMB <%s%s %.8s> at ata%d-%s %s%s %s\n", adp->total_secs / (1048576 / DEV_BSIZE), vendor, product, atadev->param.revision, device_get_unit(ch->dev), ata_unit2str(atadev), (adp->flags & AD_F_TAG_ENABLED) ? "tagged " : "", ata_mode2str(atadev->mode), ata_satarev2str(ATA_GETREV(device_get_parent(dev), atadev->unit))); if (bootverbose) { device_printf(dev, "%ju sectors [%juC/%dH/%dS] " "%d sectors/interrupt %d depth queue\n", adp->total_secs, adp->total_secs / (adp->heads * adp->sectors), adp->heads, adp->sectors, atadev->max_iosize / DEV_BSIZE, adp->num_tags + 1); } } static int ad_version(u_int16_t version) { int bit; if (version == 0xffff) return 0; for (bit = 15; bit >= 0; bit--) if (version & (1< /* * PC98 machines are based on Intel CPUs. Some add-in boards offer * different CPUs than came with the processor. These CPUs sometimes * require additional flushing before and/or after DMAs. */ extern int need_pre_dma_flush; extern int need_post_dma_flush; /* * The ad driver maps the IDE disk's actual geometry to the firmware's * notion of geometry. However, PC98 machines need to do something - * different sometimes, so override the hook so we can do so. We have to - * have a knowledge that a device_t is a struct device * here to avoid - * including too many things from this file. + * different sometimes, so override the hook so we can do so. */ struct disk; +void pc98_ata_disk_firmware_geom_adjust(struct disk *); +#define ata_disk_firmware_geom_adjust(disk) \ + pc98_ata_disk_firmware_geom_adjust(disk) +/* backwards compatibility shim */ struct device; void pc98_ad_firmware_geom_adjust(struct device *, struct disk *); -#define ad_firmware_geom_adjust(dev, dsk) pc98_ad_firmware_geom_adjust(dev, dsk) #endif /* !_PC98_INCLUDE_MD_VAR_H_ */ Index: stable/8/sys/pc98/pc98/pc98_machdep.c =================================================================== --- stable/8/sys/pc98/pc98/pc98_machdep.c (revision 208450) +++ stable/8/sys/pc98/pc98/pc98_machdep.c (revision 208451) @@ -1,321 +1,328 @@ /*- * Copyright (c) KATO Takenori, 1996, 1997. * * All rights reserved. Unpublished rights reserved under the copyright * laws of Japan. * * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer as * the first lines of this file unmodified. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. The name of the author may not be used to endorse or promote products * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * $FreeBSD$ */ #include "opt_pc98.h" #include #include #include #include #include #include #include #include #include #include #include #include static int ad_geom_method = AD_GEOM_ADJUST_COMPATIDE; TUNABLE_INT("machdep.ad_geom_method", &ad_geom_method); SYSCTL_INT(_machdep, OID_AUTO, ad_geom_method, CTLFLAG_RW, &ad_geom_method, 0, "IDE disk geometry conversion method"); /* * Initialize DMA controller */ void pc98_init_dmac(void) { outb(0x439, (inb(0x439) & 0xfb)); /* DMA Accsess Control over 1MB */ outb(0x29, (0x0c | 0)); /* Bank Mode Reg. 16M mode */ outb(0x29, (0x0c | 1)); /* Bank Mode Reg. 16M mode */ outb(0x29, (0x0c | 2)); /* Bank Mode Reg. 16M mode */ outb(0x29, (0x0c | 3)); /* Bank Mode Reg. 16M mode */ outb(0x11, 0x50); } #ifdef EPSON_MEMWIN /* * Disconnect phisical memory in 15-16MB region. * * EPSON PC-486GR, P, SR, SE, HX, HG and HA only. Other system support * this feature with software DIP switch. */ static void init_epson_memwin(void) { /* Disable 15MB-16MB caching. */ switch (epson_machine_id) { case EPSON_PC486_HX: case EPSON_PC486_HG: case EPSON_PC486_HA: /* Cache control start. */ outb(0x43f, 0x42); outw(0xc40, 0x0033); /* Disable 0xF00000-0xFFFFFF. */ outb(0xc48, 0x49); outb(0xc4c, 0x00); outb(0xc48, 0x48); outb(0xc4c, 0xf0); outb(0xc48, 0x4d); outb(0xc4c, 0x00); outb(0xc48, 0x4c); outb(0xc4c, 0xff); outb(0xc48, 0x4f); outb(0xc4c, 0x00); /* Cache control end. */ outb(0x43f, 0x40); break; case EPSON_PC486_GR: case EPSON_PC486_P: case EPSON_PC486_GR_SUPER: case EPSON_PC486_GR_PLUS: case EPSON_PC486_SE: case EPSON_PC486_SR: /* Disable 0xF00000-0xFFFFFF. */ outb(0x43f, 0x42); outb(0x467, 0xe0); outb(0x567, 0xd8); outb(0x43f, 0x40); outb(0x467, 0xe0); outb(0x567, 0xe0); break; } /* Disable 15MB-16MB RAM and enable memory window. */ outb(0x43b, inb(0x43b) & 0xfd); /* Clear bit1. */ } #endif /* * Get physical memory size */ unsigned int pc98_getmemsize(unsigned int *base, unsigned int *ext) { unsigned int under16, over16; /* available conventional memory size */ *base = ((PC98_SYSTEM_PARAMETER(0x501) & 7) + 1) * 128; /* available protected memory size under 16MB */ under16 = PC98_SYSTEM_PARAMETER(0x401) * 128 + 1024; #ifdef EPSON_MEMWIN if (pc98_machine_type & M_EPSON_PC98) { if (under16 > (15 * 1024)) /* chop under16 memory to 15MB */ under16 = 15 * 1024; init_epson_memwin(); } #endif /* available protected memory size over 16MB / 1MB */ over16 = PC98_SYSTEM_PARAMETER(0x594); over16 += PC98_SYSTEM_PARAMETER(0x595) * 256; if (over16 > 0) *ext = (16 + over16) * 1024 - 1024; else *ext = under16 - 1024; return (under16); } /* * Read a geometry information of SCSI HDD from BIOS work area. * * XXX - Before reading BIOS work area, we should check whether * host adapter support it. */ int scsi_da_bios_params(struct ccb_calc_geometry *ccg) { u_char *tmp; int target; target = ccg->ccb_h.target_id; tmp = (u_char *)&PC98_SYSTEM_PARAMETER(0x460 + target*4); if ((PC98_SYSTEM_PARAMETER(0x482) & ((1 << target)&0xff)) != 0) { ccg->secs_per_track = *tmp; ccg->cylinders = ((*(tmp+3)<<8)|*(tmp+2))&0xfff; #if 0 switch (*(tmp + 3) & 0x30) { case 0x00: disk_parms->secsiz = 256; printf("Warning!: not supported.\n"); break; case 0x10: disk_parms->secsiz = 512; break; case 0x20: disk_parms->secsiz = 1024; break; default: disk_parms->secsiz = 512; printf("Warning!: not supported. But force to 512\n"); break; } #endif if (*(tmp+3) & 0x40) { ccg->cylinders += (*(tmp+1)&0xf0)<<8; ccg->heads = *(tmp+1)&0x0f; } else { ccg->heads = *(tmp+1); } return (1); } return (0); } /* * Adjust the geometry of the IDE HDD. */ /* IDE BIOS compatible mode. */ static void -pc98_ad_geom_adjust_idebios(struct disk *disk) +pc98_ata_disk_geom_adjust_idebios(struct disk *disk) { if (disk->d_mediasize < MEDIASIZE_4_3G) { disk->d_fwsectors = 17; disk->d_fwheads = 8; } else if (disk->d_mediasize < MEDIASIZE_29_5G) { disk->d_fwsectors = 63; if (disk->d_fwheads != 15) /* Allow 15H63S. */ disk->d_fwheads = 16; } else if (disk->d_mediasize < MEDIASIZE_31_5G) { disk->d_fwsectors = 63; disk->d_fwheads = 16; } else if (disk->d_mediasize < MEDIASIZE_127G) { disk->d_fwsectors = 255; disk->d_fwheads = 16; } else { /* XXX */ disk->d_fwsectors = 255; disk->d_fwheads = 255; } } /* SCSI BIOS compatible mode. */ static void -pc98_ad_geom_adjust_scsibios(struct disk *disk) +pc98_ata_disk_geom_adjust_scsibios(struct disk *disk) { if (disk->d_mediasize < MEDIASIZE_8G) { disk->d_fwsectors = 32; disk->d_fwheads = 8; } else if (disk->d_mediasize < MEDIASIZE_32G) { disk->d_fwsectors = 128; disk->d_fwheads = 8; } else if (disk->d_mediasize < MEDIASIZE_60G) { /* Compatible with IFC-USP 1.2. */ disk->d_fwsectors = 128; disk->d_fwheads = 15; } else if (disk->d_mediasize < MEDIASIZE_120G) { disk->d_fwsectors = 255; disk->d_fwheads = 15; } else { /* XXX */ disk->d_fwsectors = 255; disk->d_fwheads = 255; } } /* Compatible with the revision 1.28. */ static void -pc98_ad_geom_adjust_cyl16bit(struct disk *disk) +pc98_ata_disk_geom_adjust_cyl16bit(struct disk *disk) { off_t totsec = disk->d_mediasize / disk->d_sectorsize; off_t cyl = totsec / disk->d_fwsectors / disk->d_fwheads; - + /* - * It is impossible to have more than 65535 cylendars, so if + * It is impossible to have more than 65535 cylinders, so if * we have more then try to adjust. This is lame, but it is * only POC. */ if (cyl > 65355) { if (totsec < 17*8*65535) { disk->d_fwsectors = 17; disk->d_fwheads = 8; } else if (totsec < 63*16*65535) { disk->d_fwsectors = 63; disk->d_fwheads = 16; } else if (totsec < 255*16*65535) { disk->d_fwsectors = 255; disk->d_fwheads = 16; } else { disk->d_fwsectors = 255; disk->d_fwheads = 255; } } } void -pc98_ad_firmware_geom_adjust(device_t dev, struct disk *disk) +pc98_ata_disk_firmware_geom_adjust(struct disk *disk) { u_int oldsectors, oldheads; oldsectors = disk->d_fwsectors; oldheads = disk->d_fwheads; switch (ad_geom_method) { case AD_GEOM_ADJUST_COMPATIDE: - pc98_ad_geom_adjust_idebios(disk); + pc98_ata_disk_geom_adjust_idebios(disk); break; case AD_GEOM_ADJUST_COMPATSCSI: - pc98_ad_geom_adjust_scsibios(disk); + pc98_ata_disk_geom_adjust_scsibios(disk); break; case AD_GEOM_ADJUST_COMPATCYL16: - pc98_ad_geom_adjust_cyl16bit(disk); + pc98_ata_disk_geom_adjust_cyl16bit(disk); break; default: /* Do nothing. */ break; } if (bootverbose && (oldsectors != disk->d_fwsectors || oldheads != disk->d_fwheads)) - device_printf(dev, - "geometry adjusted from [%dH/%dS] to [%dH/%dS]\n", + printf( + "%s%d: geometry adjusted from [%dH/%dS] to [%dH/%dS]\n", + disk->d_name, disk->d_unit, oldheads, oldsectors, disk->d_fwheads, disk->d_fwsectors); +} +void +pc98_ad_firmware_geom_adjust(device_t dev __unused, struct disk *disk) +{ + + pc98_ata_disk_firmware_geom_adjust(disk); } Index: stable/8/sys/sparc64/include/md_var.h =================================================================== --- stable/8/sys/sparc64/include/md_var.h (revision 208450) +++ stable/8/sys/sparc64/include/md_var.h (revision 208451) @@ -1,78 +1,75 @@ /*- * Copyright (c) 1995 Bruce D. Evans. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. Neither the name of the author nor the names of contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * from: FreeBSD: src/sys/i386/include/md_var.h,v 1.40 2001/07/12 * $FreeBSD$ */ #ifndef _MACHINE_MD_VAR_H_ #define _MACHINE_MD_VAR_H_ typedef void cpu_block_copy_t(const void *src, void *dst, size_t len); typedef void cpu_block_zero_t(void *dst, size_t len); extern char tl0_base[]; extern char _end[]; extern long Maxmem; extern vm_offset_t kstack0; extern vm_paddr_t kstack0_phys; struct pcpu; struct md_utrap; const char *cpu_cpuid_prop(u_int cpu_impl); uint32_t cpu_get_mid(u_int cpu_impl); void cpu_identify(u_long vers, u_int clock, u_int id); void cpu_setregs(struct pcpu *pc); int is_physical_memory(vm_paddr_t addr); struct md_utrap *utrap_alloc(void); void utrap_free(struct md_utrap *ut); struct md_utrap *utrap_hold(struct md_utrap *ut); cpu_block_copy_t spitfire_block_copy; cpu_block_zero_t spitfire_block_zero; extern cpu_block_copy_t *cpu_block_copy; extern cpu_block_zero_t *cpu_block_zero; /* * Given that the Sun disk label only uses 16-bit fields for cylinders, * heads and sectors we might need to adjust the geometry of large IDE * disks. - * We have to have a knowledge that a device_t is a struct device * here - * to avoid including too many things from this file. */ struct disk; -struct device; -void sparc64_ad_firmware_geom_adjust(struct device *dev, struct disk *disk); -#define ad_firmware_geom_adjust(dev, dsk) \ - sparc64_ad_firmware_geom_adjust(dev, dsk) +void sparc64_ata_disk_firmware_geom_adjust(struct disk *disk); +#define ata_disk_firmware_geom_adjust(disk) \ + sparc64_ata_disk_firmware_geom_adjust(disk) #endif /* !_MACHINE_MD_VAR_H_ */ Index: stable/8/sys/sparc64/sparc64/ata_machdep.c =================================================================== --- stable/8/sys/sparc64/sparc64/ata_machdep.c (revision 208450) +++ stable/8/sys/sparc64/sparc64/ata_machdep.c (revision 208451) @@ -1,52 +1,52 @@ /*- * Copyright (c) 2008 Marius Strobl * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #include __FBSDID("$FreeBSD$"); #include #include #include void -sparc64_ad_firmware_geom_adjust(device_t dev, struct disk *disk) +sparc64_ata_disk_firmware_geom_adjust(struct disk *disk) { /* * The Sun disk label only uses 16-bit fields for cylinders, * heads and sectors so the geometry of large IDE disks has * to be adjusted. If the disk is > 32GB at 16 heads and 63 * sectors, the sectors have to be adjusted to 255. If the * the disk is even > 128GB, additionally adjust the heads * to 255. * XXX the OpenSolaris dad(7D) driver limits the mediasize * to 128GB. */ if (disk->d_mediasize > (off_t)65535 * 16 * 63 * disk->d_sectorsize) disk->d_fwsectors = 255; if (disk->d_mediasize > (off_t)65535 * 16 * 255 * disk->d_sectorsize) disk->d_fwheads = 255; } Index: stable/8/sys =================================================================== --- stable/8/sys (revision 208450) +++ stable/8/sys (revision 208451) Property changes on: stable/8/sys ___________________________________________________________________ Modified: svn:mergeinfo ## -0,0 +0,1 ## Merged /head/sys:r208349