diff options
Diffstat (limited to 'sys')
31 files changed, 447 insertions, 175 deletions
| diff --git a/sys/arm/broadcom/bcm2835/bcm2835_audio.c b/sys/arm/broadcom/bcm2835/bcm2835_audio.c index 13f309dd3f11..2df6ac76124f 100644 --- a/sys/arm/broadcom/bcm2835/bcm2835_audio.c +++ b/sys/arm/broadcom/bcm2835/bcm2835_audio.c @@ -132,6 +132,7 @@ struct bcm2835_audio_info {  	uint32_t flags_pending; +	int verbose_trace;  	/* Worker thread state */  	int worker_state;  }; @@ -140,6 +141,29 @@ struct bcm2835_audio_info {  #define BCM2835_AUDIO_LOCKED(sc)	mtx_assert(&(sc)->lock, MA_OWNED)  #define BCM2835_AUDIO_UNLOCK(sc)	mtx_unlock(&(sc)->lock) +#define BCM2835_LOG_ERROR(sc,...)				\ +	do {							\ +		device_printf((sc)->dev, __VA_ARGS__);		\ +	} while(0) + +#define BCM2835_LOG_INFO(sc,...)				\ +	do {							\ +		if (sc->verbose_trace > 0)			\ +			device_printf((sc)->dev, __VA_ARGS__);	\ +	} while(0) + +#define BCM2835_LOG_WARN(sc,...) \ +	do {							\ +		if (sc->verbose_trace > 1)			\ +			device_printf((sc)->dev, __VA_ARGS__);	\ +	} while(0) + +#define BCM2835_LOG_TRACE(sc,...)				\ +	do {							\ +		if(sc->verbose_trace > 2)			\ +			device_printf((sc)->dev, __VA_ARGS__);	\ +	} while(0) +  static const char *  dest_description(uint32_t dest)  { @@ -236,8 +260,9 @@ bcm2835_audio_callback(void *param, const VCHI_CALLBACK_REASON_T reason, void *m  					device_printf(sc->dev, "available_space == %d, count = %d, perr=%d\n",  					    ch->available_space, count, perr);  					device_printf(sc->dev, -					    "retrieved_samples = %lld, submitted_samples = %lld\n", -					    ch->retrieved_samples, ch->submitted_samples); +					    "retrieved_samples = %ju, submitted_samples = %ju\n", +					    (uintmax_t)ch->retrieved_samples, +					    (uintmax_t)ch->submitted_samples);  				}  				ch->available_space += count;  				ch->retrieved_samples += count; @@ -247,7 +272,8 @@ bcm2835_audio_callback(void *param, const VCHI_CALLBACK_REASON_T reason, void *m  		}  		BCM2835_AUDIO_UNLOCK(sc);  	} else -		printf("%s: unknown m.type: %d\n", __func__, m.type); +		BCM2835_LOG_WARN(sc, "%s: unknown m.type: %d\n", __func__, +		    m.type);  }  /* VCHIQ stuff */ @@ -259,13 +285,13 @@ bcm2835_audio_init(struct bcm2835_audio_info *sc)  	/* Initialize and create a VCHI connection */  	status = vchi_initialise(&sc->vchi_instance);  	if (status != 0) { -		printf("vchi_initialise failed: %d\n", status); +		BCM2835_LOG_ERROR(sc, "vchi_initialise failed: %d\n", status);  		return;  	}  	status = vchi_connect(NULL, 0, sc->vchi_instance);  	if (status != 0) { -		printf("vchi_connect failed: %d\n", status); +		BCM2835_LOG_ERROR(sc, "vchi_connect failed: %d\n", status);  		return;  	} @@ -297,7 +323,8 @@ bcm2835_audio_release(struct bcm2835_audio_info *sc)  	if (sc->vchi_handle != VCHIQ_SERVICE_HANDLE_INVALID) {  		success = vchi_service_close(sc->vchi_handle);  		if (success != 0) -			printf("vchi_service_close failed: %d\n", success); +			BCM2835_LOG_ERROR(sc, "vchi_service_close failed: %d\n", +			    success);  		vchi_service_release(sc->vchi_handle);  		sc->vchi_handle = VCHIQ_SERVICE_HANDLE_INVALID;  	} @@ -327,7 +354,9 @@ bcm2835_audio_start(struct bcm2835_audio_chinfo *ch)  		    &m, sizeof m, VCHI_FLAGS_BLOCK_UNTIL_QUEUED, NULL);  		if (ret != 0) -			printf("%s: vchi_msg_queue failed (err %d)\n", __func__, ret); +			BCM2835_LOG_ERROR(sc, +			    "%s: vchi_msg_queue failed (err %d)\n", __func__, +			    ret);  	}  } @@ -346,7 +375,9 @@ bcm2835_audio_stop(struct bcm2835_audio_chinfo *ch)  		    &m, sizeof m, VCHI_FLAGS_BLOCK_UNTIL_QUEUED, NULL);  		if (ret != 0) -			printf("%s: vchi_msg_queue failed (err %d)\n", __func__, ret); +			BCM2835_LOG_ERROR(sc, +			    "%s: vchi_msg_queue failed (err %d)\n", __func__, +			    ret);  	}  } @@ -362,7 +393,9 @@ bcm2835_audio_open(struct bcm2835_audio_info *sc)  		    &m, sizeof m, VCHI_FLAGS_BLOCK_UNTIL_QUEUED, NULL);  		if (ret != 0) -			printf("%s: vchi_msg_queue failed (err %d)\n", __func__, ret); +			BCM2835_LOG_ERROR(sc, +			    "%s: vchi_msg_queue failed (err %d)\n", __func__, +			    ret);  	}  } @@ -384,7 +417,9 @@ bcm2835_audio_update_controls(struct bcm2835_audio_info *sc, uint32_t volume, ui  		    &m, sizeof m, VCHI_FLAGS_BLOCK_UNTIL_QUEUED, NULL);  		if (ret != 0) -			printf("%s: vchi_msg_queue failed (err %d)\n", __func__, ret); +			BCM2835_LOG_ERROR(sc, +			    "%s: vchi_msg_queue failed (err %d)\n", __func__, +			    ret);  	}  } @@ -404,7 +439,9 @@ bcm2835_audio_update_params(struct bcm2835_audio_info *sc, uint32_t fmt, uint32_  		    &m, sizeof m, VCHI_FLAGS_BLOCK_UNTIL_QUEUED, NULL);  		if (ret != 0) -			printf("%s: vchi_msg_queue failed (err %d)\n", __func__, ret); +			BCM2835_LOG_ERROR(sc, +			    "%s: vchi_msg_queue failed (err %d)\n", __func__, +			    ret);  	}  } @@ -452,14 +489,15 @@ bcm2835_audio_write_samples(struct bcm2835_audio_chinfo *ch, void *buf, uint32_t  	    &m, sizeof m, VCHI_FLAGS_BLOCK_UNTIL_QUEUED, NULL);  	if (ret != 0) -		printf("%s: vchi_msg_queue failed (err %d)\n", __func__, ret); +		BCM2835_LOG_ERROR(sc, "%s: vchi_msg_queue failed (err %d)\n", +		    __func__, ret);  	while (count > 0) {  		int bytes = MIN((int)m.u.write.max_packet, (int)count);  		ret = vchi_msg_queue(sc->vchi_handle,  		    buf, bytes, VCHI_FLAGS_BLOCK_UNTIL_QUEUED, NULL);  		if (ret != 0) -			printf("%s: vchi_msg_queue failed: %d\n", +			BCM2835_LOG_ERROR(sc, "%s: vchi_msg_queue failed: %d\n",  			    __func__, ret);  		buf = (char *)buf + bytes;  		count -= bytes; @@ -577,7 +615,8 @@ bcm2835_audio_create_worker(struct bcm2835_audio_info *sc)  	sc->worker_state = WORKER_RUNNING;  	if (kproc_create(bcm2835_audio_worker, (void*)sc, &newp, 0, 0,  	    "bcm2835_audio_worker") != 0) { -		printf("failed to create bcm2835_audio_worker\n"); +		BCM2835_LOG_ERROR(sc, +		    "failed to create bcm2835_audio_worker\n");  	}  } @@ -830,6 +869,9 @@ vchi_audio_sysctl_init(struct bcm2835_audio_info *sc)  	SYSCTL_ADD_INT(ctx, tree, OID_AUTO, "starved",  			CTLFLAG_RD, &sc->pch.starved,  			sc->pch.starved, "number of starved conditions"); +	SYSCTL_ADD_INT(ctx, tree, OID_AUTO, "trace", +			CTLFLAG_RW, &sc->verbose_trace, +			sc->verbose_trace, "enable tracing of transfers");  }  static void @@ -861,6 +903,7 @@ bcm2835_audio_delayed_init(void *xsc)  	bcm2835_audio_open(sc);  	sc->volume = 75;  	sc->dest = DEST_AUTO; +	sc->verbose_trace = 0;      	if (mixer_init(sc->dev, &bcmmixer_class, sc)) {  		device_printf(sc->dev, "mixer_init failed\n"); diff --git a/sys/compat/linuxkpi/common/include/linux/pm.h b/sys/compat/linuxkpi/common/include/linux/pm.h index c8d943027909..932697e0eda8 100644 --- a/sys/compat/linuxkpi/common/include/linux/pm.h +++ b/sys/compat/linuxkpi/common/include/linux/pm.h @@ -97,4 +97,18 @@ pm_wakeup_event(struct device *dev __unused, unsigned int x __unused)  	pr_debug("%s: TODO\n", __func__);  } +/* + * We do not need to specify anything here as a VT switch always happens on + * suspend/resume. + */ +static inline void +pm_vt_switch_required(struct device *dev __unused, bool required __unused) +{ +} + +static inline void +pm_vt_switch_unregister(struct device *dev __unused) +{ +} +  #endif	/* _LINUXKPI_LINUX_PM_H */ diff --git a/sys/compat/linuxkpi/common/src/linux_page.c b/sys/compat/linuxkpi/common/src/linux_page.c index 628af17df853..9cc981b2ba43 100644 --- a/sys/compat/linuxkpi/common/src/linux_page.c +++ b/sys/compat/linuxkpi/common/src/linux_page.c @@ -345,6 +345,10 @@ retry:  	page = vm_page_grab_iter(vm_obj, pindex, VM_ALLOC_NOCREAT, &pages);  	if (page == NULL) {  		page = PHYS_TO_VM_PAGE(IDX_TO_OFF(pfn)); +		if (page == NULL) { +			pctrie_iter_reset(&pages); +			return (VM_FAULT_SIGBUS); +		}  		if (!vm_page_busy_acquire(page, VM_ALLOC_WAITFAIL)) {  			pctrie_iter_reset(&pages);  			goto retry; diff --git a/sys/contrib/vchiq/interface/vchiq_arm/vchiq_2835_arm.c b/sys/contrib/vchiq/interface/vchiq_arm/vchiq_2835_arm.c index 0150ce72f0a4..f4aee12dec53 100644 --- a/sys/contrib/vchiq/interface/vchiq_arm/vchiq_2835_arm.c +++ b/sys/contrib/vchiq/interface/vchiq_arm/vchiq_2835_arm.c @@ -204,8 +204,8 @@ vchiq_platform_init(VCHIQ_STATE_T *state)  	bcm_mbox_write(BCM2835_MBOX_CHAN_VCHIQ, (unsigned int)g_slot_phys);  	vchiq_log_info(vchiq_arm_log_level, -		"vchiq_init - done (slots %x, phys %x)", -		(unsigned int)vchiq_slot_zero, g_slot_phys); +		"vchiq_init - done (slots %zx, phys %zx)", +		(size_t)vchiq_slot_zero, g_slot_phys);     vchiq_call_connected_callbacks(); @@ -451,10 +451,7 @@ create_pagelist(char __user *buf, size_t count, unsigned short type,  	}  	vchiq_log_trace(vchiq_arm_log_level, -		"create_pagelist - %x (%d bytes @%p)", (unsigned int)pagelist, count, buf); - -	if (!pagelist) -		return -ENOMEM; +		"create_pagelist - %zx (%zu bytes @%p)", (size_t)pagelist, count, buf);  	addrs = pagelist->addrs;  	pages = (vm_page_t*)(addrs + num_pages); @@ -549,7 +546,7 @@ free_pagelist(BULKINFO_T *bi, int actual)  	pagelist = bi->pagelist;  	vchiq_log_trace(vchiq_arm_log_level, -		"free_pagelist - %x, %d (%lu bytes @%p)", (unsigned int)pagelist, actual, pagelist->length, bi->buf); +		"free_pagelist - %zx, %d (%u bytes @%p)", (size_t)pagelist, actual, pagelist->length, bi->buf);  	num_pages =  		(pagelist->length + pagelist->offset + PAGE_SIZE - 1) / diff --git a/sys/contrib/vchiq/interface/vchiq_arm/vchiq_arm.c b/sys/contrib/vchiq/interface/vchiq_arm/vchiq_arm.c index 763cd9ce9417..e25c4d738922 100644 --- a/sys/contrib/vchiq/interface/vchiq_arm/vchiq_arm.c +++ b/sys/contrib/vchiq/interface/vchiq_arm/vchiq_arm.c @@ -442,8 +442,8 @@ vchiq_ioctl(struct cdev *cdev, u_long cmd, caddr_t arg, int fflag,  #define	_IOC_TYPE(x)	IOCGROUP(x)  	vchiq_log_trace(vchiq_arm_log_level, -		 "vchiq_ioctl - instance %x, cmd %s, arg %p", -		(unsigned int)instance, +		 "vchiq_ioctl - instance %zx, cmd %s, arg %p", +		(size_t)instance,  		((_IOC_TYPE(cmd) == VCHIQ_IOC_MAGIC) &&  		(_IOC_NR(cmd) <= VCHIQ_IOC_MAX)) ?  		ioctl_names[_IOC_NR(cmd)] : "<invalid>", arg); @@ -745,8 +745,8 @@ vchiq_ioctl(struct cdev *cdev, u_long cmd, caddr_t arg, int fflag,  				break;  			}  			vchiq_log_info(vchiq_arm_log_level, -				"found bulk_waiter %x for pid %d", -				(unsigned int)waiter, current->p_pid); +				"found bulk_waiter %zx for pid %d", +				(size_t)waiter, current->p_pid);  			args.userdata = &waiter->bulk_waiter;  		}  		status = vchiq_bulk_transfer @@ -776,8 +776,8 @@ vchiq_ioctl(struct cdev *cdev, u_long cmd, caddr_t arg, int fflag,  			list_add(&waiter->list, &instance->bulk_waiter_list);  			lmutex_unlock(&instance->bulk_waiter_list_mutex);  			vchiq_log_info(vchiq_arm_log_level, -				"saved bulk_waiter %x for pid %d", -				(unsigned int)waiter, current->p_pid); +				"saved bulk_waiter %zx for pid %d", +				(size_t)waiter, current->p_pid);  			memcpy((void *)  				&(((VCHIQ_QUEUE_BULK_TRANSFER_T *) @@ -860,9 +860,9 @@ vchiq_ioctl(struct cdev *cdev, u_long cmd, caddr_t arg, int fflag,  					if (args.msgbufsize < msglen) {  						vchiq_log_error(  							vchiq_arm_log_level, -							"header %x: msgbufsize" +							"header %zx: msgbufsize"  							" %x < msglen %x", -							(unsigned int)header, +							(size_t)header,  							args.msgbufsize,  							msglen);  						WARN(1, "invalid message " @@ -1031,8 +1031,8 @@ vchiq_ioctl(struct cdev *cdev, u_long cmd, caddr_t arg, int fflag,  				ret = -EFAULT;  		} else {  			vchiq_log_error(vchiq_arm_log_level, -				"header %x: bufsize %x < size %x", -				(unsigned int)header, args.bufsize, +				"header %zx: bufsize %x < size %x", +				(size_t)header, args.bufsize,  				header->size);  			WARN(1, "invalid size\n");  			ret = -EMSGSIZE; @@ -1435,9 +1435,9 @@ vchiq_dump_platform_instances(void *dump_context)  			instance = service->instance;  			if (instance && !instance->mark) {  				len = snprintf(buf, sizeof(buf), -					"Instance %x: pid %d,%s completions " +					"Instance %zx: pid %d,%s completions "  						"%d/%d", -					(unsigned int)instance, instance->pid, +					(size_t)instance, instance->pid,  					instance->connected ? " connected, " :  						"",  					instance->completion_insert - @@ -1465,8 +1465,8 @@ vchiq_dump_platform_service_state(void *dump_context, VCHIQ_SERVICE_T *service)  	char buf[80];  	int len; -	len = snprintf(buf, sizeof(buf), "  instance %x", -		(unsigned int)service->instance); +	len = snprintf(buf, sizeof(buf), "  instance %zx", +		(size_t)service->instance);  	if ((service->base.callback == service_callback) &&  		user_service->is_vchi) { diff --git a/sys/dev/gpio/acpi_gpiobus.c b/sys/dev/gpio/acpi_gpiobus.c index 0d2455cab399..0c31f4fec16d 100644 --- a/sys/dev/gpio/acpi_gpiobus.c +++ b/sys/dev/gpio/acpi_gpiobus.c @@ -304,6 +304,12 @@ acpi_gpiobus_attach_aei(struct acpi_gpiobus_softc *sc, ACPI_HANDLE handle)  		devi->gpiobus.pins[i] = pins[i + 1];  	free(pins, M_DEVBUF); +	status = AcpiAttachData(aei_handle, acpi_fake_objhandler, child); +	if (ACPI_FAILURE(status)) { +		printf("WARNING: Unable to attach object data to %s - %s\n", +		    acpi_name(aei_handle), AcpiFormatException(status)); +	} +  	bus_attach_children(sc->super_sc.sc_busdev);  } @@ -427,6 +433,16 @@ acpi_gpiobus_child_location(device_t bus, device_t child, struct sbuf *sb)  	return (0);  } +static void +acpi_gpiobus_child_deleted(device_t bus, device_t child) +{ +	struct acpi_gpiobus_ivar *devi = device_get_ivars(child); + +	if (acpi_get_device(devi->handle) == child) +		AcpiDetachData(devi->handle, acpi_fake_objhandler); +	gpiobus_child_deleted(bus, child); +} +  static device_method_t acpi_gpiobus_methods[] = {  	/* Device interface */  	DEVMETHOD(device_probe,		acpi_gpiobus_probe), @@ -437,6 +453,7 @@ static device_method_t acpi_gpiobus_methods[] = {  	DEVMETHOD(bus_read_ivar,	acpi_gpiobus_read_ivar),  	DEVMETHOD(bus_add_child,	acpi_gpiobus_add_child),  	DEVMETHOD(bus_child_location,	acpi_gpiobus_child_location), +	DEVMETHOD(bus_child_deleted,	acpi_gpiobus_child_deleted),  	DEVMETHOD_END  }; diff --git a/sys/dev/gpio/gpiobus.c b/sys/dev/gpio/gpiobus.c index 0fca02c41ca7..596e468d35f3 100644 --- a/sys/dev/gpio/gpiobus.c +++ b/sys/dev/gpio/gpiobus.c @@ -734,7 +734,7 @@ gpiobus_add_child(device_t dev, u_int order, const char *name, int unit)  	    sizeof(struct gpiobus_ivar)));  } -static void +void  gpiobus_child_deleted(device_t dev, device_t child)  {  	struct gpiobus_ivar *devi; diff --git a/sys/dev/gpio/gpiobus_internal.h b/sys/dev/gpio/gpiobus_internal.h index 58f862343403..be76450b2432 100644 --- a/sys/dev/gpio/gpiobus_internal.h +++ b/sys/dev/gpio/gpiobus_internal.h @@ -43,6 +43,7 @@ int gpiobus_read_ivar(device_t, device_t, int, uintptr_t *);  int gpiobus_acquire_pin(device_t, uint32_t);  void gpiobus_release_pin(device_t, uint32_t);  int gpiobus_child_location(device_t, device_t, struct sbuf *); +void gpiobus_child_deleted(device_t, device_t);  device_t gpiobus_add_child_common(device_t, u_int, const char *, int, size_t);  int gpiobus_add_gpioc(device_t); diff --git a/sys/dev/nvme/nvme_ctrlr.c b/sys/dev/nvme/nvme_ctrlr.c index f212759a5500..e607667decf5 100644 --- a/sys/dev/nvme/nvme_ctrlr.c +++ b/sys/dev/nvme/nvme_ctrlr.c @@ -1762,9 +1762,14 @@ noadminq:  		bus_release_resource(ctrlr->dev, SYS_RES_IRQ,  		    rman_get_rid(ctrlr->res), ctrlr->res); -	if (ctrlr->bar4_resource != NULL) { +	if (ctrlr->msix_table_resource != NULL) {  		bus_release_resource(dev, SYS_RES_MEMORY, -		    ctrlr->bar4_resource_id, ctrlr->bar4_resource); +		    ctrlr->msix_table_resource_id, ctrlr->msix_table_resource); +	} + +	if (ctrlr->msix_pba_resource != NULL) { +		bus_release_resource(dev, SYS_RES_MEMORY, +		    ctrlr->msix_pba_resource_id, ctrlr->msix_pba_resource);  	}  	bus_release_resource(dev, SYS_RES_MEMORY, diff --git a/sys/dev/nvme/nvme_pci.c b/sys/dev/nvme/nvme_pci.c index c07a68d2f0dc..cecb05ca0a92 100644 --- a/sys/dev/nvme/nvme_pci.c +++ b/sys/dev/nvme/nvme_pci.c @@ -152,11 +152,15 @@ static int  nvme_ctrlr_allocate_bar(struct nvme_controller *ctrlr)  {  	ctrlr->resource_id = PCIR_BAR(0); +	ctrlr->msix_table_resource_id = -1; +	ctrlr->msix_table_resource = NULL; +	ctrlr->msix_pba_resource_id = -1; +	ctrlr->msix_pba_resource = NULL;  	ctrlr->resource = bus_alloc_resource_any(ctrlr->dev, SYS_RES_MEMORY,  	    &ctrlr->resource_id, RF_ACTIVE); -	if(ctrlr->resource == NULL) { +	if (ctrlr->resource == NULL) {  		nvme_printf(ctrlr, "unable to allocate pci resource\n");  		return (ENOMEM);  	} @@ -166,15 +170,32 @@ nvme_ctrlr_allocate_bar(struct nvme_controller *ctrlr)  	ctrlr->regs = (struct nvme_registers *)ctrlr->bus_handle;  	/* -	 * The NVMe spec allows for the MSI-X table to be placed behind -	 *  BAR 4/5, separate from the control/doorbell registers.  Always -	 *  try to map this bar, because it must be mapped prior to calling -	 *  pci_alloc_msix().  If the table isn't behind BAR 4/5, -	 *  bus_alloc_resource() will just return NULL which is OK. +	 * The NVMe spec allows for the MSI-X tables to be placed behind +	 *  BAR 4 and/or 5, separate from the control/doorbell registers.  	 */ -	ctrlr->bar4_resource_id = PCIR_BAR(4); -	ctrlr->bar4_resource = bus_alloc_resource_any(ctrlr->dev, SYS_RES_MEMORY, -	    &ctrlr->bar4_resource_id, RF_ACTIVE); + +	ctrlr->msix_table_resource_id = pci_msix_table_bar(ctrlr->dev); +	ctrlr->msix_pba_resource_id = pci_msix_pba_bar(ctrlr->dev); + +	if (ctrlr->msix_table_resource_id >= 0 && +	    ctrlr->msix_table_resource_id != ctrlr->resource_id) { +		ctrlr->msix_table_resource = bus_alloc_resource_any(ctrlr->dev, +		    SYS_RES_MEMORY, &ctrlr->msix_table_resource_id, RF_ACTIVE); +		if (ctrlr->msix_table_resource == NULL) { +			nvme_printf(ctrlr, "unable to allocate msi-x table resource\n"); +			return (ENOMEM); +		} +	} +	if (ctrlr->msix_pba_resource_id >= 0 && +	    ctrlr->msix_pba_resource_id != ctrlr->resource_id && +	    ctrlr->msix_pba_resource_id != ctrlr->msix_table_resource_id) { +		ctrlr->msix_pba_resource = bus_alloc_resource_any(ctrlr->dev, +		    SYS_RES_MEMORY, &ctrlr->msix_pba_resource_id, RF_ACTIVE); +		if (ctrlr->msix_pba_resource == NULL) { +			nvme_printf(ctrlr, "unable to allocate msi-x pba resource\n"); +			return (ENOMEM); +		} +	}  	return (0);  } @@ -200,9 +221,14 @@ bad:  		    ctrlr->resource_id, ctrlr->resource);  	} -	if (ctrlr->bar4_resource != NULL) { +	if (ctrlr->msix_table_resource != NULL) { +		bus_release_resource(dev, SYS_RES_MEMORY, +		    ctrlr->msix_table_resource_id, ctrlr->msix_table_resource); +	} + +	if (ctrlr->msix_pba_resource != NULL) {  		bus_release_resource(dev, SYS_RES_MEMORY, -		    ctrlr->bar4_resource_id, ctrlr->bar4_resource); +		    ctrlr->msix_pba_resource_id, ctrlr->msix_pba_resource);  	}  	if (ctrlr->tag) diff --git a/sys/dev/nvme/nvme_private.h b/sys/dev/nvme/nvme_private.h index 04a47d799350..dd45e1acd0aa 100644 --- a/sys/dev/nvme/nvme_private.h +++ b/sys/dev/nvme/nvme_private.h @@ -235,8 +235,10 @@ struct nvme_controller {  	 *  separate from the control registers which are in BAR 0/1.  These  	 *  members track the mapping of BAR 4/5 for that reason.  	 */ -	int			bar4_resource_id; -	struct resource		*bar4_resource; +	int			msix_table_resource_id; +	struct resource		*msix_table_resource; +	int			msix_pba_resource_id; +	struct resource		*msix_pba_resource;  	int			msi_count;  	uint32_t		enable_aborts; diff --git a/sys/dev/thunderbolt/nhi.c b/sys/dev/thunderbolt/nhi.c index 205e69c16253..30a72652535a 100644 --- a/sys/dev/thunderbolt/nhi.c +++ b/sys/dev/thunderbolt/nhi.c @@ -322,6 +322,7 @@ nhi_detach(struct nhi_softc *sc)  	tbdev_remove_interface(sc);  	nhi_pci_disable_interrupts(sc); +	nhi_pci_free_interrupts(sc);  	nhi_free_ring0(sc); diff --git a/sys/dev/thunderbolt/nhi_pci.c b/sys/dev/thunderbolt/nhi_pci.c index 7dacff523cef..865963e275ec 100644 --- a/sys/dev/thunderbolt/nhi_pci.c +++ b/sys/dev/thunderbolt/nhi_pci.c @@ -67,7 +67,7 @@ static int	nhi_pci_suspend(device_t);  static int	nhi_pci_resume(device_t);  static void	nhi_pci_free(struct nhi_softc *);  static int	nhi_pci_allocate_interrupts(struct nhi_softc *); -static void	nhi_pci_free_interrupts(struct nhi_softc *); +static void	nhi_pci_free_resources(struct nhi_softc *);  static int	nhi_pci_icl_poweron(struct nhi_softc *);  static device_method_t nhi_methods[] = { @@ -253,7 +253,7 @@ static void  nhi_pci_free(struct nhi_softc *sc)  { -	nhi_pci_free_interrupts(sc); +	nhi_pci_free_resources(sc);  	if (sc->parent_dmat != NULL) {  		bus_dma_tag_destroy(sc->parent_dmat); @@ -307,7 +307,7 @@ nhi_pci_allocate_interrupts(struct nhi_softc *sc)  	return (error);  } -static void +void  nhi_pci_free_interrupts(struct nhi_softc *sc)  {  	int i; @@ -319,7 +319,11 @@ nhi_pci_free_interrupts(struct nhi_softc *sc)  	}  	pci_release_msi(sc->dev); +} +static void +nhi_pci_free_resources(struct nhi_softc *sc) +{  	if (sc->irq_table != NULL) {  		bus_release_resource(sc->dev, SYS_RES_MEMORY,  		    sc->irq_table_rid, sc->irq_table); diff --git a/sys/dev/thunderbolt/nhi_var.h b/sys/dev/thunderbolt/nhi_var.h index 2b9e878af47d..e79ecc954c1f 100644 --- a/sys/dev/thunderbolt/nhi_var.h +++ b/sys/dev/thunderbolt/nhi_var.h @@ -217,6 +217,7 @@ struct nhi_dispatch {  int nhi_pci_configure_interrupts(struct nhi_softc *sc);  void nhi_pci_enable_interrupt(struct nhi_ring_pair *r);  void nhi_pci_disable_interrupts(struct nhi_softc *sc); +void nhi_pci_free_interrupts(struct nhi_softc *sc);  int nhi_pci_get_uuid(struct nhi_softc *sc);  int nhi_read_lc_mailbox(struct nhi_softc *, u_int reg, uint32_t *val);  int nhi_write_lc_mailbox(struct nhi_softc *, u_int reg, uint32_t val); diff --git a/sys/fs/nfsclient/nfs_clvfsops.c b/sys/fs/nfsclient/nfs_clvfsops.c index 5ea7eab07632..212c88f28930 100644 --- a/sys/fs/nfsclient/nfs_clvfsops.c +++ b/sys/fs/nfsclient/nfs_clvfsops.c @@ -927,7 +927,7 @@ nfs_mount(struct mount *mp)  	struct vnode *vp;  	struct thread *td;  	char *hst; -	u_char nfh[NFSX_FHMAX], krbname[100], dirpath[100], srvkrbname[100]; +	u_char nfh[NFSX_FHMAX], krbname[100], *dirpath, srvkrbname[100];  	char *cp, *opt, *name, *secname, *tlscertname;  	int nametimeo = NFS_DEFAULT_NAMETIMEO;  	int negnametimeo = NFS_DEFAULT_NEGNAMETIMEO; @@ -943,6 +943,7 @@ nfs_mount(struct mount *mp)  	newflag = 0;  	tlscertname = NULL;  	hst = malloc(MNAMELEN, M_TEMP, M_WAITOK); +	dirpath = malloc(MNAMELEN, M_TEMP, M_WAITOK);  	if (vfs_filteropt(mp->mnt_optnew, nfs_opts)) {  		error = EINVAL;  		goto out; @@ -1329,7 +1330,7 @@ nfs_mount(struct mount *mp)  			goto out;  	} else if (nfs_mount_parse_from(mp->mnt_optnew,  	    &args.hostname, (struct sockaddr_in **)&nam, dirpath, -	    sizeof(dirpath), &dirlen) == 0) { +	    MNAMELEN, &dirlen) == 0) {  		has_nfs_from_opt = 1;  		bcopy(args.hostname, hst, MNAMELEN);  		hst[MNAMELEN - 1] = '\0'; @@ -1387,7 +1388,7 @@ nfs_mount(struct mount *mp)  	if (has_nfs_from_opt == 0) {  		if (vfs_getopt(mp->mnt_optnew,  		    "dirpath", (void **)&name, NULL) == 0) -			strlcpy(dirpath, name, sizeof (dirpath)); +			strlcpy(dirpath, name, MNAMELEN);  		else  			dirpath[0] = '\0';  		dirlen = strlen(dirpath); @@ -1472,6 +1473,7 @@ out:  		MNT_IUNLOCK(mp);  	}  	free(hst, M_TEMP); +	free(dirpath, M_TEMP);  	return (error);  } diff --git a/sys/kern/subr_bus.c b/sys/kern/subr_bus.c index bf5bda7e058d..b84f69cfd03e 100644 --- a/sys/kern/subr_bus.c +++ b/sys/kern/subr_bus.c @@ -4633,7 +4633,7 @@ bus_release_resources(device_t dev, const struct resource_spec *rs,   * parent of @p dev.   */  struct resource * -bus_alloc_resource(device_t dev, int type, int *rid, rman_res_t start, +(bus_alloc_resource)(device_t dev, int type, int *rid, rman_res_t start,      rman_res_t end, rman_res_t count, u_int flags)  {  	struct resource *res; diff --git a/sys/net/pfvar.h b/sys/net/pfvar.h index 8aefe514946e..52db00f6ce0b 100644 --- a/sys/net/pfvar.h +++ b/sys/net/pfvar.h @@ -2435,6 +2435,7 @@ extern struct pf_ksrc_node	*pf_find_src_node(struct pf_addr *,  				    struct pf_srchash **, pf_sn_types_t, bool);  extern void			 pf_unlink_src_node(struct pf_ksrc_node *);  extern u_int			 pf_free_src_nodes(struct pf_ksrc_node_list *); +extern void			 pf_free_src_node(struct pf_ksrc_node *);  extern void			 pf_print_state(struct pf_kstate *);  extern void			 pf_print_flags(uint16_t);  extern int			 pf_addr_wrap_neq(struct pf_addr_wrap *, @@ -2521,6 +2522,9 @@ uint16_t	pf_qname2qid(const char *, bool);  void	pfr_initialize(void);  void	pfr_cleanup(void); +struct pfr_kentry * +	pfr_kentry_byaddr(struct pfr_ktable *, struct pf_addr *, sa_family_t, +	    int);  int	pfr_match_addr(struct pfr_ktable *, struct pf_addr *, sa_family_t);  void	pfr_update_stats(struct pfr_ktable *, struct pf_addr *, sa_family_t,  	    u_int64_t, int, int, int); diff --git a/sys/netipsec/ipsec_offload.c b/sys/netipsec/ipsec_offload.c index 8a09d5f37b4a..59a107881676 100644 --- a/sys/netipsec/ipsec_offload.c +++ b/sys/netipsec/ipsec_offload.c @@ -300,7 +300,7 @@ ipsec_accel_sa_newkey_cb(if_t ifp, void *arg)  		dprintf("ipsec_accel_sa_install_newkey: cannot alloc "  		    "drv_spi if %s spi %#x\n", if_name(ifp),  		    be32toh(tq->sav->spi)); -		return (ENOMEM); +		return (0);  	}  	error = ifp->if_ipsec_accel_m->if_sa_newkey(ifp, tq->sav,  	    drv_spi, &priv); @@ -329,7 +329,7 @@ ipsec_accel_sa_newkey_cb(if_t ifp, void *arg)  		}  	}  out: -	return (error); +	return (0);  }  static void @@ -663,7 +663,7 @@ ipsec_accel_spdadd_cb(if_t ifp, void *arg)  	if (error != 0) {  		dprintf("ipsec_accel_spdadd: %s if_spdadd %p remember res %d\n",  		    if_name(ifp), sp, error); -		return (error); +		return (0);  	}  	error = ifp->if_ipsec_accel_m->if_spdadd(ifp, sp, inp, &i->ifdata);  	if (error != 0) { @@ -671,7 +671,7 @@ ipsec_accel_spdadd_cb(if_t ifp, void *arg)  		dprintf("ipsec_accel_spdadd: %s if_spdadd %p res %d\n",  		    if_name(ifp), sp, error);  	} -	return (error); +	return (0);  }  static void diff --git a/sys/netpfil/pf/if_pfsync.c b/sys/netpfil/pf/if_pfsync.c index 66bc99df2afa..de69ecbb0985 100644 --- a/sys/netpfil/pf/if_pfsync.c +++ b/sys/netpfil/pf/if_pfsync.c @@ -546,6 +546,9 @@ pfsync_state_import(union pfsync_state_union *sp, int flags, int msg_version)  	PF_RULES_RASSERT(); +	if (strnlen(sp->pfs_1301.ifname, IFNAMSIZ) == IFNAMSIZ) +		return (EINVAL); +  	if (sp->pfs_1301.creatorid == 0) {  		if (V_pf_status.debug >= PF_DEBUG_MISC)  			printf("%s: invalid creator id: %08x\n", __func__, diff --git a/sys/netpfil/pf/pf.c b/sys/netpfil/pf/pf.c index fd70fb1c8a36..a39f5fe58cd6 100644 --- a/sys/netpfil/pf/pf.c +++ b/sys/netpfil/pf/pf.c @@ -1007,7 +1007,7 @@ pf_src_node_exists(struct pf_ksrc_node **sn, struct pf_srchash *sh)  	return (false);  } -static void +void  pf_free_src_node(struct pf_ksrc_node *sn)  { diff --git a/sys/netpfil/pf/pf_ioctl.c b/sys/netpfil/pf/pf_ioctl.c index a4557f139ae5..703ecf446fad 100644 --- a/sys/netpfil/pf/pf_ioctl.c +++ b/sys/netpfil/pf/pf_ioctl.c @@ -4792,6 +4792,17 @@ DIOCCHANGEADDR_error:  			error = ENODEV;  			goto fail;  		} +		if (strnlen(io->pfrio_table.pfrt_anchor, MAXPATHLEN) +		    == MAXPATHLEN) { +			error = EINVAL; +			goto fail; +		} +		if (strnlen(io->pfrio_table.pfrt_name, PF_TABLE_NAME_SIZE) +		    == PF_TABLE_NAME_SIZE) { +			error = EINVAL; +			goto fail; +		} +  		PF_RULES_WLOCK();  		error = pfr_clr_tables(&io->pfrio_table, &io->pfrio_ndel,  		    io->pfrio_flags | PFR_FLAG_USERIOCTL); diff --git a/sys/netpfil/pf/pf_lb.c b/sys/netpfil/pf/pf_lb.c index 5d85e16f18e3..7aeb8266ca8c 100644 --- a/sys/netpfil/pf/pf_lb.c +++ b/sys/netpfil/pf/pf_lb.c @@ -535,6 +535,63 @@ pf_get_mape_sport(struct pf_pdesc *pd, struct pf_krule *r,  	return (1);  } +static __inline  u_short +pf_check_src_node_valid(struct pf_ksrc_node *sn, struct pf_kpool *rpool) +{ +	struct pf_addr		*raddr, *rmask; +	struct pf_addr		*caddr; /* cached redirection address */ +	struct pf_kpooladdr	*pa; +	sa_family_t		 raf; +	sa_family_t		 caf; /* cached redirection AF */ +	u_short			 valid = 0; + +	KASSERT(sn != NULL, ("sn is NULL")); +	KASSERT(rpool != NULL, ("rpool is NULL")); + +	/* check if the cached entry is still valid */ + +	if (sn->type ==  PF_SN_LIMIT) { +		/* Always valid as it does not store redirection address */ +		return (1); +	} + +	mtx_lock(&rpool->mtx); +	caddr = &(sn->raddr); +	caf = sn->raf; + +	TAILQ_FOREACH(pa, &rpool->list, entries) { +		if (PF_AZERO(caddr, caf)) { +			valid = 1; +			goto done; +		} else if (pa->addr.type == PF_ADDR_DYNIFTL) { +			if (pfr_kentry_byaddr(pa->addr.p.dyn->pfid_kt, caddr, caf, 0)) { +				valid = 1; +				goto done; +			} +		} else if (pa->addr.type == PF_ADDR_TABLE) { +			if (pfr_kentry_byaddr(pa->addr.p.tbl, caddr, caf, 0)) { +				valid = 1; +				goto done; +			} +		} else if (pa->addr.type != PF_ADDR_NOROUTE) { +			/* PF_ADDR_URPFFAILED, PF_ADDR_RANGE, PF_ADDR_ADDRMASK */ +			raddr = &(pa->addr.v.a.addr); +			rmask = &(pa->addr.v.a.mask); +			raf = pa->af; +			if (raf == caf && pf_match_addr(0, raddr, rmask, caddr, caf)) { +				valid = 1; +				goto done; +			} +		} +		/* else PF_ADDR_NOROUTE */ +	} + +done: +	mtx_unlock(&rpool->mtx); + +	return (valid); +} +  u_short  pf_map_addr(sa_family_t saf, struct pf_krule *r, struct pf_addr *saddr,      struct pf_addr *naddr, struct pfi_kkif **nkif, sa_family_t *naf, @@ -874,6 +931,45 @@ pf_map_addr_sn(sa_family_t saf, struct pf_krule *r, struct pf_addr *saddr,  	if (sn != NULL) {  		PF_SRC_NODE_LOCK_ASSERT(sn); +		/* +		 * Check if source node's redirection address still exists +		 * in pool from which the SN was created. If not, delete it. +		 * Similar to pf_kill_srcnodes(). Unlink the source node +		 * from tree, unlink it from states, then free it. Do not +		 * overlap source node and state locks to avoid LOR. +		 */ +		if (!pf_check_src_node_valid(sn, rpool)) { +			pf_unlink_src_node(sn); +			PF_SRC_NODE_UNLOCK(sn); +			if (V_pf_status.debug >= PF_DEBUG_NOISY) { +				printf("%s: stale src tracking (%d) ", +				    __func__, sn_type); +				pf_print_host(saddr, 0, saf); +				printf(" to "); +				pf_print_host(&(sn->raddr), 0, sn->raf); +				if (nkif) +					printf("@%s", sn->rkif->pfik_name); +				printf("\n"); +			} + +			for (int i = 0; i <= V_pf_hashmask; i++) { +				struct pf_idhash *ih = &V_pf_idhash[i]; +				struct pf_kstate *st; + +				PF_HASHROW_LOCK(ih); +				LIST_FOREACH(st, &ih->states, entry) { +					if (st->sns[sn->type] == sn) { +						st->sns[sn->type] = NULL; +					} +				} +				PF_HASHROW_UNLOCK(ih); +			} +			pf_free_src_node(sn); +			counter_u64_add(V_pf_status.scounters[SCNT_SRC_NODE_REMOVALS], 1); +			sn = NULL; +			goto map_addr; +		} +  		(*naf) = sn->raf;  		/* If the supplied address is the same as the current one we've @@ -902,9 +998,10 @@ pf_map_addr_sn(sa_family_t saf, struct pf_krule *r, struct pf_addr *saddr,  		goto done;  	} +map_addr:  	/* -	 * Source node has not been found. Find a new address and store it -	 * in variables given by the caller. +	 * Source node has not been found or is invalid. Find a new address +	 * and store it in variables given by the caller.  	 */  	if ((reason = pf_map_addr(saf, r, saddr, naddr, nkif, naf, init_addr,  	    rpool)) != 0) { @@ -974,6 +1071,7 @@ pf_get_transaddr(struct pf_test_ctx *ctx, struct pf_krule *r,  {  	struct pf_pdesc	*pd = ctx->pd;  	struct pf_addr	*naddr; +	int		 idx;  	uint16_t	*nportp;  	uint16_t	 low, high;  	u_short		 reason; @@ -988,8 +1086,19 @@ pf_get_transaddr(struct pf_test_ctx *ctx, struct pf_krule *r,  			return (PFRES_MEMORY);  	} -	naddr = &ctx->nk->addr[1]; -	nportp = &ctx->nk->port[1]; +	switch (nat_action) { +	case PF_NAT: +		idx = pd->sidx; +		break; +	case PF_BINAT: +		idx = 1; +		break; +	case PF_RDR: +		idx = pd->didx; +		break; +	} +	naddr = &ctx->nk->addr[idx]; +	nportp = &ctx->nk->port[idx];  	switch (nat_action) {  	case PF_NAT: diff --git a/sys/netpfil/pf/pf_table.c b/sys/netpfil/pf/pf_table.c index 73ec18fa7646..cf752ce0de18 100644 --- a/sys/netpfil/pf/pf_table.c +++ b/sys/netpfil/pf/pf_table.c @@ -2071,7 +2071,7 @@ pfr_lookup_table(struct pfr_table *tbl)  	    (struct pfr_ktable *)tbl));  } -static struct pfr_kentry * +struct pfr_kentry *  pfr_kentry_byaddr(struct pfr_ktable *kt, struct pf_addr *a, sa_family_t af,      int exact)  { diff --git a/sys/powerpc/include/openpicvar.h b/sys/powerpc/include/openpicvar.h index 3a170a8a35fe..12f01cb80406 100644 --- a/sys/powerpc/include/openpicvar.h +++ b/sys/powerpc/include/openpicvar.h @@ -28,6 +28,8 @@  #ifndef	_POWERPC_OPENPICVAR_H_  #define	_POWERPC_OPENPICVAR_H_ +#include <sys/kobj.h> +  #define OPENPIC_DEVSTR	"OpenPIC Interrupt Controller"  #define OPENPIC_IRQMAX	256	/* h/w allows more */ @@ -75,16 +77,11 @@ int	openpic_common_attach(device_t, uint32_t);  /*   * PIC interface.   */ -void	openpic_bind(device_t dev, u_int irq, cpuset_t cpumask, void **);  void	openpic_config(device_t, u_int, enum intr_trigger, enum intr_polarity); -void	openpic_dispatch(device_t, struct trapframe *);  void	openpic_enable(device_t, u_int, u_int, void **);  void	openpic_eoi(device_t, u_int, void *); -void	openpic_ipi(device_t, u_int); -void	openpic_mask(device_t, u_int, void *);  void	openpic_unmask(device_t, u_int, void *); -int	openpic_suspend(device_t dev); -int	openpic_resume(device_t dev); +DECLARE_CLASS(openpic_class);  #endif /* _POWERPC_OPENPICVAR_H_ */ diff --git a/sys/powerpc/ofw/openpic_ofw.c b/sys/powerpc/ofw/openpic_ofw.c index fdab55fb30f5..4083e9eba749 100644 --- a/sys/powerpc/ofw/openpic_ofw.c +++ b/sys/powerpc/ofw/openpic_ofw.c @@ -68,29 +68,15 @@ static device_method_t  openpic_ofw_methods[] = {  	/* Device interface */  	DEVMETHOD(device_probe,		openpic_ofw_probe),  	DEVMETHOD(device_attach,	openpic_ofw_attach), -	DEVMETHOD(device_suspend,	openpic_suspend), -	DEVMETHOD(device_resume,	openpic_resume),  	/* PIC interface */ -	DEVMETHOD(pic_bind,		openpic_bind), -	DEVMETHOD(pic_config,		openpic_config), -	DEVMETHOD(pic_dispatch,		openpic_dispatch), -	DEVMETHOD(pic_enable,		openpic_enable), -	DEVMETHOD(pic_eoi,		openpic_eoi), -	DEVMETHOD(pic_ipi,		openpic_ipi), -	DEVMETHOD(pic_mask,		openpic_mask), -	DEVMETHOD(pic_unmask,		openpic_unmask), -  	DEVMETHOD(pic_translate_code,	openpic_ofw_translate_code),  	DEVMETHOD_END  }; -static driver_t openpic_ofw_driver = { -	"openpic", -	openpic_ofw_methods, -	sizeof(struct openpic_softc), -}; +DEFINE_CLASS_1(openpic, openpic_ofw_driver, openpic_ofw_methods, +    sizeof(struct openpic_softc), openpic_class);  EARLY_DRIVER_MODULE(openpic, ofwbus, openpic_ofw_driver, 0, 0,      BUS_PASS_INTERRUPT); diff --git a/sys/powerpc/powermac/cpcht.c b/sys/powerpc/powermac/cpcht.c index 138aefda5cdb..448144c9749e 100644 --- a/sys/powerpc/powermac/cpcht.c +++ b/sys/powerpc/powermac/cpcht.c @@ -113,7 +113,7 @@ static device_method_t	cpcht_methods[] = {  struct cpcht_irq {  	enum {  	    IRQ_NONE, IRQ_HT, IRQ_MSI, IRQ_INTERNAL -	}		irq_type;  +	}		irq_type;  	int		ht_source; @@ -287,7 +287,7 @@ cpcht_configure_htbridge(device_t dev, phandle_t child)  			sc->htirq_map[irq].irq_type = IRQ_HT;  			sc->htirq_map[irq].ht_source = i; -			sc->htirq_map[irq].ht_base = sc->sc_data +  +			sc->htirq_map[irq].ht_base = sc->sc_data +  			    (((((s & 0x1f) << 3) | (f & 0x07)) << 8) | (ptr));  			PCIB_WRITE_CONFIG(dev, b, s, f, @@ -298,13 +298,13 @@ cpcht_configure_htbridge(device_t dev, phandle_t child)  			/*  			 * Apple uses a non-compliant IO/APIC that differs -			 * in how we signal EOIs. Check if this device was  +			 * in how we signal EOIs. Check if this device was  			 * made by Apple, and act accordingly.  			 */  			vend = PCIB_READ_CONFIG(dev, b, s, f,  			    PCIR_DEVVENDOR, 4);  			if ((vend & 0xffff) == 0x106b) -				sc->htirq_map[irq].apple_eoi =  +				sc->htirq_map[irq].apple_eoi =  				 (sc->htirq_map[irq].ht_base - ptr) + 0x60;  		}  	} @@ -318,7 +318,7 @@ cpcht_read_config(device_t dev, u_int bus, u_int slot, u_int func, u_int reg,  	vm_offset_t	caoff;  	sc = device_get_softc(dev); -	caoff = sc->sc_data +  +	caoff = sc->sc_data +  		(((((slot & 0x1f) << 3) | (func & 0x07)) << 8) | reg);  	if (bus == 0 && (!(sc->sc_populated_slots & (1 << slot)) || func > 0)) @@ -350,7 +350,7 @@ cpcht_write_config(device_t dev, u_int bus, u_int slot, u_int func,  	vm_offset_t	caoff;  	sc = device_get_softc(dev); -	caoff = sc->sc_data +  +	caoff = sc->sc_data +  		(((((slot & 0x1f) << 3) | (func & 0x07)) << 8) | reg);  	if (bus == 0 && (!(sc->sc_populated_slots & (1 << slot)) || func > 0)) @@ -520,16 +520,12 @@ static device_method_t  openpic_cpcht_methods[] = {  	DEVMETHOD(device_attach,	openpic_cpcht_attach),  	/* PIC interface */ -	DEVMETHOD(pic_bind,		openpic_bind),  	DEVMETHOD(pic_config,		openpic_cpcht_config), -	DEVMETHOD(pic_dispatch,		openpic_dispatch),  	DEVMETHOD(pic_enable,		openpic_cpcht_enable),  	DEVMETHOD(pic_eoi,		openpic_cpcht_eoi), -	DEVMETHOD(pic_ipi,		openpic_ipi), -	DEVMETHOD(pic_mask,		openpic_mask),  	DEVMETHOD(pic_unmask,		openpic_cpcht_unmask), -	{ 0, 0 }, +	DEVMETHOD_END  };  struct openpic_cpcht_softc { @@ -538,11 +534,8 @@ struct openpic_cpcht_softc {  	struct mtx sc_ht_mtx;  }; -static driver_t openpic_cpcht_driver = { -	"htpic", -	openpic_cpcht_methods, -	sizeof(struct openpic_cpcht_softc), -}; +DEFINE_CLASS_1(htpic, openpic_cpcht_driver, openpic_cpcht_methods, +    sizeof(struct openpic_cpcht_softc), openpic_class);  EARLY_DRIVER_MODULE(openpic, unin, openpic_cpcht_driver, 0, 0,      BUS_PASS_INTERRUPT); @@ -553,7 +546,7 @@ openpic_cpcht_probe(device_t dev)  	const char *type = ofw_bus_get_type(dev);  	if (strcmp(type, "open-pic") != 0) -                return (ENXIO); +		return (ENXIO);  	device_set_desc(dev, OPENPIC_DEVSTR);  	return (0); @@ -582,7 +575,7 @@ openpic_cpcht_attach(device_t dev)  	 * Interrupts 0-3 are internally sourced and are level triggered  	 * active low. Interrupts 4-123 are connected to a pulse generator  	 * and should be programmed as edge triggered low-to-high. -	 *  +	 *  	 * IBM CPC945 Manual, Section 9.3.  	 */ @@ -631,7 +624,7 @@ openpic_cpcht_config(device_t dev, u_int irq, enum intr_trigger trig,  		/* Mask the IRQ while we fiddle settings */  		out32rb(cpcht_irqmap[irq].ht_base + 4, ht_irq | HTAPIC_MASK); -		 +  		/* Program the interrupt sense */  		ht_irq &= ~(HTAPIC_TRIGGER_LEVEL | HTAPIC_REQUEST_EOI);  		if (trig == INTR_TRIGGER_EDGE) { @@ -671,7 +664,7 @@ openpic_cpcht_enable(device_t dev, u_int irq, u_int vec, void **priv)  		mtx_unlock_spin(&sc->sc_ht_mtx);  	} -		 +  	openpic_cpcht_eoi(dev, irq, *priv);  } diff --git a/sys/powerpc/powerpc/openpic.c b/sys/powerpc/powerpc/openpic.c index 0c717aaf6060..aa28f63cb6f5 100644 --- a/sys/powerpc/powerpc/openpic.c +++ b/sys/powerpc/powerpc/openpic.c @@ -225,7 +225,7 @@ openpic_common_attach(device_t dev, uint32_t node)   * PIC I/F methods   */ -void +static void  openpic_bind(device_t dev, u_int irq, cpuset_t cpumask, void **priv __unused)  {  	struct openpic_softc *sc; @@ -280,18 +280,7 @@ openpic_config(device_t dev, u_int irq, enum intr_trigger trig,  	openpic_write(sc, OPENPIC_SRC_VECTOR(irq), x);  } -static int -openpic_intr(void *arg) -{ -	device_t dev = (device_t)(arg); - -	/* XXX Cascaded PICs do not pass non-NULL trapframes! */ -	openpic_dispatch(dev, NULL); - -	return (FILTER_HANDLED); -} - -void +static void  openpic_dispatch(device_t dev, struct trapframe *tf)  {  	struct openpic_softc *sc; @@ -311,6 +300,17 @@ openpic_dispatch(device_t dev, struct trapframe *tf)  	}  } +static int +openpic_intr(void *arg) +{ +	device_t dev = (device_t)(arg); + +	/* XXX Cascaded PICs do not pass non-NULL trapframes! */ +	openpic_dispatch(dev, NULL); + +	return (FILTER_HANDLED); +} +  void  openpic_enable(device_t dev, u_int irq, u_int vector, void **priv __unused)  { @@ -343,7 +343,7 @@ openpic_eoi(device_t dev, u_int irq __unused, void *priv __unused)  	openpic_write(sc, OPENPIC_PCPU_EOI(cpuid), 0);  } -void +static void  openpic_ipi(device_t dev, u_int cpu)  {  	struct openpic_softc *sc; @@ -357,7 +357,7 @@ openpic_ipi(device_t dev, u_int cpu)  	sched_unpin();  } -void +static void  openpic_mask(device_t dev, u_int irq, void *priv __unused)  {  	struct openpic_softc *sc; @@ -393,7 +393,7 @@ openpic_unmask(device_t dev, u_int irq, void *priv __unused)  	}  } -int +static int  openpic_suspend(device_t dev)  {  	struct openpic_softc *sc; @@ -424,7 +424,7 @@ openpic_suspend(device_t dev)  	return (0);  } -int +static int  openpic_resume(device_t dev)  {      	struct openpic_softc *sc; @@ -453,3 +453,24 @@ openpic_resume(device_t dev)  	return (0);  } + +static device_method_t openpic_methods[] = { +	/* Device interface */ +	DEVMETHOD(device_suspend,	openpic_suspend), +	DEVMETHOD(device_resume,	openpic_resume), + +	/* PIC interface */ +	DEVMETHOD(pic_bind,		openpic_bind), +	DEVMETHOD(pic_config,		openpic_config), +	DEVMETHOD(pic_dispatch,		openpic_dispatch), +	DEVMETHOD(pic_enable,		openpic_enable), +	DEVMETHOD(pic_eoi,		openpic_eoi), +	DEVMETHOD(pic_ipi,		openpic_ipi), +	DEVMETHOD(pic_mask,		openpic_mask), +	DEVMETHOD(pic_unmask,		openpic_unmask), + +	DEVMETHOD_END +}; + +DEFINE_CLASS_0(openpic, openpic_class, openpic_methods, +    sizeof(struct openpic_softc)); diff --git a/sys/powerpc/psim/openpic_iobus.c b/sys/powerpc/psim/openpic_iobus.c index bf5bd8235a6c..21950e248b6d 100644 --- a/sys/powerpc/psim/openpic_iobus.c +++ b/sys/powerpc/psim/openpic_iobus.c @@ -69,22 +69,11 @@ static device_method_t  openpic_iobus_methods[] = {  	DEVMETHOD(device_probe,		openpic_iobus_probe),  	DEVMETHOD(device_attach,	openpic_iobus_attach), -	/* PIC interface */ -	DEVMETHOD(pic_config,		openpic_config), -	DEVMETHOD(pic_dispatch,		openpic_dispatch), -	DEVMETHOD(pic_enable,		openpic_enable), -	DEVMETHOD(pic_eoi,		openpic_eoi), -	DEVMETHOD(pic_ipi,		openpic_ipi), -	DEVMETHOD(pic_mask,		openpic_mask), -	DEVMETHOD(pic_unmask,		openpic_unmask), -	{ 0, 0 } +	DEVMETHOD_END  }; -static driver_t openpic_iobus_driver = { -	"openpic", -	openpic_iobus_methods, -	sizeof(struct openpic_softc) -}; +DEFINE_CLASS_1(openpic, openpic_iobus_driver, openpic_iobus_methods, +    sizeof(struct openpic_softc), openpic_class);  DRIVER_MODULE(openpic, iobus, openpic_iobus_driver, 0, 0); diff --git a/sys/riscv/riscv/fpe.c b/sys/riscv/riscv/fpe.c index b6c66e5e4f09..63103a794a8e 100644 --- a/sys/riscv/riscv/fpe.c +++ b/sys/riscv/riscv/fpe.c @@ -69,39 +69,39 @@ fpe_store(struct fpreg *regs)  	__asm __volatile(  	    "frcsr	%0		\n" -	    "fsd	f0, (16 * 0)(%1)\n" -	    "fsd	f1, (16 * 1)(%1)\n" -	    "fsd	f2, (16 * 2)(%1)\n" -	    "fsd	f3, (16 * 3)(%1)\n" -	    "fsd	f4, (16 * 4)(%1)\n" -	    "fsd	f5, (16 * 5)(%1)\n" -	    "fsd	f6, (16 * 6)(%1)\n" -	    "fsd	f7, (16 * 7)(%1)\n" -	    "fsd	f8, (16 * 8)(%1)\n" -	    "fsd	f9, (16 * 9)(%1)\n" -	    "fsd	f10, (16 * 10)(%1)\n" -	    "fsd	f11, (16 * 11)(%1)\n" -	    "fsd	f12, (16 * 12)(%1)\n" -	    "fsd	f13, (16 * 13)(%1)\n" -	    "fsd	f14, (16 * 14)(%1)\n" -	    "fsd	f15, (16 * 15)(%1)\n" -	    "fsd	f16, (16 * 16)(%1)\n" -	    "fsd	f17, (16 * 17)(%1)\n" -	    "fsd	f18, (16 * 18)(%1)\n" -	    "fsd	f19, (16 * 19)(%1)\n" -	    "fsd	f20, (16 * 20)(%1)\n" -	    "fsd	f21, (16 * 21)(%1)\n" -	    "fsd	f22, (16 * 22)(%1)\n" -	    "fsd	f23, (16 * 23)(%1)\n" -	    "fsd	f24, (16 * 24)(%1)\n" -	    "fsd	f25, (16 * 25)(%1)\n" -	    "fsd	f26, (16 * 26)(%1)\n" -	    "fsd	f27, (16 * 27)(%1)\n" -	    "fsd	f28, (16 * 28)(%1)\n" -	    "fsd	f29, (16 * 29)(%1)\n" -	    "fsd	f30, (16 * 30)(%1)\n" -	    "fsd	f31, (16 * 31)(%1)\n" -	    : "=&r"(fcsr), "=r"(fp_x), "=m"(*fp_x)); +	    "fsd	f0, (16 * 0)(%2)\n" +	    "fsd	f1, (16 * 1)(%2)\n" +	    "fsd	f2, (16 * 2)(%2)\n" +	    "fsd	f3, (16 * 3)(%2)\n" +	    "fsd	f4, (16 * 4)(%2)\n" +	    "fsd	f5, (16 * 5)(%2)\n" +	    "fsd	f6, (16 * 6)(%2)\n" +	    "fsd	f7, (16 * 7)(%2)\n" +	    "fsd	f8, (16 * 8)(%2)\n" +	    "fsd	f9, (16 * 9)(%2)\n" +	    "fsd	f10, (16 * 10)(%2)\n" +	    "fsd	f11, (16 * 11)(%2)\n" +	    "fsd	f12, (16 * 12)(%2)\n" +	    "fsd	f13, (16 * 13)(%2)\n" +	    "fsd	f14, (16 * 14)(%2)\n" +	    "fsd	f15, (16 * 15)(%2)\n" +	    "fsd	f16, (16 * 16)(%2)\n" +	    "fsd	f17, (16 * 17)(%2)\n" +	    "fsd	f18, (16 * 18)(%2)\n" +	    "fsd	f19, (16 * 19)(%2)\n" +	    "fsd	f20, (16 * 20)(%2)\n" +	    "fsd	f21, (16 * 21)(%2)\n" +	    "fsd	f22, (16 * 22)(%2)\n" +	    "fsd	f23, (16 * 23)(%2)\n" +	    "fsd	f24, (16 * 24)(%2)\n" +	    "fsd	f25, (16 * 25)(%2)\n" +	    "fsd	f26, (16 * 26)(%2)\n" +	    "fsd	f27, (16 * 27)(%2)\n" +	    "fsd	f28, (16 * 28)(%2)\n" +	    "fsd	f29, (16 * 29)(%2)\n" +	    "fsd	f30, (16 * 30)(%2)\n" +	    "fsd	f31, (16 * 31)(%2)\n" +	    : "=&r"(fcsr), "=m"(*fp_x) : "r"(fp_x));  	regs->fp_fcsr = fcsr;  } diff --git a/sys/sys/bus.h b/sys/sys/bus.h index e7ce152160f8..4cc8091bf775 100644 --- a/sys/sys/bus.h +++ b/sys/sys/bus.h @@ -600,6 +600,48 @@ bus_alloc_resource_anywhere(device_t dev, int type, int *rid,  	return (bus_alloc_resource(dev, type, rid, 0, ~0, count, flags));  } +/* Compat shims for bus_alloc_resource API. */ +static __inline struct resource * +bus_alloc_resource_const(device_t dev, int type, int rid, rman_res_t start, +    rman_res_t end, rman_res_t count, u_int flags) +{ +	return (bus_alloc_resource(dev, type, &rid, start, end, count, flags)); +} + +static __inline struct resource * +bus_alloc_resource_any_const(device_t dev, int type, int rid, u_int flags) +{ +	return (bus_alloc_resource(dev, type, &rid, 0, ~0, 1, flags)); +} + +static __inline struct resource * +bus_alloc_resource_anywhere_const(device_t dev, int type, int rid, +    rman_res_t count, u_int flags) +{ +	return (bus_alloc_resource(dev, type, &rid, 0, ~0, count, flags)); +} + +#define	bus_alloc_resource(dev, type, rid, start, end, count, flags)	\ +	_Generic((rid),							\ +	    int *: bus_alloc_resource,					\ +	    unsigned int *: bus_alloc_resource,				\ +	    default: bus_alloc_resource_const)				\ +	((dev), (type), (rid), (start), (end), (count), (flags)) + +#define	bus_alloc_resource_any(dev, type, rid, flags)			\ +	_Generic((rid),							\ +	    int *: bus_alloc_resource_any,				\ +	    unsigned int *: bus_alloc_resource_any,			\ +	    default: bus_alloc_resource_any_const)			\ +	((dev), (type), (rid), (flags)) + +#define	bus_alloc_resource_anywhere(dev, type, rid, count, flags)	\ +	_Generic((rid),							\ +	    int *: bus_alloc_resource_anywhere,				\ +	    unsigned int *: bus_alloc_resource_anywhere,		\ +	    default: bus_alloc_resource_anywhere_const)			\ +	((dev), (type), (rid), (count), (flags)) +  /* Compat shims for simpler bus resource API. */  int	bus_adjust_resource_old(device_t child, int type, struct resource *r,      rman_res_t start, rman_res_t end); diff --git a/sys/sys/param.h b/sys/sys/param.h index 7cfa3c6aa4a8..957f1762a17c 100644 --- a/sys/sys/param.h +++ b/sys/sys/param.h @@ -74,7 +74,7 @@   * cannot include sys/param.h and should only be updated here.   */  #undef __FreeBSD_version -#define __FreeBSD_version 1600002 +#define __FreeBSD_version 1600003  /*   * __FreeBSD_kernel__ indicates that this system uses the kernel of FreeBSD, | 
