Commit graph

6135 commits

Author SHA1 Message Date
Kumar Gala e353d123fd zephyr: Make Zephyr int types deprecated by default
As the int types defined in include/zephyr/types.h are typdef's we
utilize a Kconfig option (LEGACY_ZEPHYR_INT_TYPES) to enable/disable
the support for them.  By default to LEGACY_ZEPHYR_INT_TYPES not
being enabled and add an explicit test to ensure the types continue to
function until removed in the future.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2020-06-08 08:23:57 -05:00
Kumar Gala a1b77fd589 zephyr: replace zephyr integer types with C99 types
git grep -l 'u\(8\|16\|32\|64\)_t' | \
		xargs sed -i "s/u\(8\|16\|32\|64\)_t/uint\1_t/g"
	git grep -l 's\(8\|16\|32\|64\)_t' | \
		xargs sed -i "s/s\(8\|16\|32\|64\)_t/int\1_t/g"

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2020-06-08 08:23:57 -05:00
Kumar Gala 7dc3ecd63d stdint.h: Make {u}int64_t types consistent regardless of arch
On 64-bit arch's like AARCH64, x86_64, or riscv-64 the way {u}int64_t
will differ from how its defined on 32-bit arch's.  Do the same trick we
do for {u}int32_t for {u}int64_t so that the type is the same regardless
of what we are building for.

This keeps things like %lld working the same regardless of 32-bit or
64-bit arch.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2020-06-08 08:23:57 -05:00
Andrew Boie be919d3bf7 userspace: improve dynamic object allocation
We now have a low-level function z_dynamic_object_create()
which is not a system call and is used for installing
kernel objects that are not supported by k_object_alloc().

Checking for valid object type enumeration values moved
completely to the implementation function.

A few debug messages and comments were improved.

Futexes and sys_mutexes are now properly excluded from
dynamic generation.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2020-06-03 22:33:32 +02:00
Andrew Boie 04bba6772b net: sockets: add API to fetch an fd's ctx object
Zephyr running on MPU devices have a different memory model than
process-oriented OSes like Linux and require a method to set
kernel object permissions on a file descriptor's underlying
context object. Add this, and a test to show that it is working.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2020-06-03 22:33:32 +02:00
Andrew Boie fed960b94a net: tag net socket objects
Used for permission validation when accessing the associated file
descriptors from user mode.

There often get defined in implementation code, expand the search
to look in drivers/ and subsys/net/.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2020-06-03 22:33:32 +02:00
Andrew Boie 299ec8f1b5 userspace: net sockets are kernel objects
Any data structure declaration tagged with __net_socket will end up
in the kernel object table with type K_OBJ_NET_SOCKET. These all
correspond to objects which are associated with socket file
descriptors and can handle the socket vtable API.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2020-06-03 22:33:32 +02:00
Andrew Boie 378024c510 userspace: add z_is_in_user_syscall()
Certain types of system call validation may need to be pushed
deeper in the implementation and not performed in the verification
function. If such checks are only pertinent when the caller was
from user mode, we need an API to detect this situation.

This is implemented by having thread->syscall_frame be non-NULL
only while a user system call is in progress. The template for the
system call marshalling functions is changed to clear this value
on exit.

A test is added to prove that this works.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2020-06-03 22:33:32 +02:00
Andrew Boie 36e70afcb5 kernel: fix k_object_free() spelling
This was supposed to match definitions if dynamic objects
are turned on.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2020-06-03 22:33:32 +02:00
Peter Bigot 76d8f8f1e2 include: sys: time_units: fix 32-bit near conversion for overflow
Adjusting the input value to allow round to nearest can cause an
overflow which invalidates the expectation that the 32-bit result is
the low 32 bits of the 64-bit result.  If the adjustment overflows do
the full-precision conversion and truncate in the caller.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
2020-06-03 01:49:42 +02:00
Andy Ross 99c2d2d047 kernel/queue: Remove interior use of k_poll()
The k_queue data structure, when CONFIG_POLL was enabled, would
inexplicably use k_poll() as its blocking mechanism instead of the
original wait_q/pend() code.  This was actually racy, see commit
b173e4353f.  The code was structured as a condition variable: using
a spinlock around the queue data before deciding to block.  But unlike
pend_current_thread(), k_poll() cannot atomically release a lock.

A workaround had been in place for this, and then accidentally
reverted (both by me!) because the code looked "wrong".

This is just fragile, there's no reason to have two implementations of
k_queue_get().  Remove.

Note that this also removes a test case in the work_queue test where
(when CONFIG_POLL was enabled, but not otherwise) it was checking for
the ability to immediately cancel a delayed work item that was
submitted with a timeout of K_NO_WAIT (i.e. "queue it immediately").
This DOES NOT work with the origina/non-poll queue backend, and has
never been a documented behavior of k_delayed_work_submit_to_queue()
under any circumstances.  I don't know why we were testing this.

Fixes #25904

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2020-06-03 01:47:41 +02:00
Peter Bigot 1f5a4228af timeout: correct non-legacy legacy timeout API
The implementation of Z_TIMEOUT_US() and Z_TIMEOUT_NS() in the legacy
timeout API is incorrect in that it multiplies the input value by the
scale factor rather than dividing it, making K_USEC(3) equivalent to
K_SECONDS(3).  Replace with implementation that doesn't surprise a
user that happens to find and use them.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
2020-06-02 15:21:45 +02:00
Peter A. Bigot fae5d96618 Bluetooth: GATT: correct callback return value documentation
The indicate callback does not provide a return value.  The read
callback didn't document its return values.

Signed-off-by: Peter A. Bigot <pab@pabigot.com>
2020-06-01 20:03:25 +02:00
Henrik Brix Andersen 3046e228e7 devicetree.h: pwms: Add DT_ macros for retrieving pwm period
Add DT_ macros for retrieving the value of the 'period' cell for PWM
controllers supporting this cell type.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2020-05-29 14:48:12 +02:00
Andrew Boie 32ebe3cd24 x86: 32-bit: allow direct ISRs only with !KPTI
This doesn't work as expected with kernel page table isolation
turned on, and fixing it would likely lose any latency benefits
that direct ISRs are supposed to provide.

For now, just prevent these macros from being defined if KPTI
is turned on, like other arches that do not implement this
feature.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2020-05-29 10:46:00 +02:00
Tomasz Bursztyka 549cfff6c9 device: Rephrase data parameter documentation
This parameter points to the driver instance private data, and not to
its configuration data, which one is set via cfg_info parameter.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2020-05-29 10:42:07 +02:00
Tomasz Bursztyka 794665e75b gpio: Fix header comments
There is no device config structure anymore, and
s/decleration/declaration

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2020-05-29 10:42:07 +02:00
Andrew Boie 6af9793f0c kernek: don't allow mutex ops in ISRs
Mutex operations check ownership against _current. But in an
ISR, _current is just whatever thread was interrupted when the
ISR fired. Explicitly do not allow this.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2020-05-28 01:38:05 +02:00
Trond Einar Snekvik a385873336 Bluetooth: Mesh: Fail init on model init error
Adds propagation of error returns from the model init callbacks in
Access, and removing any other checks for successful init in the
foundation models.

Signed-off-by: Trond Einar Snekvik <Trond.Einar.Snekvik@nordicsemi.no>
2020-05-27 18:45:18 +02:00
Kumar Gala da40dd4c78 devicetree: Fix argument order for DT_*_CELL_BY_IDX
The cell paramater should have been last to match both the
DT_*_CELL_BY_NAME macros as well as how DT_PHA_BY_IDX works.  We fix the
DT_INST_*_CELL_BY_NAME macros as well.

The dma macro's implemented the behavior correctly, but got the argument
names in correct.  We fix that to make everything consistent.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2020-05-27 17:58:35 +02:00
Martí Bolívar 0ec24ca867 doc: update devicetree/spi.h
This file needs more examples. Add them and make some other fixes and
improvements.

Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
2020-05-26 22:32:34 +02:00
Martí Bolívar 369dcadc0b doc: update devicetree/pwms.h
Align with other files.

Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
2020-05-26 22:32:34 +02:00
Martí Bolívar 4447098ca6 doc: update devicetree/gpio.h
Align with other headers.

Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
2020-05-26 22:32:34 +02:00
Martí Bolívar 0a8c8fc489 doc: update devicetree/fixed-partitions.h
Add an example and align style with other files.

Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
2020-05-26 22:32:34 +02:00
Martí Bolívar 815c4967f5 doc: update devicetree/dma.h
Align with devicetree/adc.h and devicetree/clocks.h conventions.

Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
2020-05-26 22:32:34 +02:00
Martí Bolívar 13965f2ef3 doc: update devicetree/clocks.h
Align with devicetree/adc.h conventions.

Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
2020-05-26 22:32:34 +02:00
Martí Bolívar 3b32b60b08 doc: update devicetree/adc.h
Make sure to include "DT_DRV_COMPAT" in the docstring for every macro
that requires it.

Some other cleanups and additional examples to try to make it easier
to decide which API to use. Make the style more regular.

Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
2020-05-26 22:32:34 +02:00
Martí Bolívar 31a90a0e7d doc: dts: simplify DT_INST documentation
Add some introductory text to these driver helpers which makes it more
clear how they are defined in terms of the generic APIs, which allows
removing some boilerplate from doxygen. This also gives us a chance to
call out the exceptional cases and add some more documentation to those.

Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
2020-05-26 22:32:34 +02:00
Martí Bolívar 9d36b4f6e4 doc: some devicetree fixes and updates
Some updates to the reference page for the "core" APIs, and associated
follow-ups in the guides:

- centralize documentation of chosen zephyr nodes in a non-legacy
  file, provide a reference to them from the intro page in the guide
- review doxygen docstrings and correct errors for generic APIs
- add introductory text to each section in the API reference
- add missing hardware-specific pages

Documentation for layers built on top of these is mostly left to future
commits, but I do have a smattering of fixes in the guides that I
noticed while I was doing this.

Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
2020-05-26 18:12:00 +02:00
Andrzej Puzdrowski 50ecfd2836 include/storage/steram_flash: update buffer size requirements
Implementation requires that streamer buffer size must be
multiple of the flash device wbs.
This patch reflects this in API documentation

Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
2020-05-26 16:35:19 +02:00
Anas Nashif 3e4cd1853e drivers: pwm: fix doxygen docs
When referencing parameters, use @p and not @param.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2020-05-25 17:16:56 +02:00
Peter Bigot 6a79436f05 kernel: document that busy-wait clock may differ from timeout clock
Some tests assumed that a delay with k_busy_wait() could be precisely
timed by a tick or cycle count, and vice versa.  This is not true for
all clock configurations on all Zephyr targets, so highlight the
potential variation.

As an example: on some platforms busy-wait is performed by a loop with
known duration in cycles of a known CPU frequency.  The CPU clock may
be unrelated to the clock that drives the system timer.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
2020-05-24 20:28:58 +02:00
Peter Bigot ae935dccdf device_pm: correct nop documented behavior
The device_pm_control_nop function is documented to always return zero
regardless of operation.  However, when device_get_power_state() is
invoked with this control function it returns success leaving the
output parameter state unmodified, which may not be a valid device
state.

Document and implement that the nop control function returns -ENOTSUP
always.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
2020-05-21 20:32:12 +02:00
Peter Bigot a189311798 drivers: pwm: remove extraneous whitespace
PR was merged before this was cleaned up.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
2020-05-19 22:27:41 -04:00
Daniel Leung 37516a7818 x86: add ability for SoC to add MMU regions
The SoCs usually have devices that are accessed through MMIO.
This requires the corresponding regions to be marked readable
and writable in the MMU or else accesses will result in page
faults.

This adds a function which can be implemented in the SoC code to
specify those pages to be added to MMU.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2020-05-19 19:19:51 +02:00
Daniel Leung 06e86b68e7 x86: intel64: add missing _locore_end to linker script
_locore_end is missing from the linker script so add it.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2020-05-19 19:19:51 +02:00
Alexander Wachter 31ae13eeb1 drivers: pwm: Clarify period parameter
Clarify what happens when the period parameter is zero or equal
to the period.

Signed-off-by: Alexander Wachter <alexander.wachter@leica-geosystems.com>
2020-05-19 18:27:42 +02:00
Sandeep Tripathy 17fcaa3fc4 drivers: timer: get ppi configuration from dt
Use device tree provided configurations for arm architecture timer
PPIs.

This fixes issue of timer ppi not working on most hardware where
edge-triggered PPI are not supported.

Signed-off-by: Sandeep Tripathy <sandeep.tripathy@broadcom.com>
2020-05-18 11:07:57 +02:00
Pete Johanson e550302a61 Bluetooth: Fix a typo in an HCI error code constant name
* Change "BT_HIC" to "BT_HCI" in one error constant.

Signed-off-by: Pete Johanson <peter@peterjohanson.com>
2020-05-16 22:39:10 +03:00
Andrew Boie d149909b03 x86: properly align initial dummy thread
x86-32 thread objects require special alignment since they
contain a buffer that is passed to fxsave/fxrstor instructions.
This fell over if the dummy thread is created in a stack frame.

Implement a custom swap to main for x86 which still uses a
dummy thread, but in an unused part of the interrupt stack
with proper alignment.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2020-05-13 21:23:52 +02:00
Kumar Gala 6133d51ef7 storage: flash_map: Add macros to get FLASH_AREA info
Add macros that we'll utilize instead of DT_FLASH_AREA_

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2020-05-13 21:22:53 +02:00
Kumar Gala bd97378870 devicetree: Add support for fixed-partitions
Add DT_NODE_BY_FIXED_PARTITION_LABEL that given a "label" in any
fixed-partitions map will return the node_id for that partition node.

Add DT_NODE_HAS_FIXED_PARTITION_LABEL that will test if a given
fixed-partitions "label" is valid.

Add DT_FIXED_PARTITION_ID that will return an unique ordinal value for
the partition give a node_id to the partition.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2020-05-13 21:22:53 +02:00
Gerard Marull-Paretas b35152ed4b devicetree: add DT_INST_FOREACH_CHILD macro
The macro iterates through the list of child nodes in a DT_DRV_COMPAT
instance and invokes provided macro for each node.

Signed-off-by: Gerard Marull-Paretas <gerard@teslabs.com>
2020-05-13 21:22:06 +02:00
Martí Bolívar 6e8775ff84 devicetree: remove DT_HAS_NODE_STATUS_OKAY
Several reviewers agreed that DT_HAS_NODE_STATUS_OKAY(...) was an
undesirable API for the following reasons:

- it's inconsistent with the rest of the DT_NODE_HAS_FOO names
- DT_NODE_HAS_FOO_BAR_BAZ(node) was agreed upon as a shorthand
  for macros which are equivalent to
  DT_NODE_HAS_FOO(node) && DT_NODE_HAS_BAR(node) &&
- DT_NODE_HAS_BAZ(node), and DT_HAS_NODE_STATUS_OKAY is an odd duck
- DT_NODE_HAS_STATUS(..., okay) was viewed as more readable anyway
- it is seen as a somewhat aesthetically challenged name

Replace all users with DT_NODE_HAS_STATUS(..., okay), which is
semantically equivalent.

This is mostly done with sed, but a few remaining cases were done by
hand, along with whitespace, docs, and comment changes. These special
cases include the Nordic SOC static assert files.

Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
2020-05-13 18:24:42 +02:00
Peter Bigot 4f16b419e8 device: avoid casting away const from config_info pointer
The driver-specific config_info structure referenced from the device
structure is marked const.  Some drivers fail to preserve that
qualifier when casting the pointer to the driver-specific structure,
violating MISRA 11.8.

Changes produced by scripts/coccinelle/const_config_info.cocci.

Some changes proposed by the script are not included because they
reveal mutation of state through the const pointer, though the
code works as long as the driver-specific object is defined without
the const qualifier.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
2020-05-13 18:21:52 +02:00
Christopher Friedt 09f957c47a net: socket: syscall for socketpair(2)
Working:

* non-blocking reads / writes
* blocking reads / writes
* send(2) / recv(2) / sendto(2) / recvfrom(2) / sendmsg(2)
* select(2)
* poll(2)

Fixes #24366

Signed-off-by: Christopher Friedt <chrisfriedt@gmail.com>
2020-05-10 17:46:43 +02:00
Sandeep Tripathy fa9ba6ed0b arch: arm64: cortex-a72: add L2 specific defines
Add Cortex-A72 core implementation specific defines for L2 cache
configurations.

Signed-off-by: Sandeep Tripathy <sandeep.tripathy@broadcom.com>
2020-05-09 12:23:40 +02:00
Zide Chen f32eeba925 dts: x86: configure different IO APIC delivery modes for various devices
For HPET devices, configure it with fixed delivery mode because HPET
timer interrupt is needed to fuel the scheduler for all CPUS.

For all other type of devices, like UART, I2C, GPIO, Ethernet, etc.
configure them as lowest priority delivery mode, in which IO APIC
delivers the interrupt to the processor core that is executing at the
lowest priority among all the processors listed in the specified
destination. In this case, the device drivers can avoid the trouble of
handling repeated interrupts delivered to all CPUS.

Signed-off-by: Zide Chen <zide.chen@intel.com>
2020-05-08 22:32:39 -04:00
Zide Chen d27f6cb5eb interrupt_controller: program local APIC LDR register for xAPIC
If IO APIC is in logical destination mode, local APICs compare their
logical APIC ID defined in LDR (Logical Destination Register) with
the destination code sent with the interrupt to determine whether or not
to accept the incoming interrupt.

This patch programs LDR in xAPIC mode to support IO APIC logical mode.

The local APIC ID from local APIC ID register can't be used as the
'logical APIC ID' because LAPIC ID may not be consecutive numbers hence
it makes it impossible for LDR to encode 8 IDs within 8 bits.

This patch chooses 0 for BSP, and for APs, cpu_number which is the index
to x86_cpuboot[], which ultimately assigned in z_smp_init[].

Signed-off-by: Zide Chen <zide.chen@intel.com>
2020-05-08 22:32:39 -04:00
Kumar Gala c2135f8721 devicetree: DT_NODE_HAS_COMPAT_STATUS_OKAY -> DT_NODE_HAS_COMPAT_STATUS
Swap this out and make the status a parameter.
Leave a couple of cases of DT_NODE_HAS_COMPAT().

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
2020-05-08 19:37:18 -05:00