⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 aic79xx_osm.c

📁 linux-2.4.29操作系统的源码
💻 C
📖 第 1 页 / 共 5 页
字号:
		   bus_size_t alignment, bus_size_t boundary,		   bus_addr_t lowaddr, bus_addr_t highaddr,		   bus_dma_filter_t *filter, void *filterarg,		   bus_size_t maxsize, int nsegments,		   bus_size_t maxsegsz, int flags, bus_dma_tag_t *ret_tag){	bus_dma_tag_t dmat;	dmat = malloc(sizeof(*dmat), M_DEVBUF, M_NOWAIT);	if (dmat == NULL)		return (ENOMEM);	/*	 * Linux is very simplistic about DMA memory.  For now don't	 * maintain all specification information.  Once Linux supplies	 * better facilities for doing these operations, or the	 * needs of this particular driver change, we might need to do	 * more here.	 */	dmat->alignment = alignment;	dmat->boundary = boundary;	dmat->maxsize = maxsize;	*ret_tag = dmat;	return (0);}voidahd_dma_tag_destroy(struct ahd_softc *ahd, bus_dma_tag_t dmat){	free(dmat, M_DEVBUF);}intahd_dmamem_alloc(struct ahd_softc *ahd, bus_dma_tag_t dmat, void** vaddr,		 int flags, bus_dmamap_t *mapp){	bus_dmamap_t map;#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,3,0)	map = malloc(sizeof(*map), M_DEVBUF, M_NOWAIT);	if (map == NULL)		return (ENOMEM);	/*	 * Although we can dma data above 4GB, our	 * "consistent" memory is below 4GB for	 * space efficiency reasons (only need a 4byte	 * address).  For this reason, we have to reset	 * our dma mask when doing allocations.	 */	if (ahd->dev_softc != NULL)		ahd_pci_set_dma_mask(ahd->dev_softc, 0xFFFFFFFF);	*vaddr = pci_alloc_consistent(ahd->dev_softc,				      dmat->maxsize, &map->bus_addr);	if (ahd->dev_softc != NULL)		ahd_pci_set_dma_mask(ahd->dev_softc,				     ahd->platform_data->hw_dma_mask);#else /* LINUX_VERSION_CODE < KERNEL_VERSION(2,3,0) */	/*	 * At least in 2.2.14, malloc is a slab allocator so all	 * allocations are aligned.  We assume for these kernel versions	 * that all allocations will be bellow 4Gig, physically contiguous,	 * and accessible via DMA by the controller.	 */	map = NULL; /* No additional information to store */	*vaddr = malloc(dmat->maxsize, M_DEVBUF, M_NOWAIT);#endif	if (*vaddr == NULL)		return (ENOMEM);	*mapp = map;	return(0);}voidahd_dmamem_free(struct ahd_softc *ahd, bus_dma_tag_t dmat,		void* vaddr, bus_dmamap_t map){#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,3,0)	pci_free_consistent(ahd->dev_softc, dmat->maxsize,			    vaddr, map->bus_addr);#else	free(vaddr, M_DEVBUF);#endif}intahd_dmamap_load(struct ahd_softc *ahd, bus_dma_tag_t dmat, bus_dmamap_t map,		void *buf, bus_size_t buflen, bus_dmamap_callback_t *cb,		void *cb_arg, int flags){	/*	 * Assume for now that this will only be used during	 * initialization and not for per-transaction buffer mapping.	 */	bus_dma_segment_t stack_sg;#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,3,0)	stack_sg.ds_addr = map->bus_addr;#else#define VIRT_TO_BUS(a) (uint32_t)virt_to_bus((void *)(a))	stack_sg.ds_addr = VIRT_TO_BUS(buf);#endif	stack_sg.ds_len = dmat->maxsize;	cb(cb_arg, &stack_sg, /*nseg*/1, /*error*/0);	return (0);}voidahd_dmamap_destroy(struct ahd_softc *ahd, bus_dma_tag_t dmat, bus_dmamap_t map){	/*	 * The map may is NULL in our < 2.3.X implementation.	 */	if (map != NULL)		free(map, M_DEVBUF);}intahd_dmamap_unload(struct ahd_softc *ahd, bus_dma_tag_t dmat, bus_dmamap_t map){	/* Nothing to do */	return (0);}/********************* Platform Dependent Functions ***************************//* * Compare "left hand" softc with "right hand" softc, returning: * < 0 - lahd has a lower priority than rahd *   0 - Softcs are equal * > 0 - lahd has a higher priority than rahd */intahd_softc_comp(struct ahd_softc *lahd, struct ahd_softc *rahd){	int	value;	/*	 * Under Linux, cards are ordered as follows:	 *	1) PCI devices that are marked as the boot controller.	 *	2) PCI devices with BIOS enabled sorted by bus/slot/func.	 *	3) All remaining PCI devices sorted by bus/slot/func.	 */#if 0	value = (lahd->flags & AHD_BOOT_CHANNEL)	      - (rahd->flags & AHD_BOOT_CHANNEL);	if (value != 0)		/* Controllers set for boot have a *higher* priority */		return (value);#endif	value = (lahd->flags & AHD_BIOS_ENABLED)	      - (rahd->flags & AHD_BIOS_ENABLED);	if (value != 0)		/* Controllers with BIOS enabled have a *higher* priority */		return (value);	/* Still equal.  Sort by bus/slot/func. */	if (aic79xx_reverse_scan != 0)		value = ahd_get_pci_bus(lahd->dev_softc)		      - ahd_get_pci_bus(rahd->dev_softc);	else		value = ahd_get_pci_bus(rahd->dev_softc)		      - ahd_get_pci_bus(lahd->dev_softc);	if (value != 0)		return (value);	if (aic79xx_reverse_scan != 0)		value = ahd_get_pci_slot(lahd->dev_softc)		      - ahd_get_pci_slot(rahd->dev_softc);	else		value = ahd_get_pci_slot(rahd->dev_softc)		      - ahd_get_pci_slot(lahd->dev_softc);	if (value != 0)		return (value);	value = rahd->channel - lahd->channel;	return (value);}static voidahd_linux_setup_tag_info(u_long arg, int instance, int targ, int32_t value){	if ((instance >= 0) && (targ >= 0)	 && (instance < NUM_ELEMENTS(aic79xx_tag_info))	 && (targ < AHD_NUM_TARGETS)) {		aic79xx_tag_info[instance].tag_commands[targ] = value & 0x1FF;		if (bootverbose)			printf("tag_info[%d:%d] = %d\n", instance, targ, value);	}}static voidahd_linux_setup_rd_strm_info(u_long arg, int instance, int targ, int32_t value){	if ((instance >= 0)	 && (instance < NUM_ELEMENTS(aic79xx_rd_strm_info))) {		aic79xx_rd_strm_info[instance] = value & 0xFFFF;		if (bootverbose)			printf("rd_strm[%d] = 0x%x\n", instance, value);	}}static voidahd_linux_setup_dv(u_long arg, int instance, int targ, int32_t value){	if ((instance >= 0)	 && (instance < NUM_ELEMENTS(aic79xx_dv_settings))) {		aic79xx_dv_settings[instance] = value;		if (bootverbose)			printf("dv[%d] = %d\n", instance, value);	}}static voidahd_linux_setup_iocell_info(u_long index, int instance, int targ, int32_t value){	if ((instance >= 0)	 && (instance < NUM_ELEMENTS(aic79xx_iocell_info))) {		uint8_t *iocell_info;		iocell_info = (uint8_t*)&aic79xx_iocell_info[instance];		iocell_info[index] = value & 0xFFFF;		if (bootverbose)			printf("iocell[%d:%ld] = %d\n", instance, index, value);	}}static voidahd_linux_setup_tag_info_global(char *p){	int tags, i, j;	tags = simple_strtoul(p + 1, NULL, 0) & 0xff;	printf("Setting Global Tags= %d\n", tags);	for (i = 0; i < NUM_ELEMENTS(aic79xx_tag_info); i++) {		for (j = 0; j < AHD_NUM_TARGETS; j++) {			aic79xx_tag_info[i].tag_commands[j] = tags;		}	}}/* * Handle Linux boot parameters. This routine allows for assigning a value * to a parameter with a ':' between the parameter and the value. * ie. aic79xx=stpwlev:1,extended */static intaic79xx_setup(char *s){	int	i, n;	char   *p;	char   *end;	static struct {		const char *name;		uint32_t *flag;	} options[] = {		{ "extended", &aic79xx_extended },		{ "no_reset", &aic79xx_no_reset },		{ "verbose", &aic79xx_verbose },		{ "allow_memio", &aic79xx_allow_memio},#ifdef AHD_DEBUG		{ "debug", &ahd_debug },#endif		{ "reverse_scan", &aic79xx_reverse_scan },		{ "periodic_otag", &aic79xx_periodic_otag },		{ "pci_parity", &aic79xx_pci_parity },		{ "seltime", &aic79xx_seltime },		{ "tag_info", NULL },		{ "global_tag_depth", NULL},		{ "rd_strm", NULL },		{ "dv", NULL },		{ "slewrate", NULL },		{ "precomp", NULL },		{ "amplitude", NULL },	};	end = strchr(s, '\0');	/*	 * XXX ia64 gcc isn't smart enough to know that NUM_ELEMENTS	 * will never be 0 in this case.	 */      	n = 0;  	while ((p = strsep(&s, ",.")) != NULL) {		if (*p == '\0')			continue;		for (i = 0; i < NUM_ELEMENTS(options); i++) {			n = strlen(options[i].name);			if (strncmp(options[i].name, p, n) == 0)				break;		}		if (i == NUM_ELEMENTS(options))			continue;		if (strncmp(p, "global_tag_depth", n) == 0) {			ahd_linux_setup_tag_info_global(p + n);		} else if (strncmp(p, "tag_info", n) == 0) {			s = aic_parse_brace_option("tag_info", p + n, end,			    2, ahd_linux_setup_tag_info, 0);		} else if (strncmp(p, "rd_strm", n) == 0) {			s = aic_parse_brace_option("rd_strm", p + n, end,			    1, ahd_linux_setup_rd_strm_info, 0);		} else if (strncmp(p, "dv", n) == 0) {			s = aic_parse_brace_option("dv", p + n, end, 1,			    ahd_linux_setup_dv, 0);		} else if (strncmp(p, "slewrate", n) == 0) {			s = aic_parse_brace_option("slewrate",			    p + n, end, 1, ahd_linux_setup_iocell_info,			    AIC79XX_SLEWRATE_INDEX);		} else if (strncmp(p, "precomp", n) == 0) {			s = aic_parse_brace_option("precomp",			    p + n, end, 1, ahd_linux_setup_iocell_info,			    AIC79XX_PRECOMP_INDEX);		} else if (strncmp(p, "amplitude", n) == 0) {			s = aic_parse_brace_option("amplitude",			    p + n, end, 1, ahd_linux_setup_iocell_info,			    AIC79XX_AMPLITUDE_INDEX);		} else if (p[n] == ':') {			*(options[i].flag) = simple_strtoul(p + n + 1, NULL, 0);		} else if (!strncmp(p, "verbose", n)) {			*(options[i].flag) = 1;		} else {			*(options[i].flag) ^= 0xFFFFFFFF;		}	}	return 1;}#if LINUX_VERSION_CODE > KERNEL_VERSION(2,3,0)__setup("aic79xx=", aic79xx_setup);#endifuint32_t aic79xx_verbose;intahd_linux_register_host(struct ahd_softc *ahd, Scsi_Host_Template *template){	char	buf[80];	struct	Scsi_Host *host;	char	*new_name;	u_long	s;	u_long	target;	template->name = ahd->description;	host = scsi_register(template, sizeof(struct ahd_softc *));	if (host == NULL)		return (ENOMEM);	*((struct ahd_softc **)host->hostdata) = ahd;	ahd_lock(ahd, &s);#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)	scsi_assign_lock(host, &ahd->platform_data->spin_lock);#elif AHD_SCSI_HAS_HOST_LOCK != 0	host->lock = &ahd->platform_data->spin_lock;#endif	ahd->platform_data->host = host;	host->can_queue = AHD_MAX_QUEUE;	host->cmd_per_lun = 2;	host->sg_tablesize = AHD_NSEG;	host->this_id = ahd->our_id;	host->irq = ahd->platform_data->irq;	host->max_id = (ahd->features & AHD_WIDE) ? 16 : 8;	host->max_lun = AHD_NUM_LUNS;	host->max_channel = 0;	host->sg_tablesize = AHD_NSEG;	ahd_set_unit(ahd, ahd_linux_next_unit());	sprintf(buf, "scsi%d", host->host_no);	new_name = malloc(strlen(buf) + 1, M_DEVBUF, M_NOWAIT);	if (new_name != NULL) {		strcpy(new_name, buf);		ahd_set_name(ahd, new_name);	}	host->unique_id = ahd->unit;#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,4) && \    LINUX_VERSION_CODE  < KERNEL_VERSION(2,5,0)	scsi_set_pci_device(host, ahd->dev_softc);#endif	ahd_linux_setup_user_rd_strm_settings(ahd);	ahd_linux_initialize_scsi_bus(ahd);	ahd_unlock(ahd, &s);	ahd->platform_data->dv_pid = kernel_thread(ahd_linux_dv_thread, ahd, 0);	ahd_lock(ahd, &s);	if (ahd->platform_data->dv_pid < 0) {		printf("%s: Failed to create DV thread, error= %d\n",		       ahd_name(ahd), ahd->platform_data->dv_pid);		return (-ahd->platform_data->dv_pid);	}	/*	 * Initially allocate *all* of our linux target objects	 * so that the DV thread will scan them all in parallel	 * just after driver initialization.  Any device that	 * does not exist will have its target object destroyed	 * by the selection timeout handler.  In the case of a	 * device that appears after the initial DV scan, async	 * negotiation will occur for the first command, and DV	 * will comence should that first command be successful.	 */	for (target = 0; target < host->max_id; target++) {		/*		 * Skip our own ID.  Some Compaq/HP storage devices		 * have enclosure management devices that respond to		 * single bit selection (i.e. selecting ourselves).		 * It is expected that either an external application		 * or a modified kernel will be used to probe this		 * ID if it is appropriate.  To accommodate these		 * installations, ahc_linux_alloc_target() will allocate		 * for our ID if asked to do so.		 */		if (target == ahd->our_id) 			continue;		ahd_linux_alloc_target(ahd, 0, target);	}	ahd_intr_enable(ahd, TRUE);	ahd_linux_start_dv(ahd);	ahd_unlock(ahd, &s);#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)	scsi_add_host(host, &ahd->dev_softc->dev);#endif	return (0);}uint64_tahd_linux_get_memsize(void){	struct sysinfo si;	si_meminfo(&si)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -