1/*-
2 * Copyright (c) 2015 Landon Fuller <landon@landonf.org>
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
--- 14 unchanged lines hidden (view full) ---
23 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
25 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
27 * THE POSSIBILITY OF SUCH DAMAGES.
28 */
29
30#include <sys/cdefs.h>
31__FBSDID("$FreeBSD: head/sys/dev/bhnd/siba/siba_subr.c 300548 2016-05-24 01:12:19Z adrian $");
32
33#include <sys/param.h>
34#include <sys/bus.h>
35#include <sys/kernel.h>
36#include <sys/limits.h>
37#include <sys/systm.h>
38
39#include <machine/bus.h>
--- 199 unchanged lines hidden (view full) ---
239int
240siba_append_dinfo_region(struct siba_devinfo *dinfo, bhnd_port_type port_type,
241 u_int port_num, u_int region_num, uint8_t sid, uint32_t base, uint32_t size,
242 uint32_t bus_reserved)
243{
244 struct siba_addrspace *sa;
245 struct siba_port *port;
246 rman_res_t r_size;
247
248 /* Verify that base + size will not overflow */
249 if (UINT32_MAX - size < base)
250 return (ERANGE);
251
252 /* Verify that size - bus_reserved will not underflow */
253 if (size < bus_reserved)
254 return (ERANGE);
255
256 /* Must not be 0-length */
257 if (size == 0)
--- 13 unchanged lines hidden (view full) ---
271 sa->sa_size = size;
272 sa->sa_sid = sid;
273 sa->sa_region_num = region_num;
274 sa->sa_bus_reserved = bus_reserved;
275
276 /* Populate the resource list */
277 r_size = size - bus_reserved;
278 sa->sa_rid = resource_list_add_next(&dinfo->resources, SYS_RES_MEMORY,
279 base, base + r_size - 1, r_size);
280
281 /* Append to target port */
282 STAILQ_INSERT_TAIL(&port->sp_addrs, sa, sa_link);
283 port->sp_num_addrs++;
284
285 return (0);
286}
287
--- 96 unchanged lines hidden ---
2 * Copyright (c) 2015 Landon Fuller <landon@landonf.org>
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
--- 14 unchanged lines hidden (view full) ---
23 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
25 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
27 * THE POSSIBILITY OF SUCH DAMAGES.
28 */
29
30#include <sys/cdefs.h>
31__FBSDID("$FreeBSD: head/sys/dev/bhnd/siba/siba_subr.c 300548 2016-05-24 01:12:19Z adrian $");
32
33#include <sys/param.h>
34#include <sys/bus.h>
35#include <sys/kernel.h>
36#include <sys/limits.h>
37#include <sys/systm.h>
38
39#include <machine/bus.h>
--- 199 unchanged lines hidden (view full) ---
239int
240siba_append_dinfo_region(struct siba_devinfo *dinfo, bhnd_port_type port_type,
241 u_int port_num, u_int region_num, uint8_t sid, uint32_t base, uint32_t size,
242 uint32_t bus_reserved)
243{
244 struct siba_addrspace *sa;
245 struct siba_port *port;
246 rman_res_t r_size;
247
248 /* Verify that base + size will not overflow */
249 if (UINT32_MAX - size < base)
250 return (ERANGE);
251
252 /* Verify that size - bus_reserved will not underflow */
253 if (size < bus_reserved)
254 return (ERANGE);
255
256 /* Must not be 0-length */
257 if (size == 0)
--- 13 unchanged lines hidden (view full) ---
271 sa->sa_size = size;
272 sa->sa_sid = sid;
273 sa->sa_region_num = region_num;
274 sa->sa_bus_reserved = bus_reserved;
275
276 /* Populate the resource list */
277 r_size = size - bus_reserved;
278 sa->sa_rid = resource_list_add_next(&dinfo->resources, SYS_RES_MEMORY,
279 base, base + r_size - 1, r_size);
280
281 /* Append to target port */
282 STAILQ_INSERT_TAIL(&port->sp_addrs, sa, sa_link);
283 port->sp_num_addrs++;
284
285 return (0);
286}
287
--- 96 unchanged lines hidden ---