RISC-V Linux Port v1
Subsystems (21)
Palmer Dabbelt
maintainerRe: [PATCH 10/17] irqchip: New RISC-V PLIC Driver
In reply to Marc ZyngierQuoted 27 lines · On Wed, 07 Jun 2017 03:52:10 PDT (-0700), [email protected] wrote:
Hi Palmer,
Quoted 24 lines · Palmer Dabbelt
This patch adds a driver for the Platform Level Interrupt Controller (PLIC) specified as part of the RISC-V supervisor level ISA manual. The PLIC connocts global interrupt sources to the local interrupt controller on each hart. A PLIC is present on all RISC-V systems.
Signed-off-by Palmer Dabbelt <[email protected]>--- drivers/irqchip/Kconfig | 12 ++ drivers/irqchip/Makefile | 1 + drivers/irqchip/irq-riscv-plic.c | 253 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 266 insertions(+) create mode 100644 drivers/irqchip/irq-riscv-plic.cdrivers/irqchip/Kconfig +3
-0@@ -301,3 +301,15 @@ config QCOM_IRQ_COMBINER help Say yes here to add support for the IRQ combiner devices embedded in Qualcomm Technologies chips. + +config RISCV_PLIC + bool "Platform-Level Interrupt Controller"
Quoted 8 lines
drivers/irqchip/Kconfig config QCOM_IRQ_COMBINER · line 311
Quoted 5 lines
drivers/irqchip/Kconfig +5
-0+ depends on RISCV + default y + help + This enables support for the PLIC chip found in standard RISC-V + systems. The PLIC is the top-most interrupt controller found innit: this seems to slightly contradict what is being said in patch #8, where the HLIC is the top-level interrupt controller.
Sorry, I guess that was a bit confusing: by "top-level interrupt controller found in the system" I meant the stuff outside the core complex -- in other words, all the devices. How does this sound instead?
This enables support for the PLIC chip found in standard RISC-V systems. The PLIC controls devices interrupts and connects them to each core's local interrupt controller. Aside from timer and software interrupts, all other interrupt sources (MSI, GPIO, etc) are subordinate to the PLIC.
https://github.com/riscv/riscv-linux/commit/2395b17a36c3cf5aabd9b019e1f8fc7efe67e9a0
Quoted 53 lines
Quoted 53 lines
drivers/irqchip/Kconfig +4
-0+ the system, connected directly to the core complex. All other + interrupt sources (MSI, GPIO, etc) are subordinate to the PLIC. + + If you don't know what to do here, say Y.drivers/irqchip/Makefile +1
-0@@ -76,3 +76,4 @@ obj-$(CONFIG_EZNPS_GIC) += irq-eznps.o obj-$(CONFIG_ARCH_ASPEED) += irq-aspeed-vic.o obj-$(CONFIG_STM32_EXTI) += irq-stm32-exti.o obj-$(CONFIG_QCOM_IRQ_COMBINER) += qcom-irq-combiner.o +obj-$(CONFIG_RISCV_PLIC) += irq-riscv-plic.odrivers/irqchip/irq-riscv-plic.c new file +34
-0@@ -0,0 +1,253 @@ +/* +* Copyright (C) 2017 SiFive +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation, version 2. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +*/ + +#include <linux/interrupt.h> +#include <linux/io.h> +#include <linux/irq.h> +#include <linux/irqchip.h> +#include <linux/irqchip/chained_irq.h> +#include <linux/irqdomain.h> +#include <linux/module.h> +#include <linux/of.h> +#include <linux/of_address.h> +#include <linux/of_irq.h> +#include <linux/platform_device.h> + +/* From the RISC-V Privlidged Spec v1.10: +* +* Global interrupt sources are assigned small unsigned integer identifiers, +* beginning at the value 1. An interrupt ID of 0 is reserved to mean “no +* interrupt”. Interrupt identifiers are also used to break ties when two or +* more interrupt sources have the same assigned priority. Smaller values of +* interrupt ID take precedence over larger values of interrupt ID. +* +* It's not defined what the largest device ID is, so we're just fixing
Quoted 8 lines
drivers/irqchip/irq-riscv-plic.c line 39
Quoted 5 lines
drivers/irqchip/irq-riscv-plic.c new file +5
-0+* MAX_DEVICES right here (which is named oddly, as there will never be a +* device 0). +*/ +#define MAX_DEVICES 1024 +#define MAX_CONTEXTS 15872If those are HW properties, they should probably come from the device tree instead of being hardcoded here.
Sorry, this is a bit confusing: the RISC-V supervisor spec (which is what this comment was about) doesn't actually specify much about the PLIC, while this driver is for the concrete 'riscv,plic0' device (which is SiFive's PLIC implementation, and will be part of the platform specification). Maybe this is a better comment?
* While the RISC-V supervisor spec doesn't define the maximum number of
* devices supported by the PLIC, the largest number supported by devices
* marked as 'riscv,plic0' (which is the only device type this driver supports,
* and is the only extant PLIC as of now) is 1024. As mentioned above, device
* 0 is defined to be non-existant so this device really only supports 1023
* devices.
https://github.com/riscv/riscv-linux/commit/ef43982522f84874be3dfba24f5acb57ad0d9186
Quoted 8 lines
Quoted 8 lines
drivers/irqchip/irq-riscv-plic.c new file +8
-0+ +#define PRIORITY_BASE 0 +#define ENABLE_BASE 0x2000 +#define ENABLE_SIZE 0x80 +#define HART_BASE 0x200000 +#define HART_SIZE 0x1000 + +struct plic_hart_context {
Quoted 8 lines
drivers/irqchip/irq-riscv-plic.c line 50
Quoted 3 lines
drivers/irqchip/irq-riscv-plic.c new file +3
-0+u32 threshold; +u32 claim; +};Representing HW layout as a C structure is not something we usually do in the kernel. It relies on the ABI (which may change over time), and makes it harder to quickly distinguish what is a SW concept from what's not. It also leads to some of the mistakes below...
OK, makes sense. I went ahead and removed
Quoted 149 lines
drivers/irqchip/irq-riscv-plic.c line 53
Quoted 3 lines
drivers/irqchip/irq-riscv-plic.c new file +3
-0+ +struct plic_enable_context { +atomic_t mask[32 ];// 32-bit * 32-entry /* */ comments please, placed above the field.
Quoted 4 lines
drivers/irqchip/irq-riscv-plic.c new file +4
-0+}; + +struct plic_priority { +u32 prio[MAX_DEVICES ];drivers/irqchip/irq-riscv-plic.c line 67
Quoted 10 lines
drivers/irqchip/irq-riscv-plic.c new file +10
-0+}; + +struct plic_data { +struct irq_chip chip; +struct irq_domain *domain; +u32 ndev; +void __iomem *reg; +int handlers; +struct plic_handler *handler; +char name[30 ];Why 30? #define?
drivers/irqchip/irq-riscv-plic.c line 76
Quoted 9 lines
drivers/irqchip/irq-riscv-plic.c new file +9
-0+}; + +struct plic_handler { +struct plic_hart_context *context; +struct plic_data *data; +}; + +static inline +struct plic_hart_context *plic_hart_context (struct plic_data *data,size_t i)What is 'i' here?
drivers/irqchip/irq-riscv-plic.c line 78
Quoted 2 lines
drivers/irqchip/irq-riscv-plic.c new file +2
-0+{ +return (struct plic_hart_context *)((char *)data->reg +HART_BASE +HART_SIZE *i);This looks dodgy on a number of levels:
- the various levels of casts are useless
- what you return is still an__iomemSparse would certainly shout at you if you ran it on this file.
Same comment for the two functions below.
Quoted 9 lines
drivers/irqchip/irq-riscv-plic.c new file +9
-0+} + +static inline +struct plic_enable_context *plic_enable_context (struct plic_data *data,size_t i) +{ +return (struct plic_enable_context *)((char *)data->reg +ENABLE_BASE +ENABLE_SIZE *i); +} + +static inlinedrivers/irqchip/irq-riscv-plic.c line 97
Quoted 10 lines
drivers/irqchip/irq-riscv-plic.c new file +10
-0+struct plic_priority *plic_priority (struct plic_data *data) +{ +return (struct plic_priority *)((char *)data->reg +PRIORITY_BASE ); +} + +static void plic_disable (struct plic_data *data,int i,int hwirq) +{ +struct plic_enable_context *enable =plic_enable_context (data, i); + +atomic_and (~(1 << (hwirq %32 )), &enable->mask[hwirq /32 ]);This is still a device access, right? What does it mean to use the atomic primitives on that? What are you racing against? I thought the various context were private to an execution context...
Adding Will and PeterZ to the CC list because they will probably have their own views on this...
drivers/irqchip/irq-riscv-plic.c line 108
Quoted 11 lines
drivers/irqchip/irq-riscv-plic.c new file +11
-0+} + +static void plic_enable (struct plic_data *data,int i,int hwirq) +{ +struct plic_enable_context *enable =plic_enable_context (data, i); + +atomic_or ((1 << (hwirq %32 )), &enable->mask[hwirq /32 ]); +} + +// There is no need to mask/unmask PLIC interrupts +// They are "masked" by reading claim and "unmasked" when writing it back. Hmmm. What you describe here is the FastEOI flow.
drivers/irqchip/irq-riscv-plic.c line 118
Quoted 10 lines
drivers/irqchip/irq-riscv-plic.c new file +10
-0+static void plic_irq_mask (struct irq_data *d) { } +static void plic_irq_unmask (struct irq_data *d) { } + +static void plic_irq_enable (struct irq_data *d) +{ +struct plic_data *data =irq_data_get_irq_chip_data (d); +struct plic_priority *priority =plic_priority (data); +int i; + +iowrite32 (1 , &priority->prio[d->hwirq]);Using iowrite is only meaningful if your architecture has an actual I/O address space that is distinct from the "normal" address space. Using the write{b,w,l}{_relaxed} accessors would make more sense if you're not in that case.
Quoted 46 lines
drivers/irqchip/irq-riscv-plic.c new file +46
-0+for (i =0 ; i < data->handlers; ++i) +if (data->handler[i].context) +plic_enable (data, i, d->hwirq); +} + +static void plic_irq_disable (struct irq_data *d) +{ +struct plic_data *data =irq_data_get_irq_chip_data (d); +struct plic_priority *priority =plic_priority (data); +int i; + +iowrite32 (0 , &priority->prio[d->hwirq]); +for (i =0 ; i < data->handlers; ++i) +if (data->handler[i].context) +plic_disable (data, i, d->hwirq); +} + +static int plic_irqdomain_map (struct irq_domain *d,unsigned int irq, +irq_hw_number_t hwirq) +{ +struct plic_data *data = d->host_data; + +irq_set_chip_and_handler (irq, &data->chip, handle_simple_irq); +irq_set_chip_data (irq, data); +irq_set_noprobe (irq); + +return 0 ; +} + +static const struct irq_domain_ops plic_irqdomain_ops = { + .map = plic_irqdomain_map, + .xlate = irq_domain_xlate_onecell, +}; + +static void plic_chained_handle_irq (struct irq_desc *desc) +{ +struct plic_handler *handler =irq_desc_get_handler_data (desc); +struct irq_chip *chip =irq_desc_get_chip (desc); +struct irq_domain *domain = handler->data->domain; +u32 what; + +chained_irq_enter (chip, desc); + +while ((what =ioread32 (&handler->context->claim))) { +int irq =irq_find_mapping (domain, what); +
Quoted 8 lines
drivers/irqchip/irq-riscv-plic.c line 169
Quoted 5 lines
drivers/irqchip/irq-riscv-plic.c new file +5
-0+if (irq >0 ) +generic_handle_irq (irq); +else +handle_bad_irq (desc); +iowrite32 (what, &handler->context->claim);So this is your EOI. It should be represented as such, instead of abusing the
handle_simple_irqflow.
OK, I think that makes sense. From my understanding of this, when using the FastEOI flow we'll get a callback to our irq_eoi at the end of handling the IRQ via generic_handle_irq. If I've understood everything correctly then I think this should do it
https://github.com/riscv/riscv-linux/commit/c2cf592609eb927e3eef60876ca78f73538af69a
Note that I haven't tested it yet, so I probably managed to screw something up...
The one thing I'm still confused about is: what is the difference between masking an IRQ and disabling an IRQ, and are our empty mask/unmask functions obsolete in the FastEOI flow?
Quoted 29 lines
Quoted 29 lines
drivers/irqchip/irq-riscv-plic.c new file +29
-0+ } + +chained_irq_exit (chip, desc); +} + +static int plic_init (struct device_node *node,struct device_node *parent) +{ +struct plic_data *data; +struct resource resource; +int i, ok =0 ; + + data =kzalloc (sizeof (*data),GFP_KERNEL ); +if (WARN_ON (!data)) +return -ENOMEM ; + + data->reg =of_iomap (node,0 ); +if (WARN_ON (!data->reg)) +return -EIO ; + +of_property_read_u32 (node,"riscv,ndev" , &data->ndev); +if (WARN_ON (!data->ndev)) +return -EINVAL ; + + data->handlers =of_irq_count (node); +if (WARN_ON (!data->handlers)) +return -EINVAL ; + + data->handler = +kcalloc (data->handlers,sizeof (*data->handler),GFP_KERNEL );
Quoted 8 lines
drivers/irqchip/irq-riscv-plic.c line 204
Quoted 6 lines
drivers/irqchip/irq-riscv-plic.c new file +6
-0+if (WARN_ON (!data->handler)) +return -ENOMEM ; + + data->domain =irq_domain_add_linear (node, data->ndev+1 , &plic_irqdomain_ops, data); +if (WARN_ON (!data->domain)) +return -ENOMEM ;Memory leak of
data->handlerand data,data->regis still mapped...
Sorry, I should have caught that earlier. I think this should fix it
https://github.com/riscv/riscv-linux/commit/ce8fdac83558c1e2cfd759b9a090a6f4657e2951
Quoted 45 lines
Quoted 45 lines
drivers/irqchip/irq-riscv-plic.c new file +45
-0+ +of_address_to_resource (node,0 , &resource); +snprintf (data->name,sizeof (data->name), +"riscv,plic0,%llx" , resource.start); + data->chip.name = data->name; + data->chip.irq_mask = plic_irq_mask; + data->chip.irq_unmask = plic_irq_unmask; + data->chip.irq_enable = plic_irq_enable; + data->chip.irq_disable = plic_irq_disable; + +for (i =0 ; i < data->handlers; ++i) { +struct plic_handler *handler = &data->handler[i]; +struct of_phandle_args parent; +int parent_irq, hwirq; + +if (of_irq_parse_one (node, i, &parent)) +continue ; +// skip context holes +if (parent.args[0 ] ==-1 ) +continue ; + +// skip any contexts that lead to inactive harts +if (of_device_is_compatible (parent.np,"riscv,cpu-intc" ) && + parent.np->parent && +riscv_of_processor_hart (parent.np->parent) <0 ) +continue ; + + parent_irq =irq_create_of_mapping (&parent); +if (!parent_irq) +continue ; + + handler->context =plic_hart_context (data, i); + handler->data = data; +// hwirq prio must be > this to trigger an interrupt +iowrite32 (0 , &handler->context->threshold); + +for (hwirq =1 ; hwirq <= data->ndev; ++hwirq) +plic_disable (data, i, hwirq); +irq_set_chained_handler_and_data (parent_irq, plic_chained_handle_irq, handler); + ++ok; + } + +printk (KERN_INFO "%s: mapped %d interrupts to %d/%d handlers\n" , + data->name, data->ndev, ok, data->handlers); +WARN_ON (!ok);
Quoted 8 lines
drivers/irqchip/irq-riscv-plic.c line 253
Quoted 5 lines
drivers/irqchip/irq-riscv-plic.c new file +4
-0+return 0 ; +} + +IRQCHIP_DECLARE (plic0,"riscv,plic0" , plic_init);In the future, please CC me (as well as Thomas Gleixner and Jason Cooper) on all the interrupt-controller related patches.
OK. We'd just been keeping the RISC-V port all as one big patch set in order to simplify our lives (for example, this v2 is the first time we had anything outside of arch/riscv). The big feedback has been that's the wrong way to do it, so I'm going to start splitting everything up to try to get things to the correct parties.
Once I get a chance to test all this I'll go and submit a patch set with our IRQ drivers.
Thanks for reviewing our patches!
Palmer Dabbelt
maintainerPATCH 10/17 irqchip: New RISC-V PLIC Driver
In reply to Palmer DabbeltThis patch adds a driver for the Platform Level Interrupt Controller (PLIC) specified as part of the RISC-V supervisor level ISA manual. The PLIC connocts global interrupt sources to the local interrupt controller on each hart. A PLIC is present on all RISC-V systems.
--- drivers/irqchip/Kconfig | 12 ++ drivers/irqchip/Makefile | 1 + drivers/irqchip/irq-riscv-plic.c | 253 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 266 insertions(+) create mode 100644 drivers/irqchip/irq-riscv-plic.c
drivers/irqchip/Kconfig +12 -0
@@ -301,3 +301,15 @@ config QCOM_IRQ_COMBINER help Say yes here to add support for the IRQ combiner devices embedded in Qualcomm Technologies chips. + +config RISCV_PLIC + bool "Platform-Level Interrupt Controller" + depends on RISCV + default y + help + This enables support for the PLIC chip found in standard RISC-V + systems. The PLIC is the top-most interrupt controller found in + the system, connected directly to the core complex. All other + interrupt sources (MSI, GPIO, etc) are subordinate to the PLIC. + + If you don't know what to do here, say Y.
drivers/irqchip/Makefile +1 -0
@@ -76,3 +76,4 @@ obj-$(CONFIG_EZNPS_GIC) += irq-eznps.o obj-$(CONFIG_ARCH_ASPEED) += irq-aspeed-vic.o obj-$(CONFIG_STM32_EXTI) += irq-stm32-exti.o obj-$(CONFIG_QCOM_IRQ_COMBINER) += qcom-irq-combiner.o +obj-$(CONFIG_RISCV_PLIC) += irq-riscv-plic.o
drivers/irqchip/irq-riscv-plic.c new file +253 -0
253 lines not on this page · raw message
Signature · 1 line
2.13.0
Palmer Dabbelt
maintainerPATCH 11/17 irqchip: RISC-V Local Interrupt Controller Driver
In reply to Palmer DabbeltThis patch adds a driver that manages the local interrupts on each RISC-V hart, as specifiec by the RISC-V supervisor level ISA manual. The local interrupt controller manages software interrupts, timer interrupts, and hardware interrupts (which are routed via the platform level interrupt controller). Per-hart local interrupt controllers are found on all RISC-V systems.
--- drivers/irqchip/Kconfig | 14 +++ drivers/irqchip/Makefile | 1 + drivers/irqchip/irq-riscv-intc.c | 239 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 254 insertions(+) create mode 100644 drivers/irqchip/irq-riscv-intc.c
drivers/irqchip/Kconfig +14 -0
@@ -313,3 +313,17 @@ config RISCV_PLIC interrupt sources (MSI, GPIO, etc) are subordinate to the PLIC. If you don't know what to do here, say Y. + +config RISCV_INTC + def_bool y if RISCV + #bool "RISC-V Interrupt Controller" + depends on RISCV + default y + help + This enables support for the local interrupt controller found in + standard RISC-V systems. The local interrupt controller handles + timer interrupts, software interrupts, and hardware interrupts. + Without a local interrupt controller the system will be unable to + handle any interrupts, including those passed via the PLIC. + + If you don't know what to do here, say Y.
drivers/irqchip/Makefile +1 -0
@@ -77,3 +77,4 @@ obj-$(CONFIG_ARCH_ASPEED) += irq-aspeed-vic.o obj-$(CONFIG_STM32_EXTI) += irq-stm32-exti.o obj-$(CONFIG_QCOM_IRQ_COMBINER) += qcom-irq-combiner.o obj-$(CONFIG_RISCV_PLIC) += irq-riscv-plic.o +obj-$(CONFIG_RISCV_INTC) += irq-riscv-intc.o
drivers/irqchip/irq-riscv-intc.c new file +239 -0
239 lines not on this page · raw message
Signature · 1 line
2.13.0
Re: [PATCH 11/17] irqchip: RISC-V Local Interrupt Controller Driver
CC irqchip folks
Quoted 293 lines · Palmer Dabbelt
This patch adds a driver that manages the local interrupts on each RISC-V hart, as specifiec by the RISC-V supervisor level ISA manual. The local interrupt controller manages software interrupts, timer interrupts, and hardware interrupts (which are routed via the platform level interrupt controller). Per-hart local interrupt controllers are found on all RISC-V systems.
Signed-off-by Palmer Dabbelt <[email protected]>--- drivers/irqchip/Kconfig | 14 +++ drivers/irqchip/Makefile | 1 + drivers/irqchip/irq-riscv-intc.c | 239 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 254 insertions(+) create mode 100644 drivers/irqchip/irq-riscv-intc.cdrivers/irqchip/Kconfig +14
-0@@ -313,3 +313,17 @@ config RISCV_PLIC interrupt sources (MSI, GPIO, etc) are subordinate to the PLIC. If you don't know what to do here, say Y. + +config RISCV_INTC + def_bool y if RISCV + #bool "RISC-V Interrupt Controller" + depends on RISCV + default y + help + This enables support for the local interrupt controller found in + standard RISC-V systems. The local interrupt controller handles + timer interrupts, software interrupts, and hardware interrupts. + Without a local interrupt controller the system will be unable to + handle any interrupts, including those passed via the PLIC. + + If you don't know what to do here, say Y.drivers/irqchip/Makefile +1
-0@@ -77,3 +77,4 @@ obj-$(CONFIG_ARCH_ASPEED) += irq-aspeed-vic.o obj-$(CONFIG_STM32_EXTI) += irq-stm32-exti.o obj-$(CONFIG_QCOM_IRQ_COMBINER) += qcom-irq-combiner.o obj-$(CONFIG_RISCV_PLIC) += irq-riscv-plic.o +obj-$(CONFIG_RISCV_INTC) += irq-riscv-intc.odrivers/irqchip/irq-riscv-intc.c new file +239
-1@@ -0,0 +1,239 @@ +/* +* Copyright (C) 2012 Regents of the University of California +* Copyright (C) 2017 SiFive +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation, version 2. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +*/ + +#include <linux/irq.h> +#include <linux/irqchip.h> +#include <linux/irqdomain.h> +#include <linux/interrupt.h> +#include <linux/ftrace.h> +#include <linux/of.h> +#include <linux/seq_file.h> + +#include <asm/ptrace.h> +#include <asm/sbi.h> +#include <asm/smp.h> + +struct riscv_irq_data { +struct irq_chip chip; +struct irq_domain *domain; +int hart; +char name[20 ]; +}; +DEFINE_PER_CPU(struct riscv_irq_data, riscv_irq_data); +DEFINE_PER_CPU (atomic_long_t, riscv_early_sie); + +static void riscv_software_interrupt (void ) +{ +#ifdef CONFIG_SMP +irqreturn_t ret; + + ret =handle_ipi (); +if (ret !=IRQ_NONE ) +return ; +#endif + +BUG (); +} + +asmlinkage void __irq_entry do_IRQ(unsigned int cause, struct pt_regs *regs) +{ +struct pt_regs *old_regs =set_irq_regs (regs); +struct irq_domain *domain; + +irq_enter (); + +/* There are three classes of interrupt: timer, software, and +* external devices. We dispatch between them here. External +* device interrupts use the generic IRQ mechanisms. +*/ +switch (cause) { +case INTERRUPT_CAUSE_TIMER : +riscv_timer_interrupt (); +break ; +case INTERRUPT_CAUSE_SOFTWARE : +riscv_software_interrupt (); +break ; +default : + domain =per_cpu (riscv_irq_data,smp_processor_id ()).domain; +generic_handle_irq (irq_find_mapping (domain, cause)); +break ; + } + +irq_exit (); +set_irq_regs (old_regs); +} + +static int riscv_irqdomain_map (struct irq_domain *d,unsigned int irq, +irq_hw_number_t hwirq) +{ +struct riscv_irq_data *data = d->host_data; + +irq_set_chip_and_handler (irq, &data->chip, handle_simple_irq); +irq_set_chip_data (irq, data); +irq_set_noprobe (irq); + +return 0 ; +} + +static const struct irq_domain_ops riscv_irqdomain_ops = { + .map = riscv_irqdomain_map, + .xlate = irq_domain_xlate_onecell, +}; + +static void riscv_irq_mask (struct irq_data *d) +{ +struct riscv_irq_data *data =irq_data_get_irq_chip_data (d); + +BUG_ON (smp_processor_id () != data->hart); +csr_clear (sie,1 << (long )d->hwirq); +} + +static void riscv_irq_unmask (struct irq_data *d) +{ +struct riscv_irq_data *data =irq_data_get_irq_chip_data (d); + +BUG_ON (smp_processor_id () != data->hart); +csr_set (sie,1 << (long )d->hwirq); +} + +static void riscv_irq_enable_helper (void *d) +{ +riscv_irq_unmask (d); +} + +static void riscv_irq_enable (struct irq_data *d) +{ +struct riscv_irq_data *data =irq_data_get_irq_chip_data (d); + +/* There are two phases to setting up an interrupt: first we set a bit +* in this bookkeeping structure, which is used by trap_init to +* initialize SIE for each hart as it comes up. +*/ +atomic_long_or ((1 << (long )d->hwirq), + &per_cpu (riscv_early_sie, data->hart)); + +/* The CPU is usually online, so here we just attempt to enable the +* interrupt by writing SIE directly. We need to write SIE on the +* correct hart, which might be another hart. +*/ +if (data->hart ==smp_processor_id ()) +riscv_irq_unmask (d); +else if (cpu_online (data->hart)) +smp_call_function_single (data->hart, + riscv_irq_enable_helper, + d, + true); +} + +static void riscv_irq_disable_helper (void *d) +{ +riscv_irq_mask (d); +} + +static void riscv_irq_disable (struct irq_data *d) +{ +struct riscv_irq_data *data =irq_data_get_irq_chip_data (d); + +/* This is the mirror of riscv_irq_enable. */ +atomic_long_and (~(1 << (long )d->hwirq), + &per_cpu (riscv_early_sie, data->hart)); +if (data->hart ==smp_processor_id ()) +riscv_irq_mask (d); +else if (cpu_online (data->hart)) +smp_call_function_single (data->hart, + riscv_irq_disable_helper, + d, + true); +} + +static void riscv_irq_mask_noop (struct irq_data *d) { } + +static void riscv_irq_unmask_noop (struct irq_data *d) { } + +static void riscv_irq_enable_noop (struct irq_data *d) +{ +struct device_node *data =irq_data_get_irq_chip_data (d); +u32 hart; + +if (!of_property_read_u32 (data,"reg" , &hart)) +printk ( +KERN_WARNING "enabled interrupt %d for missing hart %d (this interrupt has no handler)\n" , + (int )d->hwirq, hart); +} + +static struct irq_chip riscv_noop_chip = { + .name ="riscv,cpu-intc,noop" , + .irq_mask = riscv_irq_mask_noop, + .irq_unmask = riscv_irq_unmask_noop, + .irq_enable = riscv_irq_enable_noop, +}; + +static int riscv_irqdomain_map_noop (struct irq_domain *d,unsigned int irq, +irq_hw_number_t hwirq) +{ +struct device_node *data = d->host_data; + +irq_set_chip_and_handler (irq, &riscv_noop_chip, handle_simple_irq); +irq_set_chip_data (irq, data); +return 0 ; +} + +static const struct irq_domain_ops riscv_irqdomain_ops_noop = { + .map = riscv_irqdomain_map_noop, + .xlate = irq_domain_xlate_onecell, +}; + +static int riscv_intc_init (struct device_node *node,struct device_node *parent) +{ +int hart; +struct riscv_irq_data *data; + +if (parent) +return 0 ; + + hart =riscv_of_processor_hart (node->parent); +if (hart <0 ) { +/* If a hart is disabled, create a no-op irq domain. Devices +* may still have interrupts connected to those harts. This is +* not wrong... unless they actually load a driver that needs +* it! +*/ +irq_domain_add_linear ( + node, +8 *sizeof (uintptr_t ), + &riscv_irqdomain_ops_noop, + node->parent); +return 0 ; + } + + data = &per_cpu (riscv_irq_data, hart); +snprintf (data->name,sizeof (data->name),"riscv,cpu_intc,%d" , hart); + data->hart = hart; + data->chip.name = data->name; + data->chip.irq_mask = riscv_irq_mask; + data->chip.irq_unmask = riscv_irq_unmask; + data->chip.irq_enable = riscv_irq_enable; + data->chip.irq_disable = riscv_irq_disable; + data->domain =irq_domain_add_linear ( + node, +8 *sizeof (uintptr_t ), + &riscv_irqdomain_ops, + data); +WARN_ON (!data->domain); +printk (KERN_INFO "%s: %d local interrupts mapped\n" , + data->name,8 *(int )sizeof (uintptr_t )); +return 0 ; +} + +IRQCHIP_DECLARE (riscv,"riscv,cpu-intc" , riscv_intc_init); --2.13.0
Palmer Dabbelt
maintainerPATCH 12/17 tty: New RISC-V SBI Console Driver
In reply to Palmer DabbeltThis patch adds a new driver for the console availiable via the RISC-V SBI. This console is specified to be used for early boot messages, and is designed to be a very simple (albiet somewhat slow) console that is always availiable. All RISC-V systems have an SBI console.
The SBI console is made availiable for early printk messages and is also availiable as a regular console.
--- drivers/tty/hvc/Kconfig | 11 +++++ drivers/tty/hvc/Makefile | 1 + drivers/tty/hvc/hvc_sbi.c | 102 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 114 insertions(+) create mode 100644 drivers/tty/hvc/hvc_sbi.c
drivers/tty/hvc/Kconfig +11 -0
@@ -114,4 +114,15 @@ config HVCS which will also be compiled when this driver is built as a module. +config HVC_SBI + bool "SBI console support" + depends on RISCV + select HVC_DRIVER + default y + help + This enables support for console output via RISC-V SBI calls, which + is normally used only during boot to output printk. + + If you don't know what do to here, say Y. + endif # TTY
drivers/tty/hvc/Makefile +1 -0
@@ -11,3 +11,4 @@ obj-$(CONFIG_HVC_IUCV) += hvc_iucv.o obj-$(CONFIG_HVC_UDBG) += hvc_udbg.o obj-$(CONFIG_HVC_BFIN_JTAG) += hvc_bfin_jtag.o obj-$(CONFIG_HVCS) += hvcs.o +obj-$(CONFIG_HVC_SBI) += hvc_sbi.o
drivers/tty/hvc/hvc_sbi.c new file +102 -0
102 lines not on this page · raw message
Signature · 1 line
2.13.0
Re: [PATCH 12/17] tty: New RISC-V SBI Console Driver
CC (hypervisor) console folks
Quoted 155 lines · Palmer Dabbelt
This patch adds a new driver for the console availiable via the RISC-V SBI. This console is specified to be used for early boot messages, and is designed to be a very simple (albiet somewhat slow) console that is always availiable. All RISC-V systems have an SBI console.
The SBI console is made availiable for early printk messages and is also availiable as a regular console.
Signed-off-by Palmer Dabbelt <[email protected]>--- drivers/tty/hvc/Kconfig | 11 +++++ drivers/tty/hvc/Makefile | 1 + drivers/tty/hvc/hvc_sbi.c | 102 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 114 insertions(+) create mode 100644 drivers/tty/hvc/hvc_sbi.cdrivers/tty/hvc/Kconfig +11
-0@@ -114,4 +114,15 @@ config HVCS which will also be compiled when this driver is built as a module. +config HVC_SBI + bool "SBI console support" + depends on RISCV + select HVC_DRIVER + default y + help + This enables support for console output via RISC-V SBI calls, which + is normally used only during boot to output printk. + + If you don't know what do to here, say Y. + endif # TTYdrivers/tty/hvc/Makefile +1
-0@@ -11,3 +11,4 @@ obj-$(CONFIG_HVC_IUCV) += hvc_iucv.o obj-$(CONFIG_HVC_UDBG) += hvc_udbg.o obj-$(CONFIG_HVC_BFIN_JTAG) += hvc_bfin_jtag.o obj-$(CONFIG_HVCS) += hvcs.o +obj-$(CONFIG_HVC_SBI) += hvc_sbi.odrivers/tty/hvc/hvc_sbi.c new file +102
-1@@ -0,0 +1,102 @@ +/* +* RISC-V SBI interface to hvc_console.c +* based on drivers-tty/hvc/hvc_udbg.c +* +* Copyright (C) 2008 David Gibson, IBM Corporation +* Copyright (C) 2012 Regents of the University of California +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation, version 2. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +*/ + +#include <linux/console.h> +#include <linux/delay.h> +#include <linux/err.h> +#include <linux/init.h> +#include <linux/moduleparam.h> +#include <linux/types.h> +#include <linux/irq.h> + +#include <asm/sbi.h> + +#include "hvc_console.h" + +static int hvc_sbi_tty_put (uint32_t vtermno,const char *buf,int count) +{ +int i; + +for (i =0 ; i < count; i++) +sbi_console_putchar (buf[i]); + +return i; +} + +static int hvc_sbi_tty_get (uint32_t vtermno,char *buf,int count) +{ +int i, c; + +for (i =0 ; i < count; i++) { +if ((c =sbi_console_getchar ()) <0 ) +break ; + buf[i] = c; + } + +return i; +} + +static const struct hv_ops hvc_sbi_ops = { + .get_chars = hvc_sbi_tty_get, + .put_chars = hvc_sbi_tty_put, +}; + +static int __init hvc_sbi_init (void ) +{ +return PTR_ERR_OR_ZERO (hvc_alloc (0 ,0 , &hvc_sbi_ops,16 )); +} +device_initcall (hvc_sbi_init); + +static int __init hvc_sbi_console_init (void ) +{ +hvc_instantiate (0 ,0 , &hvc_sbi_ops); +add_preferred_console ("hvc" ,0 ,NULL ); + +return 0 ; +} +console_initcall (hvc_sbi_console_init); + +#ifdef CONFIG_EARLY_PRINTK +static void sbi_console_write (struct console *co,const char *buf, +unsigned int n) +{ +int i; + +for (i =0 ; i < n; ++i) { +if (buf[i] =='\n' ) +sbi_console_putchar ('\r' ); +sbi_console_putchar (buf[i]); + } +} + +static struct console early_console_dev__initdata = { + .name ="early" , + .write = sbi_console_write, + .flags =CON_PRINTBUFFER |CON_BOOT , + .index =-1 +}; + +static int __init setup_early_printk (char *str) +{ +if (early_console ==NULL ) { + early_console = &early_console_dev; +register_console (early_console); + } +return 0 ; +} +early_param ("earlyprintk" , setup_early_printk); +#endif --2.13.0
Arnd Bergmann
maintainerRe: [PATCH 12/17] tty: New RISC-V SBI Console Driver
Quoted 27 lines · Geert Uytterhoeven
CC (hypervisor) console folks
Quoted 24 lines · Palmer Dabbelt
This patch adds a new driver for the console availiable via the RISC-V SBI. This console is specified to be used for early boot messages, and is designed to be a very simple (albiet somewhat slow) console that is always availiable. All RISC-V systems have an SBI console.
The SBI console is made availiable for early printk messages and is also availiable as a regular console.
Signed-off-by Palmer Dabbelt <[email protected]>--- drivers/tty/hvc/Kconfig | 11 +++++ drivers/tty/hvc/Makefile | 1 + drivers/tty/hvc/hvc_sbi.c | 102 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 114 insertions(+) create mode 100644 drivers/tty/hvc/hvc_sbi.cdrivers/tty/hvc/Kconfig +0
-0@@ -114,4 +114,15 @@ config HVCS which will also be compiled when this driver is built as a module.
Quoted 12 lines
drivers/tty/hvc/Kconfig config HVCS · line 128
Quoted 12 lines
drivers/tty/hvc/Kconfig +11
-0+config HVC_SBI + bool "SBI console support" + depends on RISCV + select HVC_DRIVER + default y + help + This enables support for console output via RISC-V SBI calls, which + is normally used only during boot to output printk. + + If you don't know what do to here, say Y. + endif # TTY
Please move this a little higher along with the other HVC_DRIVER implementations.
Quoted 5 lines
Quoted 5 lines
+ * RISC-V SBI interface to
hvc_console.c
+ * based ondrivers-tty/hvc/hvc_udbg.c
+ *
+ * Copyright (C) 2008 David Gibson, IBM Corporation
+ * Copyright (C) 2012 Regents of the University of California
2017?
Arnd
Palmer Dabbelt
maintainerRe: [PATCH 12/17] tty: New RISC-V SBI Console Driver
Quoted 28 lines · Arnd Bergmann
Quoted 27 lines · Geert Uytterhoeven
CC (hypervisor) console folks
Quoted 24 lines · Palmer Dabbelt
This patch adds a new driver for the console availiable via the RISC-V SBI. This console is specified to be used for early boot messages, and is designed to be a very simple (albiet somewhat slow) console that is always availiable. All RISC-V systems have an SBI console.
The SBI console is made availiable for early printk messages and is also availiable as a regular console.
Signed-off-by Palmer Dabbelt <[email protected]>--- drivers/tty/hvc/Kconfig | 11 +++++ drivers/tty/hvc/Makefile | 1 + drivers/tty/hvc/hvc_sbi.c | 102 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 114 insertions(+) create mode 100644 drivers/tty/hvc/hvc_sbi.cdrivers/tty/hvc/Kconfig +0
-0@@ -114,4 +114,15 @@ config HVCS which will also be compiled when this driver is built as a module.
Quoted 15 lines
Quoted 4 lines
Quoted 4 lines
drivers/tty/hvc/Kconfig +4
-0+config HVC_SBI + bool "SBI console support" + depends on RISCV + select HVC_DRIVERQuoted 8 lines
drivers/tty/hvc/Kconfig config HVCS · line 128
Quoted 8 lines
drivers/tty/hvc/Kconfig +7
-0+ default y + help + This enables support for console output via RISC-V SBI calls, which + is normally used only during boot to output printk. + + If you don't know what do to here, say Y. + endif # TTYPlease move this a little higher along with the other
HVC_DRIVERimplementations.
OK: https://github.com/riscv/riscv-linux/commit/1c769cad7931b7b08644d2d4a7b6985777a8e0be
Quoted 7 lines
Quoted 5 lines
Quoted 5 lines
+ * RISC-V SBI interface to
hvc_console.c
+ * based ondrivers-tty/hvc/hvc_udbg.c
+ *
+ * Copyright (C) 2008 David Gibson, IBM Corporation
+ * Copyright (C) 2012 Regents of the University of California2017?
https://github.com/riscv/riscv-linux/commit/dafa678d26886076a8a9cccc2486f1bbbfa44aa8
Palmer Dabbelt
maintainerPATCH 12/17 tty: New RISC-V SBI Console Driver
In reply to Palmer DabbeltThis patch adds a new driver for the console availiable via the RISC-V SBI. This console is specified to be used for early boot messages, and is designed to be a very simple (albiet somewhat slow) console that is always availiable. All RISC-V systems have an SBI console.
The SBI console is made availiable for early printk messages and is also availiable as a regular console.
--- drivers/tty/hvc/Kconfig | 11 +++++ drivers/tty/hvc/Makefile | 1 + drivers/tty/hvc/hvc_sbi.c | 102 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 114 insertions(+) create mode 100644 drivers/tty/hvc/hvc_sbi.c
drivers/tty/hvc/Kconfig +11 -0
@@ -114,4 +114,15 @@ config HVCS which will also be compiled when this driver is built as a module. +config HVC_SBI + bool "SBI console support" + depends on RISCV + select HVC_DRIVER + default y + help + This enables support for console output via RISC-V SBI calls, which + is normally used only during boot to output printk. + + If you don't know what do to here, say Y. + endif # TTY
drivers/tty/hvc/Makefile +1 -0
@@ -11,3 +11,4 @@ obj-$(CONFIG_HVC_IUCV) += hvc_iucv.o obj-$(CONFIG_HVC_UDBG) += hvc_udbg.o obj-$(CONFIG_HVC_BFIN_JTAG) += hvc_bfin_jtag.o obj-$(CONFIG_HVCS) += hvcs.o +obj-$(CONFIG_HVC_SBI) += hvc_sbi.o
drivers/tty/hvc/hvc_sbi.c new file +102 -0
102 lines not on this page · raw message
Signature · 1 line
2.13.0
Palmer Dabbelt
maintainerPATCH 13/17 RISC-V: Add include subdirectory
In reply to Palmer DabbeltThis patch adds the include files for the RISC-V port. These are mostly based on the score port, but there are a lot of arm64-based files as well.
--- arch/riscv/include/asm/Kbuild | 61 +++++ arch/riscv/include/asm/asm-offsets.h | 1 + arch/riscv/include/asm/asm.h | 76 ++++++ arch/riscv/include/asm/atomic.h | 349 ++++++++++++++++++++++++ arch/riscv/include/asm/atomic64.h | 355 ++++++++++++++++++++++++ arch/riscv/include/asm/barrier.h | 41 +++ arch/riscv/include/asm/bitops.h | 228 ++++++++++++++++ arch/riscv/include/asm/bug.h | 88 ++++++ arch/riscv/include/asm/cache.h | 22 ++ arch/riscv/include/asm/cacheflush.h | 39 +++ arch/riscv/include/asm/cmpxchg.h | 124 +++++++++ arch/riscv/include/asm/compat.h | 31 +++ arch/riscv/include/asm/csr.h | 125 +++++++++ arch/riscv/include/asm/current.h | 42 +++ arch/riscv/include/asm/delay.h | 28 ++ arch/riscv/include/asm/device.h | 27 ++ arch/riscv/include/asm/dma-mapping.h | 41 +++ arch/riscv/include/asm/elf.h | 85 ++++++ arch/riscv/include/asm/io.h | 152 +++++++++++ arch/riscv/include/asm/irq.h | 31 +++ arch/riscv/include/asm/irqflags.h | 63 +++++ arch/riscv/include/asm/kprobes.h | 22 ++ arch/riscv/include/asm/linkage.h | 20 ++ arch/riscv/include/asm/mmu.h | 26 ++ arch/riscv/include/asm/mmu_context.h | 69 +++++ arch/riscv/include/asm/page.h | 138 ++++++++++ arch/riscv/include/asm/pci.h | 50 ++++ arch/riscv/include/asm/pgalloc.h | 124 +++++++++ arch/riscv/include/asm/pgtable-32.h | 25 ++ arch/riscv/include/asm/pgtable-64.h | 84 ++++++ arch/riscv/include/asm/pgtable-bits.h | 48 ++++ arch/riscv/include/asm/pgtable.h | 427 +++++++++++++++++++++++++++++ arch/riscv/include/asm/processor.h | 102 +++++++ arch/riscv/include/asm/ptrace.h | 116 ++++++++ arch/riscv/include/asm/sbi.h | 100 +++++++ arch/riscv/include/asm/smp.h | 41 +++ arch/riscv/include/asm/spinlock.h | 155 +++++++++++ arch/riscv/include/asm/spinlock_types.h | 33 +++ arch/riscv/include/asm/string.h | 30 ++ arch/riscv/include/asm/switch_to.h | 69 +++++ arch/riscv/include/asm/syscall.h | 90 ++++++ arch/riscv/include/asm/syscalls.h | 25 ++ arch/riscv/include/asm/thread_info.h | 96 +++++++ arch/riscv/include/asm/timex.h | 43 +++ arch/riscv/include/asm/tlb.h | 24 ++ arch/riscv/include/asm/tlbflush.h | 64 +++++ arch/riscv/include/asm/uaccess.h | 440 ++++++++++++++++++++++++++++++ arch/riscv/include/asm/unistd.h | 16 ++ arch/riscv/include/asm/vdso.h | 32 +++ arch/riscv/include/asm/word-at-a-time.h | 55 ++++ arch/riscv/include/uapi/asm/Kbuild | 2 + arch/riscv/include/uapi/asm/auxvec.h | 24 ++ arch/riscv/include/uapi/asm/bitsperlong.h | 25 ++ arch/riscv/include/uapi/asm/byteorder.h | 23 ++ arch/riscv/include/uapi/asm/elf.h | 83 ++++++ arch/riscv/include/uapi/asm/ptrace.h | 68 +++++ arch/riscv/include/uapi/asm/sigcontext.h | 29 ++ arch/riscv/include/uapi/asm/siginfo.h | 24 ++ arch/riscv/include/uapi/asm/unistd.h | 22 ++ 59 files changed, 4873 insertions(+) create mode 100644 arch/riscv/include/asm/Kbuild create mode 100644 arch/riscv/include/asm/asm-offsets.h create mode 100644 arch/riscv/include/asm/asm.h create mode 100644 arch/riscv/include/asm/atomic.h create mode 100644 arch/riscv/include/asm/atomic64.h create mode 100644 arch/riscv/include/asm/barrier.h create mode 100644 arch/riscv/include/asm/bitops.h create mode 100644 arch/riscv/include/asm/bug.h create mode 100644 arch/riscv/include/asm/cache.h create mode 100644 arch/riscv/include/asm/cacheflush.h create mode 100644 arch/riscv/include/asm/cmpxchg.h create mode 100644 arch/riscv/include/asm/compat.h create mode 100644 arch/riscv/include/asm/csr.h create mode 100644 arch/riscv/include/asm/current.h create mode 100644 arch/riscv/include/asm/delay.h create mode 100644 arch/riscv/include/asm/device.h create mode 100644 arch/riscv/include/asm/dma-mapping.h create mode 100644 arch/riscv/include/asm/elf.h create mode 100644 arch/riscv/include/asm/io.h create mode 100644 arch/riscv/include/asm/irq.h create mode 100644 arch/riscv/include/asm/irqflags.h create mode 100644 arch/riscv/include/asm/kprobes.h create mode 100644 arch/riscv/include/asm/linkage.h create mode 100644 arch/riscv/include/asm/mmu.h create mode 100644 arch/riscv/include/asm/mmu_context.h create mode 100644 arch/riscv/include/asm/page.h create mode 100644 arch/riscv/include/asm/pci.h create mode 100644 arch/riscv/include/asm/pgalloc.h create mode 100644 arch/riscv/include/asm/pgtable-32.h create mode 100644 arch/riscv/include/asm/pgtable-64.h create mode 100644 arch/riscv/include/asm/pgtable-bits.h create mode 100644 arch/riscv/include/asm/pgtable.h create mode 100644 arch/riscv/include/asm/processor.h create mode 100644 arch/riscv/include/asm/ptrace.h create mode 100644 arch/riscv/include/asm/sbi.h create mode 100644 arch/riscv/include/asm/smp.h create mode 100644 arch/riscv/include/asm/spinlock.h create mode 100644 arch/riscv/include/asm/spinlock_types.h create mode 100644 arch/riscv/include/asm/string.h create mode 100644 arch/riscv/include/asm/switch_to.h create mode 100644 arch/riscv/include/asm/syscall.h create mode 100644 arch/riscv/include/asm/syscalls.h create mode 100644 arch/riscv/include/asm/thread_info.h create mode 100644 arch/riscv/include/asm/timex.h create mode 100644 arch/riscv/include/asm/tlb.h create mode 100644 arch/riscv/include/asm/tlbflush.h create mode 100644 arch/riscv/include/asm/uaccess.h create mode 100644 arch/riscv/include/asm/unistd.h create mode 100644 arch/riscv/include/asm/vdso.h create mode 100644 arch/riscv/include/asm/word-at-a-time.h create mode 100644 arch/riscv/include/uapi/asm/Kbuild create mode 100644 arch/riscv/include/uapi/asm/auxvec.h create mode 100644 arch/riscv/include/uapi/asm/bitsperlong.h create mode 100644 arch/riscv/include/uapi/asm/byteorder.h create mode 100644 arch/riscv/include/uapi/asm/elf.h create mode 100644 arch/riscv/include/uapi/asm/ptrace.h create mode 100644 arch/riscv/include/uapi/asm/sigcontext.h create mode 100644 arch/riscv/include/uapi/asm/siginfo.h create mode 100644 arch/riscv/include/uapi/asm/unistd.h
arch/riscv/include/asm/Kbuild new file +61 -0
@@ -0,0 +1,61 @@ +generic-y += bugs.h +generic-y += cacheflush.h +generic-y += checksum.h +generic-y += clkdev.h +generic-y += cputime.h +generic-y += div64.h +generic-y += dma.h +generic-y += dma-contiguous.h +generic-y += emergency-restart.h +generic-y += errno.h +generic-y += exec.h +generic-y += fb.h +generic-y += fcntl.h +generic-y += ftrace.h +generic-y += futex.h +generic-y += hardirq.h +generic-y += hash.h +generic-y += hw_irq.h +generic-y += ioctl.h +generic-y += ioctls.h +generic-y += ipcbuf.h +generic-y += irq_regs.h +generic-y += irq_work.h +generic-y += kdebug.h +generic-y += kmap_types.h +generic-y += kvm_para.h +generic-y += local.h +generic-y += mm-arch-hooks.h +generic-y += mman.h +generic-y += module.h +generic-y += msgbuf.h +generic-y += mutex.h +generic-y += param.h +generic-y += percpu.h +generic-y += poll.h +generic-y += posix_types.h +generic-y += preempt.h +generic-y += resource.h +generic-y += scatterlist.h +generic-y += sections.h +generic-y += sembuf.h +generic-y += setup.h +generic-y += shmbuf.h +generic-y += shmparam.h +generic-y += signal.h +generic-y += socket.h +generic-y += sockios.h +generic-y += stat.h +generic-y += statfs.h +generic-y += swab.h +generic-y += termbits.h +generic-y += termios.h +generic-y += topology.h +generic-y += trace_clock.h +generic-y += types.h +generic-y += ucontext.h +generic-y += unaligned.h +generic-y += user.h +generic-y += vga.h +generic-y += vmlinux.lds.h +generic-y += xor.h
arch/riscv/include/asm/asm-offsets.h new file +1 -0
@@ -0,0 +1 @@ +#include <generated/asm-offsets.h>
arch/riscv/include/asm/asm.h new file +76 -0
76 lines not on this page · raw message
arch/riscv/include/asm/atomic.h new file +349 -0
349 lines not on this page · raw message
arch/riscv/include/asm/atomic64.h new file +355 -0
355 lines not on this page · raw message
arch/riscv/include/asm/barrier.h new file +41 -0
41 lines not on this page · raw message
arch/riscv/include/asm/bitops.h new file +228 -0
228 lines not on this page · raw message
arch/riscv/include/asm/bug.h new file +88 -0
88 lines not on this page · raw message
arch/riscv/include/asm/cache.h new file +22 -0
@@ -0,0 +1,22 @@ +/* +* Copyright (C) 2017 Chen Liqin <[email protected]> +* Copyright (C) 2012 Regents of the University of California +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation, version 2. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +*/ + +#ifndef _ASM_RISCV_CACHE_H +#define _ASM_RISCV_CACHE_H + +#define L1_CACHE_SHIFT 6 + +#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT) + +#endif /* _ASM_RISCV_CACHE_H */
arch/riscv/include/asm/cacheflush.h new file +39 -0
@@ -0,0 +1,39 @@ +/* +* Copyright (C) 2015 Regents of the University of California +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation, version 2. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +*/ + +#ifndef _ASM_RISCV_CACHEFLUSH_H +#define _ASM_RISCV_CACHEFLUSH_H + +#include <asm-generic/cacheflush.h> + +#undef flush_icache_range +#undef flush_icache_user_range + +static inline void local_flush_icache_all (void ) +{ + asmvolatile ("fence.i" :::"memory" ); +} + +#ifndef CONFIG_SMP + +#define flush_icache_range (start, end) local_flush_icache_all() +#define flush_icache_user_range (vma, pg, addr, len) local_flush_icache_all() + +#else /* CONFIG_SMP */ + +#define flush_icache_range (start, end) sbi_remote_fence_i(0) +#define flush_icache_user_range (vma, pg, addr, len) sbi_remote_fence_i(0) + +#endif /* CONFIG_SMP */ + +#endif /* _ASM_RISCV_CACHEFLUSH_H */
arch/riscv/include/asm/cmpxchg.h new file +124 -0
124 lines not on this page · raw message
arch/riscv/include/asm/compat.h new file +31 -0
@@ -0,0 +1,31 @@ +/* +* Copyright (C) 2012 ARM Ltd. +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ +#ifndef __ASM_COMPAT_H +#define __ASM_COMPAT_H +#ifdef __KERNEL__ +#ifdef CONFIG_COMPAT + +#if defined(CONFIG_64BIT ) +#define COMPAT_UTS_MACHINE "riscv64\0\0" +#elif defined(CONFIG_32BIT ) +#define COMPAT_UTS_MACHINE "riscv32\0\0" +#else +#error "Unknown RISC-V base ISA" +#endif + +#endif /*CONFIG_COMPAT*/ +#endif /*__KERNEL__*/ +#endif /*__ASM_COMPAT_H*/
arch/riscv/include/asm/csr.h new file +125 -0
125 lines not on this page · raw message
arch/riscv/include/asm/current.h new file +42 -0
42 lines not on this page · raw message
arch/riscv/include/asm/delay.h new file +28 -0
@@ -0,0 +1,28 @@ +/* +* Copyright (C) 2009 Chen Liqin <[email protected]> +* Copyright (C) 2016 Regents of the University of California +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation, version 2. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +*/ + +#ifndef _ASM_RISCV_DELAY_H +#define _ASM_RISCV_DELAY_H + +extern unsigned long riscv_timebase; + +#define udelay udelay +extern void udelay (unsigned long usecs); + +#define ndelay ndelay +extern void ndelay (unsigned long nsecs); + +extern void __delay (unsigned long cycles); + +#endif /* _ASM_RISCV_DELAY_H */
arch/riscv/include/asm/device.h new file +27 -0
@@ -0,0 +1,27 @@ +/* +* Copyright (C) 2016 SiFive +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation, version 2. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +*/ + + +#ifndef _ASM_RISCV_DEVICE_H +#define _ASM_RISCV_DEVICE_H + +#include <linux/sysfs.h> + +struct dev_archdata { +struct dma_map_ops *dma_ops; +}; + +struct pdev_archdata { +}; + +#endif /* _ASM_RISCV_DEVICE_H */
arch/riscv/include/asm/dma-mapping.h new file +41 -0
41 lines not on this page · raw message
arch/riscv/include/asm/elf.h new file +85 -0
85 lines not on this page · raw message
arch/riscv/include/asm/io.h new file +152 -0
152 lines not on this page · raw message
arch/riscv/include/asm/irq.h new file +31 -0
@@ -0,0 +1,31 @@ +/* +* Copyright (C) 2012 Regents of the University of California +* Copyright (C) 2017 SiFive +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation, version 2. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +*/ + +#ifndef _ASM_RISCV_IRQ_H +#define _ASM_RISCV_IRQ_H + +#define NR_IRQS 0 + +#define INTERRUPT_CAUSE_SOFTWARE 1 +#define INTERRUPT_CAUSE_TIMER 5 +#define INTERRUPT_CAUSE_EXTERNAL 9 + +void riscv_timer_interrupt (void ); + +#include <asm-generic/irq.h> + +/* The value of csr sie before init_traps runs (core is up) */ +DECLARE_PER_CPU (atomic_long_t, riscv_early_sie); + +#endif /* _ASM_RISCV_IRQ_H */
arch/riscv/include/asm/irqflags.h new file +63 -0
63 lines not on this page · raw message
arch/riscv/include/asm/kprobes.h new file +22 -0
@@ -0,0 +1,22 @@ +/* +* Copyright (C) 2017 SiFive +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation, version 2. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +*/ + + +#ifndef ASM_RISCV_KPROBES_H +#define ASM_RISCV_KPROBES_H + +#ifdef CONFIG_KPROBES +#error "RISC-V doesn't skpport CONFIG_KPROBES" +#endif + +#endif
arch/riscv/include/asm/linkage.h new file +20 -0
@@ -0,0 +1,20 @@ +/* +* Copyright (C) 2015 Regents of the University of California +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation, version 2. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +*/ + +#ifndef _ASM_RISCV_LINKAGE_H +#define _ASM_RISCV_LINKAGE_H + +#define __ALIGN .balign 4 +#define __ALIGN_STR ".balign 4" + +#endif /* _ASM_RISCV_LINKAGE_H */
arch/riscv/include/asm/mmu.h new file +26 -0
@@ -0,0 +1,26 @@ +/* +* Copyright (C) 2012 Regents of the University of California +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation, version 2. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +*/ + + +#ifndef _ASM_RISCV_MMU_H +#define _ASM_RISCV_MMU_H + +#ifndef __ASSEMBLY__ + +typedef struct { +void *vdso; +}mm_context_t ; + +#endif /* __ASSEMBLY__ */ + +#endif /* _ASM_RISCV_MMU_H */
arch/riscv/include/asm/mmu_context.h new file +69 -0
69 lines not on this page · raw message
arch/riscv/include/asm/page.h new file +138 -0
138 lines not on this page · raw message
arch/riscv/include/asm/pci.h new file +50 -0
50 lines not on this page · raw message
arch/riscv/include/asm/pgalloc.h new file +124 -0
124 lines not on this page · raw message
arch/riscv/include/asm/pgtable-32.h new file +25 -0
@@ -0,0 +1,25 @@ +/* +* Copyright (C) 2012 Regents of the University of California +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation, version 2. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +*/ + +#ifndef _ASM_RISCV_PGTABLE_32_H +#define _ASM_RISCV_PGTABLE_32_H + +#include <asm-generic/pgtable-nopmd.h> +#include <linux/const.h> + +/* Size of region mapped by a page global directory */ +#define PGDIR_SHIFT 22 +#define PGDIR_SIZE (_AC(1, UL) << PGDIR_SHIFT) +#define PGDIR_MASK (~(PGDIR_SIZE - 1)) + +#endif /* _ASM_RISCV_PGTABLE_32_H */
arch/riscv/include/asm/pgtable-64.h new file +84 -0
84 lines not on this page · raw message
arch/riscv/include/asm/pgtable-bits.h new file +48 -0
48 lines not on this page · raw message
arch/riscv/include/asm/pgtable.h new file +427 -0
385 lines not on this page · raw message
arch/riscv/include/asm/processor.h new file +102 -0
102 lines not on this page · raw message
arch/riscv/include/asm/ptrace.h new file +116 -0
116 lines not on this page · raw message
arch/riscv/include/asm/sbi.h new file +100 -0
100 lines not on this page · raw message
arch/riscv/include/asm/smp.h new file +41 -0
41 lines not on this page · raw message
arch/riscv/include/asm/spinlock.h new file +155 -0
155 lines not on this page · raw message
arch/riscv/include/asm/spinlock_types.h new file +33 -0
Lines of this file are not shown. View the raw message.
arch/riscv/include/asm/string.h new file +30 -0
Lines of this file are not shown. View the raw message.
arch/riscv/include/asm/switch_to.h new file +69 -0
69 lines not on this page · raw message
arch/riscv/include/asm/syscall.h new file +90 -0
90 lines not on this page · raw message
arch/riscv/include/asm/syscalls.h new file +25 -0
Lines of this file are not shown. View the raw message.
arch/riscv/include/asm/thread_info.h new file +96 -0
96 lines not on this page · raw message
arch/riscv/include/asm/timex.h new file +43 -0
43 lines not on this page · raw message
arch/riscv/include/asm/tlbflush.h new file +64 -0
64 lines not on this page · raw message
arch/riscv/include/asm/uaccess.h new file +440 -0
440 lines not on this page · raw message
arch/riscv/include/asm/unistd.h new file +16 -0
Lines of this file are not shown. View the raw message.
arch/riscv/include/asm/vdso.h new file +32 -0
Lines of this file are not shown. View the raw message.
arch/riscv/include/asm/word-at-a-time.h new file +55 -0
55 lines not on this page · raw message
arch/riscv/include/uapi/asm/Kbuild new file +2 -0
Lines of this file are not shown. View the raw message.
arch/riscv/include/uapi/asm/auxvec.h new file +24 -0
Lines of this file are not shown. View the raw message.
arch/riscv/include/uapi/asm/bitsperlong.h new file +25 -0
Lines of this file are not shown. View the raw message.
arch/riscv/include/uapi/asm/byteorder.h new file +23 -0
Lines of this file are not shown. View the raw message.
arch/riscv/include/uapi/asm/elf.h new file +83 -0
83 lines not on this page · raw message
arch/riscv/include/uapi/asm/ptrace.h new file +68 -0
68 lines not on this page · raw message
arch/riscv/include/uapi/asm/sigcontext.h new file +29 -0
Lines of this file are not shown. View the raw message.
arch/riscv/include/uapi/asm/siginfo.h new file +24 -0
Lines of this file are not shown. View the raw message.
arch/riscv/include/uapi/asm/unistd.h new file +22 -0
Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.13.0
Part of the diff is not shown here. View the raw message.
Arnd Bergmann
maintainerRe: [PATCH 13/17] RISC-V: Add include subdirectory
Quoted 5 lines · Palmer Dabbelt
This patch adds the include files for the RISC-V port. These are mostly based on the score port, but there are a lot of arm64-based files as well.
Signed-off-by Palmer Dabbelt <[email protected]>
It might be better to split this up into several parts, as the patch is longer than
most people are willing to review at once.
The uapi should definitely be a separate patch, as it includes the parts that cannot be changed any more later. memory management (pgtable, mmu, uaccess) would be another part to split out, and possibly all the atomics in one separate patch (along with spinlocks and bitops).
Quoted 37 lines
arch/riscv/include/asm/io.h new file +37
-0+ +/* IO barriers. These only fence on the IO bits because they're only required +* to order device access. We're defining mmiowb because our AMO instructions +* (which are used to implement locks) don't specify ordering. From Chapter 7 +* of v2.2 of the user ISA: +* "The bits order accesses to one of the two address domains, memory or I/O, +* depending on which address domain the atomic instruction is accessing. No +* ordering constraint is implied to accesses to the other domain, and a FENCE +* instruction should be used to order across both domains." +*/ + +#define __iormb () __asm__ __volatile__ ("fence i,io" : : : "memory"); +#define __iowmb () __asm__ __volatile__ ("fence io,o" : : : "memory"); + +#define mmiowb () __asm__ __volatile__ ("fence io,io" : : : "memory"); + +/* +* Relaxed I/O memory access primitives. These follow the Device memory +* ordering rules but do not guarantee any ordering relative to Normal memory +* accesses. +*/ +#define readb_relaxed (c) ({ u8 __r = __raw_readb(c); __r; }) +#define readw_relaxed (c) ({ u16 __r = le16_to_cpu((__force __le16)__raw_readw(c)); __r; }) +#define readl_relaxed (c) ({ u32 __r = le32_to_cpu((__force __le32)__raw_readl(c)); __r; }) +#define readq_relaxed (c) ({ u64 __r = le64_to_cpu((__force __le64)__raw_readq(c)); __r; }) + +#define writeb_relaxed (v,c) ((void)__raw_writeb((v),(c))) +#define writew_relaxed (v,c) ((void)__raw_writew((__force u16)cpu_to_le16(v),(c))) +#define writel_relaxed (v,c) ((void)__raw_writel((__force u32)cpu_to_le32(v),(c))) +#define writeq_relaxed (v,c) ((void)__raw_writeq((__force u64)cpu_to_le64(v),(c))) + +/* +* I/O memory access primitives. Reads are ordered relative to any +* following Normal memory access. Writes are ordered relative to any prior +* Normal memory access. +*/ +#define readb (c) ({ u8 __v = readb_relaxed(c); __iormb(); __v; })
arch/riscv/include/asm/io.h line 148
Quoted 10 lines
arch/riscv/include/asm/io.h new file +10
-0+#define readw (c) ({ u16 __v = readw_relaxed(c); __iormb(); __v; }) +#define readl (c) ({ u32 __v = readl_relaxed(c); __iormb(); __v; }) +#define readq (c) ({ u64 __v = readq_relaxed(c); __iormb(); __v; }) + +#define writeb (v,c) ({ __iowmb(); writeb_relaxed((v),(c)); }) +#define writew (v,c) ({ __iowmb(); writew_relaxed((v),(c)); }) +#define writel (v,c) ({ __iowmb(); writel_relaxed((v),(c)); }) +#define writeq (v,c) ({ __iowmb(); writeq_relaxed((v),(c)); }) + +#include <asm-generic/io.h>
These do not yet contain all the changes we discussed: the relaxed operations don't seem to be ordered against one another and the regular accessors are not ordered against DMA.
Arnd
Palmer Dabbelt
maintainerRe: [PATCH 13/17] RISC-V: Add include subdirectory
Quoted 7 lines · Arnd Bergmann
Quoted 5 lines · Palmer Dabbelt
This patch adds the include files for the RISC-V port. These are mostly based on the score port, but there are a lot of arm64-based files as well.
Signed-off-by Palmer Dabbelt <[email protected]>
Quoted 8 lines
It might be better to split this up into several parts, as the patch is longer than
most people are willing to review at once.The uapi should definitely be a separate patch, as it includes the parts that cannot be changed any more later. memory management (pgtable, mmu, uaccess) would be another part to split out, and possibly all the atomics in one separate patch (along with spinlocks and bitops).
OK, we'll do this for the v3.
Quoted 44 lines
Quoted 44 lines
arch/riscv/include/asm/io.h new file +43
-0+ +/* IO barriers. These only fence on the IO bits because they're only required +* to order device access. We're defining mmiowb because our AMO instructions +* (which are used to implement locks) don't specify ordering. From Chapter 7 +* of v2.2 of the user ISA: +* "The bits order accesses to one of the two address domains, memory or I/O, +* depending on which address domain the atomic instruction is accessing. No +* ordering constraint is implied to accesses to the other domain, and a FENCE +* instruction should be used to order across both domains." +*/ + +#define __iormb () __asm__ __volatile__ ("fence i,io" : : : "memory"); +#define __iowmb () __asm__ __volatile__ ("fence io,o" : : : "memory"); + +#define mmiowb () __asm__ __volatile__ ("fence io,io" : : : "memory"); + +/* +* Relaxed I/O memory access primitives. These follow the Device memory +* ordering rules but do not guarantee any ordering relative to Normal memory +* accesses. +*/ +#define readb_relaxed (c) ({ u8 __r = __raw_readb(c); __r; }) +#define readw_relaxed (c) ({ u16 __r = le16_to_cpu((__force __le16)__raw_readw(c)); __r; }) +#define readl_relaxed (c) ({ u32 __r = le32_to_cpu((__force __le32)__raw_readl(c)); __r; }) +#define readq_relaxed (c) ({ u64 __r = le64_to_cpu((__force __le64)__raw_readq(c)); __r; }) + +#define writeb_relaxed (v,c) ((void)__raw_writeb((v),(c))) +#define writew_relaxed (v,c) ((void)__raw_writew((__force u16)cpu_to_le16(v),(c))) +#define writel_relaxed (v,c) ((void)__raw_writel((__force u32)cpu_to_le32(v),(c))) +#define writeq_relaxed (v,c) ((void)__raw_writeq((__force u64)cpu_to_le64(v),(c))) + +/* +* I/O memory access primitives. Reads are ordered relative to any +* following Normal memory access. Writes are ordered relative to any prior +* Normal memory access. +*/ +#define readb (c) ({ u8 __v = readb_relaxed(c); __iormb(); __v; }) +#define readw (c) ({ u16 __v = readw_relaxed(c); __iormb(); __v; }) +#define readl (c) ({ u32 __v = readl_relaxed(c); __iormb(); __v; }) +#define readq (c) ({ u64 __v = readq_relaxed(c); __iormb(); __v; }) + +#define writeb (v,c) ({ __iowmb(); writeb_relaxed((v),(c)); }) +#define writew (v,c) ({ __iowmb(); writew_relaxed((v),(c)); })
Quoted 8 lines
arch/riscv/include/asm/io.h line 148
Quoted 4 lines
arch/riscv/include/asm/io.h new file +4
-0+#define writel (v,c) ({ __iowmb(); writel_relaxed((v),(c)); }) +#define writeq (v,c) ({ __iowmb(); writeq_relaxed((v),(c)); }) + +#include <asm-generic/io.h> These do not yet contain all the changes we discussed: the relaxed operations don't seem to be ordered against one another and the regular accessors are not ordered against DMA.
Sorry, I must have forgotten to write this -- I just wanted to push out a v3 patch set without the changes to the atomics so everything else could be looked at. I wanted to just go through the atomics completely and fix them, as I found a handful of problems (everything was missing the AQ and RL bits, for example) and figured it would be best to just get them done right.
I think that's not something for after dinner on a Friday, but hopefully I'll get to it tomorrow morning.
Re: [PATCH 13/17] RISC-V: Add include subdirectory
Quoted 1 line · Palmer Dabbelt
Quoted 1 line
Quoted 1 line
+#define mmiowb()
__asm____volatile__("fence io,io" : : : "memory");
I forgot if we already mentioned that but mmiowb is primarily intended to order MMIO stores vs. a subsequent spin_unlock.
I'm not sure an IO only fence is sufficient here.
Note that I've never trusted drivers to get that right, it's a rather bad abstraction to begin with, so on powerpc, instead, I just set a per-cpu flag on every non-relaxed MMIO write and test it in spin_unlock in order to "beef up" the barrier in there if necessary.
Cheers,
Ben.
Palmer Dabbelt
maintainerRe: [patches] Re: [PATCH 13/17] RISC-V: Add include subdirectory
Quoted 6 lines · On Sat, 24 Jun 2017 08:42:05 PDT (-0700), [email protected] wrote:
Quoted 1 line · Palmer Dabbelt
Quoted 1 line
Quoted 1 line
+#define mmiowb()
__asm____volatile__("fence io,io" : : : "memory");I forgot if we already mentioned that but mmiowb is primarily intended to order MMIO stores vs. a subsequent
spin_unlock.
Quoted 6 lines
I'm not sure an IO only fence is sufficient here.
Note that I've never trusted drivers to get that right, it's a rather bad abstraction to begin with, so on powerpc, instead, I just set a per-cpu flag on every non-relaxed MMIO write and test it in
spin_unlockin order to "beef up" the barrier in there if necessary.
Sorry about that -- I thought I'd included a note somewhere that the atomics and barriers weren't ready to go yet, as we'd found a bunch of problems with them in the first review and I needed to go through them all. Arnd suggested copying the PowerPC approach to mmiowb and I like that better, so we're going to use it.
Thanks!
Re: [patches] Re: [PATCH 13/17] RISC-V: Add include subdirectory
Quoted 14 lines · Palmer Dabbelt
Quoted 6 lines · On Sat, 24 Jun 2017 08:42:05 PDT (-0700), [email protected] wrote:
Quoted 1 line · Palmer Dabbelt
Quoted 1 line
Quoted 1 line
+#define mmiowb()
__asm____volatile__("fence io,io" : : : "memory");I forgot if we already mentioned that but mmiowb is primarily intended to order MMIO stores vs. a subsequent
spin_unlock.Quoted 6 lines
I'm not sure an IO only fence is sufficient here.
Note that I've never trusted drivers to get that right, it's a rather bad abstraction to begin with, so on powerpc, instead, I just set a per-cpu flag on every non-relaxed MMIO write and test it in
spin_unlockin order to "beef up" the barrier in there if necessary.
Quoted 5 lines
Sorry about that -- I thought I'd included a note somewhere that the atomics and barriers weren't ready to go yet, as we'd found a bunch of problems with them in the first review and I needed to go through them all. Arnd suggested copying the PowerPC approach to mmiowb and I like that better, so we're going to use it.
Ah yes, I did see your note, I just wasn't sure we had clarified the mmiowb case and thought it was worth mentioning.
Cheers,
Ben,
Peter Zijlstra
maintainerRe: [PATCH 13/17] RISC-V: Add include subdirectory
In reply to Palmer Dabbeltarch/riscv/include/asm/atomic.h
Quoted 8 lines · Palmer Dabbelt
arch/riscv/include/asm/atomic.h new file +7
-0+/* Assume that atomic operations are already serializing */ +#define smp_mb__before_atomic_dec () barrier() +#define smp_mb__after_atomic_dec () barrier() +#define smp_mb__before_atomic_inc () barrier() +#define smp_mb__after_atomic_inc () barrier() +#define smp_mb__before_clear_bit () smp_mb() +#define smp_mb__after_clear_bit () smp_mb()
These no longer exist.. Also how can they be different? bitops would use the same atomic primitives as regular atomic ops would and would thus have the very same implicit ordering.
Peter Zijlstra
maintainerRe: [PATCH 13/17] RISC-V: Add include subdirectory
Quoted 7 lines · Peter Zijlstra
Quoted 5 lines · Palmer Dabbelt
arch/riscv/include/asm/atomic.h new file +5
-0+/* Assume that atomic operations are already serializing */ +#define smp_mb__before_atomic_dec () barrier() +#define smp_mb__after_atomic_dec () barrier() +#define smp_mb__before_atomic_inc () barrier() +#define smp_mb__after_atomic_inc () barrier()
Quoted 6 lines
arch/riscv/include/asm/bitops.h line 32
Quoted 2 lines
arch/riscv/include/asm/bitops.h new file +2
-0+#define smp_mb__before_clear_bit () smp_mb() +#define smp_mb__after_clear_bit () smp_mb()These no longer exist.. Also how can they be different? bitops would use the same atomic primitives as regular atomic ops would and would thus have the very same implicit ordering.
Your manual states that each atomic instruction (be it AMO or LR/SC) have two ordering bits: AQ and RL. If neither are set the instruction is unordered, if either one is set, its either an ACQUIRE or a RELEASE and if both are set its SC.
So you can in fact make the above happen, however your atomic implementation does not appear to use ".aq.rl" mnemonics so would be entirely unordered, just like your bitops.
Therefore the above is just plain wrong and broken.
Peter Zijlstra
maintainerRe: [PATCH 13/17] RISC-V: Add include subdirectory
In reply to Palmer DabbeltQuoted 151 lines · Palmer Dabbelt
+ *
atomic_add- add integer to atomic variable
+ * @i: integer value to add
+ * @v: pointer of typeatomic_t
+ *
+ * Atomically adds @i to @v.
+ */arch/riscv/include/asm/atomic.h new file +144
-0+static inline void atomic_add (int i,atomic_t *v) +{ + __asm__ __volatile__ ( +"amoadd.w zero, %1, %0" + :"+A" (v->counter) + :"r" (i)); +} + +#define atomic_fetch_add atomic_fetch_add +static inline int atomic_fetch_add (unsigned int mask,atomic_t *v) +{ +int out; + + __asm__ __volatile__ ( +"amoadd.w %2, %1, %0" + :"+A" (v->counter),"=r" (out) + :"r" (mask)); +return out; +} + +/** +* atomic_sub - subtract integer from atomic variable +* @i: integer value to subtract +* @v: pointer of type atomic_t +* +* Atomically subtracts @i from @v. +*/ +static inline void atomic_sub (int i,atomic_t *v) +{ +atomic_add (-i, v); +} + +#define atomic_fetch_sub atomic_fetch_sub +static inline int atomic_fetch_sub (unsigned int mask,atomic_t *v) +{ +int out; + + __asm__ __volatile__ ( +"amosub.w %2, %1, %0" + :"+A" (v->counter),"=r" (out) + :"r" (mask)); +return out; +} + +/** +* atomic_add_return - add integer to atomic variable +* @i: integer value to add +* @v: pointer of type atomic_t +* +* Atomically adds @i to @v and returns the result +*/ +static inline int atomic_add_return (int i,atomic_t *v) +{ + registerint c; + + __asm__ __volatile__ ( +"amoadd.w %0, %2, %1" + :"=r" (c),"+A" (v->counter) + :"r" (i)); +return (c + i); +} + +/** +* atomic_sub_return - subtract integer from atomic variable +* @i: integer value to subtract +* @v: pointer of type atomic_t +* +* Atomically subtracts @i from @v and returns the result +*/ +static inline int atomic_sub_return (int i,atomic_t *v) +{ +return atomic_add_return (-i, v); +} + +/** +* atomic_and - Atomically clear bits in atomic variable +* @mask: Mask of the bits to be retained +* @v: pointer of type atomic_t +* +* Atomically retains the bits set in @mask from @v +*/ +static inline void atomic_and (unsigned int mask,atomic_t *v) +{ + __asm__ __volatile__ ( +"amoand.w zero, %1, %0" + :"+A" (v->counter) + :"r" (mask)); +} + +#define atomic_fetch_and atomic_fetch_and +static inline int atomic_fetch_and (unsigned int mask,atomic_t *v) +{ +int out; + + __asm__ __volatile__ ( +"amoand.w %2, %1, %0" + :"+A" (v->counter),"=r" (out) + :"r" (mask)); +return out; +} + +/** +* atomic_or - Atomically set bits in atomic variable +* @mask: Mask of the bits to be set +* @v: pointer of type atomic_t +* +* Atomically sets the bits set in @mask in @v +*/ +static inline void atomic_or (unsigned int mask,atomic_t *v) +{ + __asm__ __volatile__ ( +"amoor.w zero, %1, %0" + :"+A" (v->counter) + :"r" (mask)); +} + +#define atomic_fetch_or atomic_fetch_or +static inline int atomic_fetch_or (unsigned int mask,atomic_t *v) +{ +int out; + + __asm__ __volatile__ ( +"amoor.w %2, %1, %0" + :"+A" (v->counter),"=r" (out) + :"r" (mask)); +return out; +} + +/** +* atomic_xor - Atomically flips bits in atomic variable +* @mask: Mask of the bits to be flipped +* @v: pointer of type atomic_t +* +* Atomically flips the bits set in @mask in @v +*/ +static inline void atomic_xor (unsigned int mask,atomic_t *v) +{ + __asm__ __volatile__ ( +"amoxor.w zero, %1, %0" + :"+A" (v->counter) + :"r" (mask)); +} + +#define atomic_fetch_xor atomic_fetch_xor
arch/riscv/include/asm/atomic.h line 333
Quoted 10 lines
arch/riscv/include/asm/atomic.h new file +10
-0+static inline int atomic_fetch_xor (unsigned int mask,atomic_t *v) +{ +int out; + + __asm__ __volatile__ ( +"amoxor.w %2, %1, %0" + :"+A" (v->counter),"=r" (out) + :"r" (mask)); +return out; +}
What pretty much all the other architectures do is something like:
#define ATOMIC_OP(op, asm_op, c_op) \
static __always_inline void atomic_##op(int i, atomic_t *v) \
{ \
__asm__ __volatile__ ( \
"amo" #asm_op ".w zero, %1, %0" \
: "+A" (v->counter) \
: "r" (i)); \
}#define ATOMIC_FETCH_OP(op, asm_op, c_op) \
static __always_inline int atomic_fetch_##op(int i, atomic_t *v)\
{ \
register int ret; \
__asm__ __volatile__ ( \
"amo" #asm_op ".w %2, %1, %0" \
: "+A" (v->counter), "=r" (ret) \
: "r" (mask)); \
return ret; \
}#define ATOMIC_OP_RETURN(op, asm_op, c_op) \
static __always_inline int atomic_##op##_return(int i, atomic_t *v) \
{ \
return atomic_fetch_##op(i, v) c_op i; \
}#define ATOMIC_OPS(op, asm_op, c_op) \ ATOMIC_OP(op, asm_op, c_op) \ ATOMIC_OP_RETURN(op, asm_op, c_op) \ ATOMIC_FETCH_OP(op, asm_op, c_op)
ATOMIC_OPS(add, add, +)ATOMIC_OPS(sub, sub, -)
#undef ATOMIC_OPS
#define ATOMIC_OPS(op, asm_op, c_op) \ ATOMIC_OP(op, asm_op, c_op) \ ATOMIC_FETCH_OP(op, asm_op, c_op)
ATOMIC_OPS(and, and, &)ATOMIC_OPS(or, or, |)ATOMIC_OPS(xor, xor, ^)
#undef ATOMIC_OPS
Which is much simpler no?
Peter Zijlstra
maintainerRe: [PATCH 13/17] RISC-V: Add include subdirectory
Quoted 12 lines · Peter Zijlstra
arch/riscv/include/asm/atomic.h line 93
Quoted 10 lines · Palmer Dabbelt
arch/riscv/include/asm/atomic.h new file +10
-0+static inline int atomic_fetch_sub (unsigned int mask,atomic_t *v) +{ +int out; + + __asm__ __volatile__ ( +"amosub.w %2, %1, %0" + :"+A" (v->counter),"=r" (out) + :"r" (mask)); +return out; +}
Your instruction manual does not list AMOSUB as a valid instruction. So either it is wrong or this code never compiled. Please clarify.
Peter Zijlstra
maintainerRe: [PATCH 13/17] RISC-V: Add include subdirectory
In reply to Peter ZijlstraQuoted 43 lines · Peter Zijlstra
On Tue, Jun 06, 2017 at 04:00:03PM -0700, Palmer Dabbelt wrote:
What pretty much all the other architectures do is something like:#define
ATOMIC_OP(op, asm_op, c_op)\
static__always_inlinevoid atomic_##op(int i,atomic_t*v) \{ \ __asm__ __volatile__ ( \ "amo" #asm_op ".w zero, %1, %0" \ : "+A" (v->counter) \ : "r" (i)); \ }#define
ATOMIC_FETCH_OP(op, asm_op, c_op)\
static__always_inlineint atomic_fetch_##op(int i,atomic_t*v)\{ \ register int ret; \ __asm__ __volatile__ ( \ "amo" #asm_op ".w %2, %1, %0" \ : "+A" (v->counter), "=r" (ret) \ : "r" (mask)); \ return ret; \ }#define
ATOMIC_OP_RETURN(op, asm_op, c_op)\
static__always_inlineint atomic_##op##_return(int i,atomic_t*v) \{ \ return atomic_fetch_##op(i, v) c_op i; \ }#define ATOMIC_OPS(op, asm_op, c_op) \ ATOMIC_OP(op, asm_op, c_op) \ ATOMIC_OP_RETURN(op, asm_op, c_op) \ ATOMIC_FETCH_OP(op, asm_op, c_op)
ATOMIC_OPS(add, add, +)ATOMIC_OPS(sub, sub, -)#undef
ATOMIC_OPS#define ATOMIC_OPS(op, asm_op, c_op) \ ATOMIC_OP(op, asm_op, c_op) \ ATOMIC_FETCH_OP(op, asm_op, c_op)
Quoted 7 lines
ATOMIC_OPS(and, and, &)ATOMIC_OPS(or, or, |)ATOMIC_OPS(xor, xor, ^)#undef
ATOMIC_OPSWhich is much simpler no?
In fact, after having read your manual you'd want something like:
#define ATOMIC_OP(op, asm_op, c_op) \
static __always_inline void atomic_##op(int i, atomic_t *v) \
{ \
__asm__ __volatile__ ( \
"amo" #asm_op ".w zero, %1, %0" \
: "+A" (v->counter) \
: "r" (i)); \
}#define ATOMIC_FETCH_OP(op, asm_op, c_op, asm_or, order) \
static __always_inline int atomic_fetch_##op##order(int i, atomic_t *v)\
{ \
register int ret; \
__asm__ __volatile__ ( \
"amo" #asm_op ".w" #asm_or " %2, %1, %0" \
: "+A" (v->counter), "=r" (ret) \
: "r" (mask)); \
return ret; \
}#define ATOMIC_OP_RETURN(op, asm_op, c_op, asm_or, order) \
static __always_inline int atomic_##op##_return##order(int i, atomic_t *v) \
{ \
return atomic_fetch_##op##order(i, v) c_op i; \
}#define ATOMIC_OPS(op, asm_op, c_op) \ ATOMIC_OP(op, asm_op, c_op, , _relaxed) \ ATOMIC_OP_RETURN(op, asm_op, c_op, , _relaxed) \ ATOMIC_FETCH_OP(op, asm_op, c_op, , _relaxed)
ATOMIC_OPS(add, add, +)ATOMIC_OPS(sub, sub, -)
#undef ATOMIC_OPS
#define ATOMIC_OPS(op, asm_op, c_op, asm_or, order) \ ATOMIC_OP_RETURN(op, asm_op, c_op, , _relaxed) \ ATOMIC_FETCH_OP(op, asm_op, c_op, , _relaxed)
ATOMIC_OPS(add, add, +, ".aq", _acquire) ATOMIC_OPS(add, add, +, ".rl", _release) ATOMIC_OPS(add, add, +, ".aq.rl", )
ATOMIC_OPS(sub, sub, -, ".aq", _acquire) ATOMIC_OPS(sub, sub, -, ".rl", _release) ATOMIC_OPS(sub, sub, -, ".aq.rl", )
#undef ATOMIC_OPS
#define ATOMIC_OPS(op, asm_op, c_op) \ ATOMIC_OP(op, asm_op, c_op) \ ATOMIC_FETCH_OP(op, asm_op, c_op, , _relaxed)
ATOMIC_OPS(and, and, &)ATOMIC_OPS(or, or, |)ATOMIC_OPS(xor, xor, ^)
#undef ATOMIC_OPS
ATOMIC_FETCH_OP(and, and, &, ".aq", _acquire) ATOMIC_FETCH_OP(and, and, &, ".rl", _release) ATOMIC_FETCH_OP(and, and, &, ".aq.rl", )
ATOMIC_FETCH_OP(or, or, |, ".aq", _acquire) ATOMIC_FETCH_OP(or, or, |, ".rl", _release) ATOMIC_FETCH_OP(or, or, |, ".aq.rl", )
ATOMIC_FETCH_OP(xor, xor, ^, ".aq", _acquire) ATOMIC_FETCH_OP(xor, xor, ^, ".rl", _release) ATOMIC_FETCH_OP(xor, xor, ^, ".aq.rl", )
#define smp_mb__before_atomic() smp_mb()
#define smp_mb__after_atomic() smp_mb()
Which (pending the sub confusion) will generate the entire set of:
atomic_add, atomic_add_return{_relaxed,_acquire,_release,} atomic_fetch_add{_relaxed,_acquire,_release,} atomic_sub, atomic_sub_return{_relaxed,_acquire,_release,} atomic_fetch_sub{_relaxed,_acquire,_release,}
atomic_and, atomic_fetch_and{_relaxed,_acquire,_release,} atomic_or, atomic_fetch_or{_relaxed,_acquire,_release,} atomic_xor, atomic_fetch_xor{_relaxed,_acquire,_release,}
Peter Zijlstra
maintainerRe: [PATCH 13/17] RISC-V: Add include subdirectory
Quoted 9 lines · Peter Zijlstra
Which (pending the sub confusion) will generate the entire set of:
atomic_add, atomic_add_return{_relaxed,_acquire,_release,} atomic_fetch_add{_relaxed,_acquire,_release,}atomic_sub, atomic_sub_return{_relaxed,_acquire,_release,} atomic_fetch_sub{_relaxed,_acquire,_release,}
atomic_and, atomic_fetch_and{_relaxed,_acquire,_release,}atomic_or, atomic_fetch_or{_relaxed,_acquire,_release,}atomic_xor, atomic_fetch_xor{_relaxed,_acquire,_release,}
Another approach would be to override __atomic_op_{acquire,release} and use things like:
"FENCE r,rw" -- (load) ACQUIRE
"FENCE rw,w" -- (store) RELEASE
And then you only need to provide _relaxed atomics.
Also, and I didn't check for that, you need to provide:
smp_load_acquire(), smp_store_release(), atomic_read_acquire(), atomic_store_release().
Re: [PATCH 13/17] RISC-V: Add include subdirectory
[sorry, jumping in here because it's the only mail I have relating to
patch 13]
Quoted 17 lines · Peter Zijlstra
Quoted 9 lines · Peter Zijlstra
Which (pending the sub confusion) will generate the entire set of:
atomic_add, atomic_add_return{_relaxed,_acquire,_release,} atomic_fetch_add{_relaxed,_acquire,_release,}atomic_sub, atomic_sub_return{_relaxed,_acquire,_release,} atomic_fetch_sub{_relaxed,_acquire,_release,}
atomic_and, atomic_fetch_and{_relaxed,_acquire,_release,}atomic_or, atomic_fetch_or{_relaxed,_acquire,_release,}atomic_xor, atomic_fetch_xor{_relaxed,_acquire,_release,}Another approach would be to override __atomic_op_{acquire,release} and use things like:
"FENCE r,rw" -- (load) ACQUIRE
"FENCE rw,w" -- (store) RELEASE
Quoted 6 lines
And then you only need to provide
_relaxedatomics.Also, and I didn't check for that, you need to provide:
smp_load_acquire(),smp_store_release(),atomic_read_acquire(),atomic_store_release().
Is there an up-to-date specification for the RISC-V memory model? I looked at:
https://github.com/riscv/riscv-isa-manual/releases/download/riscv-user-2.2/riscv-spec-v2.2.pdf
but it says:
| 2.7 Memory Model | This section is out of date as the RISC-V memory model is | currently under revision to ensure it can efficiently support current | programming language memory models. The revised base mem- ory model will | contain further ordering constraints, including at least that loads to the | same address from the same hart cannot be reordered, and that syntactic data | dependencies between instructions are respected
which, on the one hand is reassuring (because ignoring dependency ordering is plain broken), but on the other it doesn't go quite far enough in defining exactly what constitutes a "syntactic data dependency". The cumulativity of your fences also needs defining, because I think this was up in the air at some point and the document above doesn't seem to tackle it (it doesn't seem to describe what constitutes being a memory of the predecessor or successor sets)
Could you shed some light on this please? We've started relying on RW control dependencies in semi-recent history, so it's important to get this nailed down.
Thanks,
Will
P.S. You should also totally get your architects to write a formal model ;)
Palmer Dabbelt
maintainerRe: [PATCH 13/17] RISC-V: Add include subdirectory
Quoted 25 lines · On Wed, 07 Jun 2017 06:16:11 PDT (-0700), [email protected] wrote:
[sorry, jumping in here because it's the only mail I have relating to
patch 13]Quoted 21 lines · Peter Zijlstra
Quoted 9 lines · Peter Zijlstra
Which (pending the sub confusion) will generate the entire set of:
atomic_add, atomic_add_return{_relaxed,_acquire,_release,} atomic_fetch_add{_relaxed,_acquire,_release,}atomic_sub, atomic_sub_return{_relaxed,_acquire,_release,} atomic_fetch_sub{_relaxed,_acquire,_release,}
atomic_and, atomic_fetch_and{_relaxed,_acquire,_release,}atomic_or, atomic_fetch_or{_relaxed,_acquire,_release,}atomic_xor, atomic_fetch_xor{_relaxed,_acquire,_release,}Another approach would be to override __atomic_op_{acquire,release} and use things like:
"FENCE r,rw" -- (load) ACQUIRE
"FENCE rw,w" -- (store) RELEASEAnd then you only need to provide
_relaxedatomics.Also, and I didn't check for that, you need to provide:
Quoted 7 lines
Quoted 2 lines
smp_load_acquire(),smp_store_release(),atomic_read_acquire(),atomic_store_release().Is there an up-to-date specification for the RISC-V memory model? I looked at:
https://github.com/riscv/riscv-isa-manual/releases/download/riscv-user-2.2/riscv-spec-v2.2.pdf
That's the most up to date spec.
Quoted 10 lines
but it says:
| 2.7 Memory Model | This section is out of date as the RISC-V memory model is | currently under revision to ensure it can efficiently support current | programming language memory models. The revised base mem- ory model will | contain further ordering constraints, including at least that loads to the | same address from the same hart cannot be reordered, and that syntactic data | dependencies between instructions are respected
Quoted 6 lines
which, on the one hand is reassuring (because ignoring dependency ordering is plain broken), but on the other it doesn't go quite far enough in defining exactly what constitutes a "syntactic data dependency". The cumulativity of your fences also needs defining, because I think this was up in the air at some point and the document above doesn't seem to tackle it (it doesn't seem to describe what constitutes being a memory of the predecessor or successor sets)
Unfortunately I'm not really a formal memory model guy, so I probably know a lot less about what a "syntactic data dependency" is than you do. I believe the plan (like for most of RISC-V) is to avoid doing anything weird, to support existing software systems, and to allow for implementation flexibility where possible.
Quoted 2 lines
Could you shed some light on this please? We've started relying on RW control dependencies in semi-recent history, so it's important to get this nailed down.
This has been a sticking point for a while. The result of lacking a proper memory model has been that implementations have been extremely conservative and as a result there aren't any issues in practice, but that itself is a bad thing.
Quoted 5 lines
Thanks,
Will
P.S. You should also totally get your architects to write a formal model ;)
The RISC-V organization has a working group defining a formal memory model. Here's the original posting about the working group
https://groups.google.com/a/groups.riscv.org/forum/#!topic/isa-dev/Oxm_IvfYItY
To the best of my understanding we hope to have a formal memory model defined by the end of the year. I've added Daniel Lustig, the chair of the working group, to the thread. He knows a lot more about this than I do.
Daniel Lustig
reviewerRE: [PATCH 13/17] RISC-V: Add include subdirectory
Quoted 4 lines
Quoted 2 lines
https://github.com/riscv/riscv-isa-manual/releases/download/riscv-user
-2.2/riscv-spec-v2.2.pdfThat's the most up to date spec.
Yes, that's the most up to date public spec. Internally, the RISC-V memory model task group has been working on fixing the memory model spec for the past couple of months now. We're aiming to release it for public review well before the end of the year. Hopefully in the coming weeks even.
Quoted 7 lines
Quoted 7 lines
which, on the one hand is reassuring (because ignoring dependency ordering is plain broken), but on the other it doesn't go quite far enough in defining exactly what constitutes a "syntactic data dependency". The cumulativity of your fences also needs defining, because I think this was up in the air at some point and the document above doesn't seem to tackle it (it doesn't seem to describe what constitutes being a memory of the predecessor or successor sets)
That will all covered in the new spec.
Quoted 2 lines
Quoted 2 lines
P.S. You should also totally get your architects to write a formal model ;)
Also in progress :)
Were there any more specific questions I can answer in the meantime? Or any specific concern you'd like to point me to?
Dan
Re: [PATCH 13/17] RISC-V: Add include subdirectory
Hi Dan,
Quoted 9 lines · Daniel Lustig
Quoted 4 lines
Quoted 2 lines
https://github.com/riscv/riscv-isa-manual/releases/download/riscv-user
-2.2/riscv-spec-v2.2.pdfThat's the most up to date spec.
Yes, that's the most up to date public spec. Internally, the RISC-V memory model task group has been working on fixing the memory model spec for the past couple of months now. We're aiming to release it for public review well before the end of the year. Hopefully in the coming weeks even.
Excellent, cheers for the update.
Quoted 8 lines
Quoted 7 lines
Quoted 7 lines
which, on the one hand is reassuring (because ignoring dependency ordering is plain broken), but on the other it doesn't go quite far enough in defining exactly what constitutes a "syntactic data dependency". The cumulativity of your fences also needs defining, because I think this was up in the air at some point and the document above doesn't seem to tackle it (it doesn't seem to describe what constitutes being a memory of the predecessor or successor sets)
Quoted 6 lines
That will all covered in the new spec.
Quoted 2 lines
Quoted 2 lines
P.S. You should also totally get your architects to write a formal model ;)Also in progress :)
3/3 :)
Quoted 2 lines
Were there any more specific questions I can answer in the meantime? Or any specific concern you'd like to point me to?
Nothing specific, but we won't be able to review the memory-ordering/atomics/locking parts of this patch series until we have a spec.
Will
Peter Zijlstra
maintainerRe: [PATCH 13/17] RISC-V: Add include subdirectory
In reply to Peter ZijlstraQuoted 17 lines · Peter Zijlstra
Quoted 9 lines · Peter Zijlstra
Which (pending the sub confusion) will generate the entire set of:
atomic_add, atomic_add_return{_relaxed,_acquire,_release,} atomic_fetch_add{_relaxed,_acquire,_release,}atomic_sub, atomic_sub_return{_relaxed,_acquire,_release,} atomic_fetch_sub{_relaxed,_acquire,_release,}
atomic_and, atomic_fetch_and{_relaxed,_acquire,_release,}atomic_or, atomic_fetch_or{_relaxed,_acquire,_release,}atomic_xor, atomic_fetch_xor{_relaxed,_acquire,_release,}Another approach would be to override __atomic_op_{acquire,release} and use things like:
"FENCE r,rw" -- (load) ACQUIRE
"FENCE rw,w" -- (store) RELEASE
Quoted 6 lines
And then you only need to provide
_relaxedatomics.Also, and I didn't check for that, you need to provide:
smp_load_acquire(),smp_store_release(),atomic_read_acquire(),atomic_store_release().
Also, you probably need to provide smp_mb__before_spinlock(), but also see:
Palmer Dabbelt
maintainerRe: [PATCH 13/17] RISC-V: Add include subdirectory
In reply to Peter ZijlstraQuoted 17 lines · On Wed, 07 Jun 2017 05:58:50 PDT (-0700), [email protected] wrote:
Quoted 9 lines · Peter Zijlstra
Which (pending the sub confusion) will generate the entire set of:
atomic_add, atomic_add_return{_relaxed,_acquire,_release,} atomic_fetch_add{_relaxed,_acquire,_release,}atomic_sub, atomic_sub_return{_relaxed,_acquire,_release,} atomic_fetch_sub{_relaxed,_acquire,_release,}
atomic_and, atomic_fetch_and{_relaxed,_acquire,_release,}atomic_or, atomic_fetch_or{_relaxed,_acquire,_release,}atomic_xor, atomic_fetch_xor{_relaxed,_acquire,_release,}Another approach would be to override __atomic_op_{acquire,release} and use things like:
"FENCE r,rw" -- (load) ACQUIRE
"FENCE rw,w" -- (store) RELEASE
Quoted 6 lines
And then you only need to provide
_relaxedatomics.Also, and I didn't check for that, you need to provide:
smp_load_acquire(),smp_store_release(),atomic_read_acquire(),atomic_store_release().
OK, thanks for looking so deeply into this. Sorry it was such a mess, I thought I included a note somewhere that this all needed to be redone -- I just wanted to get a v2 out first as that split all the drivers out. I've went ahead and completely rewrote atomic.h using your suggestions in a slightly modified way. It includes
* _relaxed, _acquire, and _release versions of everything via a bunch of macros.
* What I believe to be correct aqrl bits on every op.
* 64-bit and 32-bit atomics (as opposed to just copying everything)
I didn't implement try_cmpxchg yet. I'm going to go ahead and sort through our memory barriers, look at the few remaining CR comments from our v2, and then submit a v3 patch set.
I'm only replying to this message, but I believe I'll have taken into account all your comments for the v3.
Thanks, again, for your time!
Peter Zijlstra
maintainerRe: [PATCH 13/17] RISC-V: Add include subdirectory
In reply to Palmer DabbeltQuoted 43 lines · Palmer Dabbelt
arch/riscv/include/asm/cmpxchg.h new file +37
-0@@ -0,0 +1,124 @@ +/* +* Copyright (C) 2014 Regents of the University of California +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation, version 2. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +*/ + +#ifndef _ASM_RISCV_CMPXCHG_H +#define _ASM_RISCV_CMPXCHG_H + +#include <linux/bug.h> + +#ifdef CONFIG_ISA_A + +#include <asm/barrier.h> + +#define __xchg (new, ptr, size) \ +({ \ + __typeof__(ptr) __ptr = (ptr); \ + __typeof__(new) __new = (new); \ + __typeof__(*(ptr)) __ret; \ + switch (size) { \ + case 4: \ + __asm__ __volatile__ ( \ + "amoswap.w %0, %2, %1" \ + : "=r" (__ret), "+A" (*__ptr) \ + : "r" (__new)); \ + break; \ + case 8: \ + __asm__ __volatile__ ( \ + "amoswap.d %0, %2, %1" \
arch/riscv/include/asm/cmpxchg.h line 47
Quoted 10 lines
arch/riscv/include/asm/cmpxchg.h new file +10
-0+ : "=r" (__ret), "+A" (*__ptr) \ + : "r" (__new)); \ +break ; \ +default : \ +BUILD_BUG (); \ + } \ + __ret; \ +}) + +#define xchg (ptr, x) (__xchg((x), (ptr), sizeof(*(ptr))))
our xchg() is fully ordered, and thus you need to use "amoswap.aq.rl"
Quoted 41 lines
arch/riscv/include/asm/cmpxchg.h new file +41
-0+ + +/* +* Atomic compare and exchange. Compare OLD with MEM, if identical, +* store NEW in MEM. Return the initial value in MEM. Success is +* indicated by comparing RETURN with OLD. +*/ +#define __cmpxchg (ptr, old, new, size) \ +({ \ + __typeof__(ptr) __ptr = (ptr); \ + __typeof__(old) __old = (old); \ + __typeof__(new) __new = (new); \ + __typeof__(*(ptr)) __ret; \ + register unsigned int __rc; \ + switch (size) { \ + case 4: \ + __asm__ __volatile__ ( \ + "0:" \ + "lr.w %0, %2\n" \ + "bne %0, %z3, 1f\n" \ + "sc.w %1, %z4, %2\n" \ + "bnez %1, 0b\n" \ + "1:" \ + : "=&r" (__ret), "=&r" (__rc), "+A" (*__ptr) \ + : "rJ" (__old), "rJ" (__new)); \ + break; \ + case 8: \ + __asm__ __volatile__ ( \ + "0:" \ + "lr.d %0, %2\n" \ + "bne %0, %z3, 1f\n" \ + "sc.d %1, %z4, %2\n" \ + "bnez %1, 0b\n" \ + "1:" \ + : "=&r" (__ret), "=&r" (__rc), "+A" (*__ptr) \ + : "rJ" (__old), "rJ" (__new)); \ + break; \ + default: \ + BUILD_BUG(); \ + } \ + __ret; \
arch/riscv/include/asm/cmpxchg.h line 98
Quoted 10 lines
arch/riscv/include/asm/cmpxchg.h new file +10
-0+}) + +#define __cmpxchg_mb (ptr, old, new, size) \ +({ \ + __typeof__(*(ptr)) __ret; \ + smp_mb(); \ + __ret = __cmpxchg((ptr), (old), (new), (size)); \ + smp_mb(); \ + __ret; \ +})
Your ISA of course, but wouldn't setting the AQ and RL bits on LR/SC be cheaper than doing two full barriers around the thing?
Note that cmpxchg() doesn't need to provide ordering on failure.
Further note that we have:
{atomic_,}cmpxchg{_relaxed,_acquire,_release,}()and recently:
{atomic_,}try_cmpxchg{_relaxed,_acquire,_release,}()Peter Zijlstra
maintainerRe: [PATCH 13/17] RISC-V: Add include subdirectory
In reply to Palmer DabbeltQuoted 18 lines · Palmer Dabbelt
arch/riscv/include/asm/spinlock.h new file +12
-0@@ -0,0 +1,155 @@ +/* +* Copyright (C) 2015 Regents of the University of California +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation, version 2. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +*/
arch/riscv/include/asm/spinlock.h line 22
Quoted 10 lines
arch/riscv/include/asm/spinlock.h new file +10
-0+ +#ifndef _ASM_RISCV_SPINLOCK_H +#define _ASM_RISCV_SPINLOCK_H + +#include <linux/kernel.h> +#include <asm/current.h> + +/* +* Simple spin lock operations. These provide no fairness guarantees. +*/
Any reason to use a test-and-set spinlock at all?
arch/riscv/include/asm/spinlock.h line 27
Quoted 5 lines
arch/riscv/include/asm/spinlock.h new file +5
-0+ +#define arch_spin_lock_flags (lock, flags) arch_spin_lock(lock) +#define arch_spin_is_locked (x) ((x)->lock != 0) +#define arch_spin_unlock_wait (x) \ + do { cpu_relax(); } while ((x)->lock)
Hehe, yeah, no ;-) There are ordering constraints on that.
Quoted 32 lines
arch/riscv/include/asm/spinlock.h new file +32
-0+ +static inline void arch_spin_unlock (arch_spinlock_t *lock) +{ + __asm__ __volatile__ ( +"amoswap.w.rl x0, x0, %0" + :"=A" (lock->lock) + ::"memory" ); +} + +static inline int arch_spin_trylock (arch_spinlock_t *lock) +{ +int tmp =1 , busy; + + __asm__ __volatile__ ( +"amoswap.w.aq %0, %2, %1" + :"=r" (busy),"+A" (lock->lock) + :"r" (tmp) + :"memory" ); + +return !busy; +} + +static inline void arch_spin_lock (arch_spinlock_t *lock) +{ +while (1 ) { +if (arch_spin_is_locked (lock)) +continue ; + +if (arch_spin_trylock (lock)) +break ; + } +}
Peter Zijlstra
maintainerRe: [PATCH 13/17] RISC-V: Add include subdirectory
Quoted 12 lines · Peter Zijlstra
Quoted 12 lines
arch/riscv/include/asm/spinlock.h new file +12
-0+static inline void arch_spin_unlock (arch_spinlock_t *lock) +{ + __asm__ __volatile__ ( +"amoswap.w.rl x0, x0, %0" + :"=A" (lock->lock) + ::"memory" ); +} + +static inline int arch_spin_trylock (arch_spinlock_t *lock) +{ +int tmp =1 , busy; +
Quoted 8 lines
arch/riscv/include/asm/spinlock.h line 48
Quoted 8 lines
arch/riscv/include/asm/spinlock.h new file +8
-0+ __asm__ __volatile__ ( +"amoswap.w.aq %0, %2, %1" + :"=r" (busy),"+A" (lock->lock) + :"r" (tmp) + :"memory" ); + +return !busy; +}
One other thing, you need to describe the acquire/release semantics for your platform. Is the above lock RCpc or RCsc ? If RCpc, you need to look into adding smp_mb__after_unlock_lock().
Palmer Dabbelt
maintainerRe: [PATCH 13/17] RISC-V: Add include subdirectory
In reply to Peter ZijlstraQuoted 23 lines · On Wed, 07 Jun 2017 06:17:27 PDT (-0700), [email protected] wrote:
Quoted 22 lines · Palmer Dabbelt
arch/riscv/include/asm/spinlock.h new file +16
-0@@ -0,0 +1,155 @@ +/* +* Copyright (C) 2015 Regents of the University of California +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation, version 2. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +*/ + +#ifndef _ASM_RISCV_SPINLOCK_H +#define _ASM_RISCV_SPINLOCK_H +
Quoted 8 lines
arch/riscv/include/asm/spinlock.h line 22
Quoted 6 lines
arch/riscv/include/asm/spinlock.h new file +6
-0+#include <linux/kernel.h> +#include <asm/current.h> + +/* +* Simple spin lock operations. These provide no fairness guarantees. +*/ Any reason to use a test-and-set spinlock at all?
Just simplicity. I looked at the MIPS ticket lock and I think we can implement that while still maintaining the forward progress constraints on our LR/SC sequences. I added a FIXME about it, which I'll try to get around to
https://github.com/riscv/riscv-linux/commit/a75d28c849e695639b7909ffa88ce571abfb0c76
but I'm going to try and get a v3 patch set out first.
Quoted 7 lines
arch/riscv/include/asm/spinlock.h line 27
Quoted 5 lines
arch/riscv/include/asm/spinlock.h new file +5
-0+ +#define arch_spin_lock_flags (lock, flags) arch_spin_lock(lock) +#define arch_spin_is_locked (x) ((x)->lock != 0) +#define arch_spin_unlock_wait (x) \ + do { cpu_relax(); } while ((x)->lock)Hehe, yeah, no ;-) There are ordering constraints on that.
OK. I copied the ordering guarntees from MIPS here
https://github.com/riscv/riscv-linux/commit/7d16920452c6bd14c847aade2d51c56d2a1ae457
Quoted 24 lines
Quoted 24 lines
arch/riscv/include/asm/spinlock.h new file +24
-0+ +static inline void arch_spin_unlock (arch_spinlock_t *lock) +{ + __asm__ __volatile__ ( +"amoswap.w.rl x0, x0, %0" + :"=A" (lock->lock) + ::"memory" ); +} + +static inline int arch_spin_trylock (arch_spinlock_t *lock) +{ +int tmp =1 , busy; + + __asm__ __volatile__ ( +"amoswap.w.aq %0, %2, %1" + :"=r" (busy),"+A" (lock->lock) + :"r" (tmp) + :"memory" ); + +return !busy; +} + +static inline void arch_spin_lock (arch_spinlock_t *lock) +{
Quoted 8 lines
arch/riscv/include/asm/spinlock.h line 59
Quoted 8 lines
arch/riscv/include/asm/spinlock.h new file +8
-0+while (1 ) { +if (arch_spin_is_locked (lock)) +continue ; + +if (arch_spin_trylock (lock)) +break ; + } +}
Thanks for all the comments!
Palmer Dabbelt
maintainerPATCH 14/17 RISC-V: lib files
In reply to Palmer DabbeltMost of these files are based off code in GCC, but the delay code is mostly from ARM.
--- arch/riscv/lib/Makefile | 5 ++ arch/riscv/lib/delay.c | 107 ++++++++++++++++++++++++++++++++++++++++ arch/riscv/lib/memcpy.S | 98 +++++++++++++++++++++++++++++++++++++ arch/riscv/lib/memset.S | 118 ++++++++++++++++++++++++++++++++++++++++++++ arch/riscv/lib/uaccess.S | 125 +++++++++++++++++++++++++++++++++++++++++++++++ arch/riscv/lib/udivdi3.S | 39 +++++++++++++++ 6 files changed, 492 insertions(+) create mode 100644 arch/riscv/lib/Makefile create mode 100644 arch/riscv/lib/delay.c create mode 100644 arch/riscv/lib/memcpy.S create mode 100644 arch/riscv/lib/memset.S create mode 100644 arch/riscv/lib/uaccess.S create mode 100644 arch/riscv/lib/udivdi3.S
arch/riscv/lib/Makefile new file +5 -0
@@ -0,0 +1,5 @@ +lib-y := delay.o memcpy.o memset.o uaccess.o + +ifeq ($(CONFIG_64BIT),) +lib-y += udivdi3.o +endif
arch/riscv/lib/delay.c new file +107 -0
107 lines not on this page · raw message
arch/riscv/lib/memcpy.S new file +98 -0
98 lines not on this page · raw message
arch/riscv/lib/memset.S new file +118 -0
118 lines not on this page · raw message
arch/riscv/lib/uaccess.S new file +125 -0
125 lines not on this page · raw message
arch/riscv/lib/udivdi3.S new file +39 -0
@@ -0,0 +1,39 @@ +/* + * Copyright (C) 2016-2017 Free Software Foundation, Inc. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation, version 2. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + + .globl __udivdi3 +__udivdi3: + mv a2, a1 + mv a1, a0 + li a0, -1 + beqz a2, .L5 + li a3, 1 + bgeu a2, a1, .L2 +.L1: + blez a2, .L2 + slli a2, a2, 1 + slli a3, a3, 1 + bgtu a1, a2, .L1 +.L2: + li a0, 0 +.L3: + bltu a1, a2, .L4 + sub a1, a1, a2 + or a0, a0, a3 +.L4: + srli a3, a3, 1 + srli a2, a2, 1 + bnez a3, .L3 +.L5: + ret +
Signature · 1 line
2.13.0
Palmer Dabbelt
maintainerPATCH 15/17 RISC-V: Add mm subdirectory
In reply to Palmer DabbeltThese files are mostly based on the score port, but as all the non-stub functions are very ISA specific they've been heavily modified.
--- arch/riscv/mm/Makefile | 1 + arch/riscv/mm/extable.c | 37 +++++++ arch/riscv/mm/fault.c | 280 ++++++++++++++++++++++++++++++++++++++++++++++++ arch/riscv/mm/init.c | 72 +++++++++++++ arch/riscv/mm/ioremap.c | 93 ++++++++++++++++ 5 files changed, 483 insertions(+) create mode 100644 arch/riscv/mm/Makefile create mode 100644 arch/riscv/mm/extable.c create mode 100644 arch/riscv/mm/fault.c create mode 100644 arch/riscv/mm/init.c create mode 100644 arch/riscv/mm/ioremap.c
arch/riscv/mm/Makefile new file +1 -0
@@ -0,0 +1 @@ +obj-y := init.o fault.o extable.o ioremap.o
arch/riscv/mm/extable.c new file +37 -0
@@ -0,0 +1,37 @@ +/* +* Copyright (C) 2009 Sunplus Core Technology Co., Ltd. +* Lennox Wu <[email protected]> +* Chen Liqin <[email protected]> +* Copyright (C) 2013 Regents of the University of California +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, see the file COPYING, or write +* to the Free Software Foundation, Inc., +*/ + + +#include <linux/extable.h> +#include <linux/module.h> +#include <linux/uaccess.h> + +int fixup_exception (struct pt_regs *regs) +{ +const struct exception_table_entry *fixup; + + fixup =search_exception_tables (regs->sepc); +if (fixup) { + regs->sepc = fixup->fixup; +return 1 ; + } +return 0 ; +}
arch/riscv/mm/fault.c new file +280 -0
280 lines not on this page · raw message
arch/riscv/mm/init.c new file +72 -0
72 lines not on this page · raw message
arch/riscv/mm/ioremap.c new file +93 -0
93 lines not on this page · raw message
Signature · 1 line
2.13.0
Palmer Dabbelt
maintainerPATCH 16/17 RISC-V: Add kernel subdirectory
In reply to Palmer DabbeltThese files were mostly based on the score port, but many of them are very ISA specific.
--- arch/riscv/kernel/.gitignore | 1 + arch/riscv/kernel/Makefile | 16 ++ arch/riscv/kernel/asm-offsets.c | 316 +++++++++++++++++++++++++++ arch/riscv/kernel/cacheinfo.c | 103 +++++++++ arch/riscv/kernel/cpu.c | 89 ++++++++ arch/riscv/kernel/entry.S | 437 +++++++++++++++++++++++++++++++++++++ arch/riscv/kernel/head.S | 147 +++++++++++++ arch/riscv/kernel/irq.c | 20 ++ arch/riscv/kernel/module.c | 215 ++++++++++++++++++ arch/riscv/kernel/process.c | 132 +++++++++++ arch/riscv/kernel/ptrace.c | 147 +++++++++++++ arch/riscv/kernel/reset.c | 36 +++ arch/riscv/kernel/riscv_ksyms.c | 16 ++ arch/riscv/kernel/setup.c | 240 ++++++++++++++++++++ arch/riscv/kernel/signal.c | 257 ++++++++++++++++++++++ arch/riscv/kernel/smp.c | 110 ++++++++++ arch/riscv/kernel/smpboot.c | 103 +++++++++ arch/riscv/kernel/stacktrace.c | 177 +++++++++++++++ arch/riscv/kernel/sys_riscv.c | 85 ++++++++ arch/riscv/kernel/syscall_table.c | 25 +++ arch/riscv/kernel/traps.c | 183 ++++++++++++++++ arch/riscv/kernel/vdso.c | 125 +++++++++++ arch/riscv/kernel/vdso/.gitignore | 1 + arch/riscv/kernel/vdso/Makefile | 61 ++++++ arch/riscv/kernel/vdso/sigreturn.S | 24 ++ arch/riscv/kernel/vdso/vdso.S | 27 +++ arch/riscv/kernel/vdso/vdso.lds.S | 76 +++++++ arch/riscv/kernel/vmlinux.lds.S | 92 ++++++++ 28 files changed, 3261 insertions(+) create mode 100644 arch/riscv/kernel/.gitignore create mode 100644 arch/riscv/kernel/Makefile create mode 100644 arch/riscv/kernel/asm-offsets.c create mode 100644 arch/riscv/kernel/cacheinfo.c create mode 100644 arch/riscv/kernel/cpu.c create mode 100644 arch/riscv/kernel/entry.S create mode 100644 arch/riscv/kernel/head.S create mode 100644 arch/riscv/kernel/irq.c create mode 100644 arch/riscv/kernel/module.c create mode 100644 arch/riscv/kernel/process.c create mode 100644 arch/riscv/kernel/ptrace.c create mode 100644 arch/riscv/kernel/reset.c create mode 100644 arch/riscv/kernel/riscv_ksyms.c create mode 100644 arch/riscv/kernel/setup.c create mode 100644 arch/riscv/kernel/signal.c create mode 100644 arch/riscv/kernel/smp.c create mode 100644 arch/riscv/kernel/smpboot.c create mode 100644 arch/riscv/kernel/stacktrace.c create mode 100644 arch/riscv/kernel/sys_riscv.c create mode 100644 arch/riscv/kernel/syscall_table.c create mode 100644 arch/riscv/kernel/traps.c create mode 100644 arch/riscv/kernel/vdso.c create mode 100644 arch/riscv/kernel/vdso/.gitignore create mode 100644 arch/riscv/kernel/vdso/Makefile create mode 100644 arch/riscv/kernel/vdso/sigreturn.S create mode 100644 arch/riscv/kernel/vdso/vdso.S create mode 100644 arch/riscv/kernel/vdso/vdso.lds.S create mode 100644 arch/riscv/kernel/vmlinux.lds.S
arch/riscv/kernel/.gitignore new file +1 -0
@@ -0,0 +1 @@ +/vmlinux.lds
arch/riscv/kernel/Makefile new file +16 -0
@@ -0,0 +1,16 @@ +# +# Makefile for the RISC-V Linux kernel +# + +extra-y := head.o vmlinux.lds + +obj-y := cpu.o entry.o irq.o process.o ptrace.o reset.o setup.o \ + signal.o syscall_table.o sys_riscv.o traps.o \ + riscv_ksyms.o stacktrace.o vdso.o cacheinfo.o vdso/ + +CFLAGS_setup.o := -mcmodel=medany + +obj-$(CONFIG_SMP) += smpboot.o smp.o +obj-$(CONFIG_MODULES) += module.o + +clean:
arch/riscv/kernel/asm-offsets.c new file +316 -0
316 lines not on this page · raw message
arch/riscv/kernel/cacheinfo.c new file +103 -0
103 lines not on this page · raw message
arch/riscv/kernel/cpu.c new file +89 -0
89 lines not on this page · raw message
arch/riscv/kernel/entry.S new file +437 -0
437 lines not on this page · raw message
arch/riscv/kernel/head.S new file +147 -0
147 lines not on this page · raw message
arch/riscv/kernel/irq.c new file +20 -0
@@ -0,0 +1,20 @@ +/* +* Copyright (C) 2012 Regents of the University of California +* Copyright (C) 2017 SiFive +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation, version 2. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +*/ + +#include <linux/irqchip.h> + +void __init init_IRQ (void ) +{ +irqchip_init (); +}
arch/riscv/kernel/module.c new file +215 -0
215 lines not on this page · raw message
arch/riscv/kernel/process.c new file +132 -0
132 lines not on this page · raw message
arch/riscv/kernel/ptrace.c new file +147 -0
147 lines not on this page · raw message
arch/riscv/kernel/reset.c new file +36 -0
@@ -0,0 +1,36 @@ +/* +* Copyright (C) 2012 Regents of the University of California +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation, version 2. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +*/ + +#include <linux/reboot.h> +#include <linux/export.h> +#include <asm/sbi.h> + +void (*pm_power_off)(void ) = machine_power_off; +EXPORT_SYMBOL (pm_power_off); + +void machine_restart (char *cmd) +{ +do_kernel_restart (cmd); +while (1 ); +} + +void machine_halt (void ) +{ +machine_power_off (); +} + +void machine_power_off (void ) +{ +sbi_shutdown (); +while (1 ); +}
arch/riscv/kernel/riscv_ksyms.c new file +16 -0
@@ -0,0 +1,16 @@ +/* +* Copyright (C) 2017 Zihao Yu +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation. +*/ + +#include <linux/export.h> +#include <linux/uaccess.h> + +/* +* Assembly functions that may be used (directly or indirectly) by modules +*/ +EXPORT_SYMBOL (__copy_user); +
arch/riscv/kernel/setup.c new file +240 -0
240 lines not on this page · raw message
arch/riscv/kernel/signal.c new file +257 -0
257 lines not on this page · raw message
arch/riscv/kernel/smp.c new file +110 -0
110 lines not on this page · raw message
arch/riscv/kernel/smpboot.c new file +103 -0
103 lines not on this page · raw message
arch/riscv/kernel/stacktrace.c new file +177 -0
177 lines not on this page · raw message
arch/riscv/kernel/sys_riscv.c new file +85 -0
85 lines not on this page · raw message
arch/riscv/kernel/syscall_table.c new file +25 -0
@@ -0,0 +1,25 @@ +/* +* Copyright (C) 2009 Arnd Bergmann <[email protected]> +* Copyright (C) 2012 Regents of the University of California +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation, version 2. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +*/ + +#include <linux/syscalls.h> + +#include <asm/syscalls.h> + +#undef __SYSCALL +#define __SYSCALL (nr, call) [nr] = (call), + +void *sys_call_table[__NR_syscalls] = { + [0 ... __NR_syscalls -1 ] = sys_ni_syscall, +#include <asm/unistd.h> +};
arch/riscv/kernel/traps.c new file +183 -0
183 lines not on this page · raw message
arch/riscv/kernel/vdso.c new file +125 -0
125 lines not on this page · raw message
arch/riscv/kernel/vdso/.gitignore new file +1 -0
@@ -0,0 +1 @@ +vdso.lds
arch/riscv/kernel/vdso/Makefile new file +61 -0
19 lines not on this page · raw message
arch/riscv/kernel/vdso/sigreturn.S new file +24 -0
Lines of this file are not shown. View the raw message.
arch/riscv/kernel/vdso/vdso.S new file +27 -0
Lines of this file are not shown. View the raw message.
arch/riscv/kernel/vdso/vdso.lds.S new file +76 -0
76 lines not on this page · raw message
arch/riscv/kernel/vmlinux.lds.S new file +92 -0
92 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.13.0
Part of the diff is not shown here. View the raw message.
Palmer Dabbelt
maintainerPATCH 16/17 RISC-V: Add kernel subdirectory
In reply to Palmer DabbeltThese files were mostly based on the score port, but many of them are very ISA specific.
--- arch/riscv/kernel/.gitignore | 1 + arch/riscv/kernel/Makefile | 16 ++ arch/riscv/kernel/asm-offsets.c | 316 +++++++++++++++++++++++++++ arch/riscv/kernel/cacheinfo.c | 103 +++++++++ arch/riscv/kernel/cpu.c | 89 ++++++++ arch/riscv/kernel/entry.S | 437 +++++++++++++++++++++++++++++++++++++ arch/riscv/kernel/head.S | 147 +++++++++++++ arch/riscv/kernel/irq.c | 20 ++ arch/riscv/kernel/module.c | 215 ++++++++++++++++++ arch/riscv/kernel/process.c | 132 +++++++++++ arch/riscv/kernel/ptrace.c | 147 +++++++++++++ arch/riscv/kernel/reset.c | 36 +++ arch/riscv/kernel/riscv_ksyms.c | 16 ++ arch/riscv/kernel/setup.c | 240 ++++++++++++++++++++ arch/riscv/kernel/signal.c | 257 ++++++++++++++++++++++ arch/riscv/kernel/smp.c | 110 ++++++++++ arch/riscv/kernel/smpboot.c | 103 +++++++++ arch/riscv/kernel/stacktrace.c | 177 +++++++++++++++ arch/riscv/kernel/sys_riscv.c | 85 ++++++++ arch/riscv/kernel/syscall_table.c | 25 +++ arch/riscv/kernel/traps.c | 183 ++++++++++++++++ arch/riscv/kernel/vdso.c | 125 +++++++++++ arch/riscv/kernel/vdso/.gitignore | 1 + arch/riscv/kernel/vdso/Makefile | 61 ++++++ arch/riscv/kernel/vdso/sigreturn.S | 24 ++ arch/riscv/kernel/vdso/vdso.S | 27 +++ arch/riscv/kernel/vdso/vdso.lds.S | 76 +++++++ arch/riscv/kernel/vmlinux.lds.S | 92 ++++++++ 28 files changed, 3261 insertions(+) create mode 100644 arch/riscv/kernel/.gitignore create mode 100644 arch/riscv/kernel/Makefile create mode 100644 arch/riscv/kernel/asm-offsets.c create mode 100644 arch/riscv/kernel/cacheinfo.c create mode 100644 arch/riscv/kernel/cpu.c create mode 100644 arch/riscv/kernel/entry.S create mode 100644 arch/riscv/kernel/head.S create mode 100644 arch/riscv/kernel/irq.c create mode 100644 arch/riscv/kernel/module.c create mode 100644 arch/riscv/kernel/process.c create mode 100644 arch/riscv/kernel/ptrace.c create mode 100644 arch/riscv/kernel/reset.c create mode 100644 arch/riscv/kernel/riscv_ksyms.c create mode 100644 arch/riscv/kernel/setup.c create mode 100644 arch/riscv/kernel/signal.c create mode 100644 arch/riscv/kernel/smp.c create mode 100644 arch/riscv/kernel/smpboot.c create mode 100644 arch/riscv/kernel/stacktrace.c create mode 100644 arch/riscv/kernel/sys_riscv.c create mode 100644 arch/riscv/kernel/syscall_table.c create mode 100644 arch/riscv/kernel/traps.c create mode 100644 arch/riscv/kernel/vdso.c create mode 100644 arch/riscv/kernel/vdso/.gitignore create mode 100644 arch/riscv/kernel/vdso/Makefile create mode 100644 arch/riscv/kernel/vdso/sigreturn.S create mode 100644 arch/riscv/kernel/vdso/vdso.S create mode 100644 arch/riscv/kernel/vdso/vdso.lds.S create mode 100644 arch/riscv/kernel/vmlinux.lds.S
arch/riscv/kernel/.gitignore new file +1 -0
@@ -0,0 +1 @@ +/vmlinux.lds
arch/riscv/kernel/Makefile new file +16 -0
@@ -0,0 +1,16 @@ +# +# Makefile for the RISC-V Linux kernel +# + +extra-y := head.o vmlinux.lds + +obj-y := cpu.o entry.o irq.o process.o ptrace.o reset.o setup.o \ + signal.o syscall_table.o sys_riscv.o traps.o \ + riscv_ksyms.o stacktrace.o vdso.o cacheinfo.o vdso/ + +CFLAGS_setup.o := -mcmodel=medany + +obj-$(CONFIG_SMP) += smpboot.o smp.o +obj-$(CONFIG_MODULES) += module.o + +clean:
arch/riscv/kernel/asm-offsets.c new file +316 -0
316 lines not on this page · raw message
arch/riscv/kernel/cacheinfo.c new file +103 -0
103 lines not on this page · raw message
arch/riscv/kernel/cpu.c new file +89 -0
89 lines not on this page · raw message
arch/riscv/kernel/entry.S new file +437 -0
437 lines not on this page · raw message
arch/riscv/kernel/head.S new file +147 -0
147 lines not on this page · raw message
arch/riscv/kernel/irq.c new file +20 -0
@@ -0,0 +1,20 @@ +/* +* Copyright (C) 2012 Regents of the University of California +* Copyright (C) 2017 SiFive +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation, version 2. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +*/ + +#include <linux/irqchip.h> + +void __init init_IRQ (void ) +{ +irqchip_init (); +}
arch/riscv/kernel/module.c new file +215 -0
215 lines not on this page · raw message
arch/riscv/kernel/process.c new file +132 -0
132 lines not on this page · raw message
arch/riscv/kernel/ptrace.c new file +147 -0
147 lines not on this page · raw message
arch/riscv/kernel/reset.c new file +36 -0
@@ -0,0 +1,36 @@ +/* +* Copyright (C) 2012 Regents of the University of California +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation, version 2. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +*/ + +#include <linux/reboot.h> +#include <linux/export.h> +#include <asm/sbi.h> + +void (*pm_power_off)(void ) = machine_power_off; +EXPORT_SYMBOL (pm_power_off); + +void machine_restart (char *cmd) +{ +do_kernel_restart (cmd); +while (1 ); +} + +void machine_halt (void ) +{ +machine_power_off (); +} + +void machine_power_off (void ) +{ +sbi_shutdown (); +while (1 ); +}
arch/riscv/kernel/riscv_ksyms.c new file +16 -0
@@ -0,0 +1,16 @@ +/* +* Copyright (C) 2017 Zihao Yu +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation. +*/ + +#include <linux/export.h> +#include <linux/uaccess.h> + +/* +* Assembly functions that may be used (directly or indirectly) by modules +*/ +EXPORT_SYMBOL (__copy_user); +
arch/riscv/kernel/setup.c new file +240 -0
240 lines not on this page · raw message
arch/riscv/kernel/signal.c new file +257 -0
257 lines not on this page · raw message
arch/riscv/kernel/smp.c new file +110 -0
110 lines not on this page · raw message
arch/riscv/kernel/smpboot.c new file +103 -0
103 lines not on this page · raw message
arch/riscv/kernel/stacktrace.c new file +177 -0
177 lines not on this page · raw message
arch/riscv/kernel/sys_riscv.c new file +85 -0
85 lines not on this page · raw message
arch/riscv/kernel/syscall_table.c new file +25 -0
@@ -0,0 +1,25 @@ +/* +* Copyright (C) 2009 Arnd Bergmann <[email protected]> +* Copyright (C) 2012 Regents of the University of California +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation, version 2. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +*/ + +#include <linux/syscalls.h> + +#include <asm/syscalls.h> + +#undef __SYSCALL +#define __SYSCALL (nr, call) [nr] = (call), + +void *sys_call_table[__NR_syscalls] = { + [0 ... __NR_syscalls -1 ] = sys_ni_syscall, +#include <asm/unistd.h> +};
arch/riscv/kernel/traps.c new file +183 -0
183 lines not on this page · raw message
arch/riscv/kernel/vdso.c new file +125 -0
125 lines not on this page · raw message
arch/riscv/kernel/vdso/.gitignore new file +1 -0
@@ -0,0 +1 @@ +vdso.lds
arch/riscv/kernel/vdso/Makefile new file +61 -0
19 lines not on this page · raw message
arch/riscv/kernel/vdso/sigreturn.S new file +24 -0
Lines of this file are not shown. View the raw message.
arch/riscv/kernel/vdso/vdso.S new file +27 -0
Lines of this file are not shown. View the raw message.
arch/riscv/kernel/vdso/vdso.lds.S new file +76 -0
76 lines not on this page · raw message
arch/riscv/kernel/vmlinux.lds.S new file +92 -0
92 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.13.0
Part of the diff is not shown here. View the raw message.
Palmer Dabbelt
maintainerPATCH 17/17 RISC-V: Makefile and Kconfig
In reply to Palmer DabbeltThis patch adds RISC-V support to the build infastructure.
--- Makefile | 3 +- arch/riscv/Kconfig | 318 ++++++++++++++++++++++++++++++ arch/riscv/Makefile | 64 ++++++ arch/riscv/configs/freedom-u500_defconfig | 53 +++++ arch/riscv/configs/spike32_defconfig | 50 +++++ arch/riscv/configs/spike64_defconfig | 46 +++++ 6 files changed, 533 insertions(+), 1 deletion(-) create mode 100644 arch/riscv/Kconfig create mode 100644 arch/riscv/Makefile create mode 100644 arch/riscv/configs/freedom-u500_defconfig create mode 100644 arch/riscv/configs/spike32_defconfig create mode 100644 arch/riscv/configs/spike64_defconfig
Makefile +2 -1
@@ -232,7 +232,8 @@ SUBARCH := $(shell uname -m | sed -e s/i.86/x86/ -e s/x86_64/x86/ \ -e s/arm.*/arm/ -e s/sa110/arm/ \ -e s/s390x/s390/ -e s/parisc64/parisc/ \ -e s/ppc.*/powerpc/ -e s/mips.*/mips/ \ - -e s/sh[234].*/sh/ -e s/aarch64.*/arm64/ ) + -e s/sh[234].*/sh/ -e s/aarch64.*/arm64/ \ + -e s/riscv.*/riscv/) # Cross compiling and selecting different set of gcc/bin-utils # ---------------------------------------------------------------------------
arch/riscv/Kconfig new file +318 -0
318 lines not on this page · raw message
arch/riscv/Makefile new file +64 -0
64 lines not on this page · raw message
arch/riscv/configs/freedom-u500_defconfig new file +53 -0
53 lines not on this page · raw message
arch/riscv/configs/spike32_defconfig new file +50 -0
50 lines not on this page · raw message
arch/riscv/configs/spike64_defconfig new file +46 -0
46 lines not on this page · raw message
Signature · 1 line
2.13.0
Palmer Dabbelt
maintainerPATCH 17/17 RISC-V: Makefile and Kconfig
In reply to Palmer DabbeltThis patch adds RISC-V support to the build infastructure.
--- Makefile | 3 +- arch/riscv/Kconfig | 318 ++++++++++++++++++++++++++++++ arch/riscv/Makefile | 64 ++++++ arch/riscv/configs/freedom-u500_defconfig | 53 +++++ arch/riscv/configs/spike32_defconfig | 50 +++++ arch/riscv/configs/spike64_defconfig | 46 +++++ 6 files changed, 533 insertions(+), 1 deletion(-) create mode 100644 arch/riscv/Kconfig create mode 100644 arch/riscv/Makefile create mode 100644 arch/riscv/configs/freedom-u500_defconfig create mode 100644 arch/riscv/configs/spike32_defconfig create mode 100644 arch/riscv/configs/spike64_defconfig
Makefile +2 -1
@@ -232,7 +232,8 @@ SUBARCH := $(shell uname -m | sed -e s/i.86/x86/ -e s/x86_64/x86/ \ -e s/arm.*/arm/ -e s/sa110/arm/ \ -e s/s390x/s390/ -e s/parisc64/parisc/ \ -e s/ppc.*/powerpc/ -e s/mips.*/mips/ \ - -e s/sh[234].*/sh/ -e s/aarch64.*/arm64/ ) + -e s/sh[234].*/sh/ -e s/aarch64.*/arm64/ \ + -e s/riscv.*/riscv/) # Cross compiling and selecting different set of gcc/bin-utils # ---------------------------------------------------------------------------
arch/riscv/Kconfig new file +318 -0
318 lines not on this page · raw message
arch/riscv/Makefile new file +64 -0
64 lines not on this page · raw message
arch/riscv/configs/freedom-u500_defconfig new file +53 -0
53 lines not on this page · raw message
arch/riscv/configs/spike32_defconfig new file +50 -0
50 lines not on this page · raw message
arch/riscv/configs/spike64_defconfig new file +46 -0
46 lines not on this page · raw message
Signature · 1 line
2.13.0
David Howells
maintainerRe: RISC-V Linux Port v2
In reply to Palmer DabbeltWhat's the target type for building cross-binutils and cross-gcc for it?
David
Palmer Dabbelt
maintainerRe: RISC-V Linux Port v2
Quoted 1 line · On Wed, 07 Jun 2017 00:29:44 PDT (-0700), [email protected] wrote:
What's the target type for building cross-binutils and cross-gcc for it?
riscv64-unknown-linux-gnu
We have a super-repo that scripts the build, and includes a handful of patches that fix GCC and binutils bugs that are in our first releases.
Re: RISC-V Linux Port v2
In reply to Palmer DabbeltHi Palmer,
Quoted 4 lines · Palmer Dabbelt
Thanks to everyone who has participated in the review process so far. We've made a lot of changes since the v1 and while this isn't ready to go yet, I finally managed to get through everything in my inbox so I thought it would be a good time to submit a v2 so everyone is on the same page.
[...]
Quoted 1 line
[PATCH 13/17] RISC-V: Add include subdirectory
This guy is too big, and got silently dropped by the mailing list. Any chance you could split it up please, so that it can be reviewed?
Thanks,
Will
Palmer Dabbelt
maintainerRe: RISC-V Linux Port v2
Quoted 8 lines · On Wed, 07 Jun 2017 02:23:42 PDT (-0700), [email protected] wrote:
Hi Palmer,
Quoted 4 lines · Palmer Dabbelt
Thanks to everyone who has participated in the review process so far. We've made a lot of changes since the v1 and while this isn't ready to go yet, I finally managed to get through everything in my inbox so I thought it would be a good time to submit a v2 so everyone is on the same page.
Quoted 6 lines
[...]
Quoted 1 line
[PATCH 13/17] RISC-V: Add include subdirectory
This guy is too big, and got silently dropped by the mailing list. Any chance you could split it up please, so that it can be reviewed?
Sorry about that. It's online
https://github.com/riscv/riscv-linux/commit/daaea1609cb5e8c93745c1ce112a06e90f5b663c
I'll be sure to split it up next time. I can submit a v3 if you want?
Re: RISC-V Linux Port v2
Quoted 13 lines · Palmer Dabbelt
Quoted 12 lines · On Wed, 07 Jun 2017 02:23:42 PDT (-0700), [email protected] wrote:
Hi Palmer,
Quoted 4 lines · Palmer Dabbelt
Thanks to everyone who has participated in the review process so far. We've made a lot of changes since the v1 and while this isn't ready to go yet, I finally managed to get through everything in my inbox so I thought it would be a good time to submit a v2 so everyone is on the same page.
[...]
Quoted 1 line
[PATCH 13/17] RISC-V: Add include subdirectory
Quoted 8 lines
Quoted 2 lines
This guy is too big, and got silently dropped by the mailing list. Any chance you could split it up please, so that it can be reviewed?
Sorry about that. It's online
https://github.com/riscv/riscv-linux/commit/daaea1609cb5e8c93745c1ce112a06e90f5b663c
I'll be sure to split it up next time. I can submit a v3 if you want?
It looks like you'll be submitting a v3 anyway, so if you could split it up for that then it would be much appreciated.
Thanks,
Will
Palmer Dabbelt
maintainerRe: RISC-V Linux Port v2
Quoted 17 lines · On Thu, 08 Jun 2017 03:26:32 PDT (-0700), [email protected] wrote:
Quoted 16 lines · Palmer Dabbelt
Quoted 14 lines · On Wed, 07 Jun 2017 02:23:42 PDT (-0700), [email protected] wrote:
Hi Palmer,
Quoted 4 lines · Palmer Dabbelt
Thanks to everyone who has participated in the review process so far. We've made a lot of changes since the v1 and while this isn't ready to go yet, I finally managed to get through everything in my inbox so I thought it would be a good time to submit a v2 so everyone is on the same page.
[...]
Quoted 1 line
[PATCH 13/17] RISC-V: Add include subdirectory
This guy is too big, and got silently dropped by the mailing list. Any chance you could split it up please, so that it can be reviewed?
Quoted 8 lines
Quoted 5 lines
Sorry about that. It's online
https://github.com/riscv/riscv-linux/commit/daaea1609cb5e8c93745c1ce112a06e90f5b663c
I'll be sure to split it up next time. I can submit a v3 if you want?
It looks like you'll be submitting a v3 anyway, so if you could split it up for that then it would be much appreciated.
Sounds good. I won't spin a v3 just for this problem, as there's a lot of other comments I need to go through.
Palmer Dabbelt
maintainerRISC-V Linux Port v3
In reply to Palmer DabbeltThanks to everyone who has particpated in the review process so far. We've made a handful of changes since the v2 port, and at this point aside from a handful of FIXMEs floating around the code I don't think there's anything left I know about that's still missing for a minimal port. I believe I've addressed every review comment so far, if I've missed yours then I'm sorry but I'd like to request you resend it.
A highlight of the changes since the v1 patch set includes:
* We've split out all our drivers into separate patch sets, which I've already sent out to the relevant maintainers. I haven't included those patches in this patch set, but some of them are necessary to build our port. A git tree that contains all our patch sets merged together lives at
<https://github.com/riscv/riscv-linux/tree/riscv-for-submission-v3>.
* The patch set is now split up differently: rather than being split per directory it is split per topic. Hopefully this will make it easier to review the port on the mailing list. The split is a bit rough, so you probably still want to look at the patch set as a whole.
* atomic.h has been completely rewritten and is hopefully now correct. I've attempted to sanitize the various other memory model related code as well, and I think it should all be sane now aside from a handful of FIXMEs commented in the code.
* We've changed the cmpexchg syscall to always exist and to not be multiplexed. There is also a VDSO entry for compare and exchange, which allows kernels with the A extension to execute user code without the A extension reasonably fast.
* Our user-visible register state now contains enough space for the Q extension for 128-bit floating point, as well as a few words to allow extensibility to future ISA extensions like the eventual V extension for vectors.
* A handful of driver cleanups, but these have been split into separate patch sets now so I won't duplicate them here.
The full list of patches is below
[PATCH 1/9] RISC-V: Init and Halt Code
[PATCH 2/9] RISC-V: Atomic and Locking Code [PATCH 3/9] RISC-V: Generic library routines and assembly [PATCH 4/9] RISC-V: ELF and module implementation [PATCH 5/9] RISC-V: Task implementation
[PATCH 6/9] RISC-V: Device, timer, IRQs, and the SBI [PATCH 7/9] RISC-V: Paging and MMU
[PATCH 8/9] RISC-V: User-facing API
[PATCH 9/9] RISC-V: Build Infastructure
In case one gets eaten by the mailing list, this is also availiable as a git tree on our Git Hub
https://github.com/riscv/riscv-linux/tree/riscv-for-submission-arch-v3
This patch set just contains the arch code, we have various drivers that are required to build and boot a RISC-V system. A tree that contains this patch set merged with all our other patch sets lives at
https://github.com/riscv/riscv-linux/tree/riscv-for-submission-v3
commit 319a127e0685ed294996e0e6b25b229f42ec1d6e
Merge: a980edd4a4b7 e67734c51bc9
Author: Palmer Dabbelt <[email protected]>
Date: Wed Jun 28 10:45:14 2017 -0700
Merge branch 'riscv-for-submission-arch-v3' into riscv-for-submission-v3
If you're going to try to build or boot the kernel, I'd recommend using that.
Thanks to everyone who has helped review our port!
Palmer Dabbelt
maintainerPATCH 1/9 RISC-V: Init and Halt Code
This contains the various __init C functions, the initial assembly kernel entry point, and the code to reset the system. When a file was init-related, it contains
--- arch/riscv/include/asm/bug.h | 88 +++++++++++++++ arch/riscv/include/asm/cache.h | 22 ++++ arch/riscv/include/asm/smp.h | 41 +++++++ arch/riscv/kernel/cacheinfo.c | 105 ++++++++++++++++++ arch/riscv/kernel/cpu.c | 89 +++++++++++++++ arch/riscv/kernel/head.S | 147 +++++++++++++++++++++++++ arch/riscv/kernel/irq.c | 20 ++++ arch/riscv/kernel/reset.c | 36 +++++++ arch/riscv/kernel/setup.c | 240 +++++++++++++++++++++++++++++++++++++++++ arch/riscv/kernel/smp.c | 110 +++++++++++++++++++ arch/riscv/kernel/smpboot.c | 103 ++++++++++++++++++ arch/riscv/kernel/time.c | 61 +++++++++++ arch/riscv/kernel/traps.c | 183 +++++++++++++++++++++++++++++++ arch/riscv/kernel/vdso.c | 125 +++++++++++++++++++++ arch/riscv/mm/init.c | 70 ++++++++++++ 15 files changed, 1440 insertions(+) create mode 100644 arch/riscv/include/asm/bug.h create mode 100644 arch/riscv/include/asm/cache.h create mode 100644 arch/riscv/include/asm/smp.h create mode 100644 arch/riscv/kernel/cacheinfo.c create mode 100644 arch/riscv/kernel/cpu.c create mode 100644 arch/riscv/kernel/head.S create mode 100644 arch/riscv/kernel/irq.c create mode 100644 arch/riscv/kernel/reset.c create mode 100644 arch/riscv/kernel/setup.c create mode 100644 arch/riscv/kernel/smp.c create mode 100644 arch/riscv/kernel/smpboot.c create mode 100644 arch/riscv/kernel/time.c create mode 100644 arch/riscv/kernel/traps.c create mode 100644 arch/riscv/kernel/vdso.c create mode 100644 arch/riscv/mm/init.c
arch/riscv/include/asm/bug.h new file +88 -0
@@ -0,0 +1,88 @@ +/* +* Copyright (C) 2012 Regents of the University of California +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation, version 2. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +*/ + +#ifndef _ASM_RISCV_BUG_H +#define _ASM_RISCV_BUG_H + +#include <linux/compiler.h> +#include <linux/const.h> +#include <linux/types.h> + +#include <asm/asm.h> + +#ifdef CONFIG_GENERIC_BUG +#define __BUG_INSN _AC(0x00100073, UL)/* sbreak */ + +#ifndef __ASSEMBLY__ +typedef u32 bug_insn_t ; + +#ifdef CONFIG_GENERIC_BUG_RELATIVE_POINTERS +#define __BUG_ENTRY_ADDR INT " 1b - 2b" +#define __BUG_ENTRY_FILE INT " %0 - 2b" +#else +#define __BUG_ENTRY_ADDR RISCV_PTR " 1b" +#define __BUG_ENTRY_FILE RISCV_PTR " %0" +#endif + +#ifdef CONFIG_DEBUG_BUGVERBOSE +#define __BUG_ENTRY \ + __BUG_ENTRY_ADDR "\n\t" \ + __BUG_ENTRY_FILE "\n\t" \ + SHORT " %1" +#else +#define __BUG_ENTRY \ + __BUG_ENTRY_ADDR +#endif + +#define BUG () \ +do { \ + __asm__ __volatile__ ( \ + "1:\n\t" \ + "sbreak\n" \ + ".pushsection __bug_table,\"a\"\n\t" \ + "2:\n\t" \ + __BUG_ENTRY "\n\t" \ + ".org 2b + %2\n\t" \ + ".popsection" \ + : \ + : "i" (__FILE__), "i" (__LINE__), \ + "i" (sizeof(struct bug_entry))); \ + unreachable(); \ +} while (0) +#endif /* !__ASSEMBLY__ */ +#else /* CONFIG_GENERIC_BUG */ +#ifndef __ASSEMBLY__ +#define BUG () \ +do { \ + __asm__ __volatile__ ("sbreak\n"); \ + unreachable(); \ +} while (0) +#endif /* !__ASSEMBLY__ */ +#endif /* CONFIG_GENERIC_BUG */ + +#define HAVE_ARCH_BUG + +#include <asm-generic/bug.h> + +#ifndef __ASSEMBLY__ + +struct pt_regs ; +struct task_struct ; + +extern void die (struct pt_regs *regs,const char *str); +extern void do_trap (struct pt_regs *regs,int signo,int code, +unsigned long addr,struct task_struct *tsk); + +#endif /* !__ASSEMBLY__ */ + +#endif /* _ASM_RISCV_BUG_H */
arch/riscv/include/asm/cache.h new file +22 -0
@@ -0,0 +1,22 @@ +/* +* Copyright (C) 2017 Chen Liqin <[email protected]> +* Copyright (C) 2012 Regents of the University of California +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation, version 2. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +*/ + +#ifndef _ASM_RISCV_CACHE_H +#define _ASM_RISCV_CACHE_H + +#define L1_CACHE_SHIFT 6 + +#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT) + +#endif /* _ASM_RISCV_CACHE_H */
arch/riscv/include/asm/smp.h new file +41 -0
41 lines not on this page · raw message
arch/riscv/kernel/cacheinfo.c new file +105 -0
105 lines not on this page · raw message
arch/riscv/kernel/cpu.c new file +89 -0
89 lines not on this page · raw message
arch/riscv/kernel/head.S new file +147 -0
147 lines not on this page · raw message
arch/riscv/kernel/irq.c new file +20 -0
@@ -0,0 +1,20 @@ +/* +* Copyright (C) 2012 Regents of the University of California +* Copyright (C) 2017 SiFive +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation, version 2. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +*/ + +#include <linux/irqchip.h> + +void __init init_IRQ (void ) +{ +irqchip_init (); +}
arch/riscv/kernel/reset.c new file +36 -0
@@ -0,0 +1,36 @@ +/* +* Copyright (C) 2012 Regents of the University of California +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation, version 2. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +*/ + +#include <linux/reboot.h> +#include <linux/export.h> +#include <asm/sbi.h> + +void (*pm_power_off)(void ) = machine_power_off; +EXPORT_SYMBOL (pm_power_off); + +void machine_restart (char *cmd) +{ +do_kernel_restart (cmd); +while (1 ); +} + +void machine_halt (void ) +{ +machine_power_off (); +} + +void machine_power_off (void ) +{ +sbi_shutdown (); +while (1 ); +}
arch/riscv/kernel/setup.c new file +240 -0
240 lines not on this page · raw message
arch/riscv/kernel/smp.c new file +110 -0
110 lines not on this page · raw message
arch/riscv/kernel/smpboot.c new file +103 -0
103 lines not on this page · raw message
arch/riscv/kernel/time.c new file +61 -0
61 lines not on this page · raw message
arch/riscv/kernel/traps.c new file +183 -0
183 lines not on this page · raw message
arch/riscv/kernel/vdso.c new file +125 -0
125 lines not on this page · raw message
arch/riscv/mm/init.c new file +70 -0
70 lines not on this page · raw message
Signature · 1 line
2.13.0
Palmer Dabbelt
maintainerPATCH 1/9 RISC-V: Init and Halt Code
In reply to Palmer DabbeltThis contains the various __init C functions, the initial assembly kernel entry point, and the code to reset the system. When a file was init-related, it contains
--- arch/riscv/include/asm/bug.h | 88 +++++++++++++++ arch/riscv/include/asm/cache.h | 22 ++++ arch/riscv/include/asm/smp.h | 41 +++++++ arch/riscv/kernel/cacheinfo.c | 105 ++++++++++++++++++ arch/riscv/kernel/cpu.c | 89 +++++++++++++++ arch/riscv/kernel/head.S | 147 +++++++++++++++++++++++++ arch/riscv/kernel/irq.c | 20 ++++ arch/riscv/kernel/reset.c | 36 +++++++ arch/riscv/kernel/setup.c | 240 +++++++++++++++++++++++++++++++++++++++++ arch/riscv/kernel/smp.c | 110 +++++++++++++++++++ arch/riscv/kernel/smpboot.c | 103 ++++++++++++++++++ arch/riscv/kernel/time.c | 61 +++++++++++ arch/riscv/kernel/traps.c | 183 +++++++++++++++++++++++++++++++ arch/riscv/kernel/vdso.c | 125 +++++++++++++++++++++ arch/riscv/mm/init.c | 70 ++++++++++++ 15 files changed, 1440 insertions(+) create mode 100644 arch/riscv/include/asm/bug.h create mode 100644 arch/riscv/include/asm/cache.h create mode 100644 arch/riscv/include/asm/smp.h create mode 100644 arch/riscv/kernel/cacheinfo.c create mode 100644 arch/riscv/kernel/cpu.c create mode 100644 arch/riscv/kernel/head.S create mode 100644 arch/riscv/kernel/irq.c create mode 100644 arch/riscv/kernel/reset.c create mode 100644 arch/riscv/kernel/setup.c create mode 100644 arch/riscv/kernel/smp.c create mode 100644 arch/riscv/kernel/smpboot.c create mode 100644 arch/riscv/kernel/time.c create mode 100644 arch/riscv/kernel/traps.c create mode 100644 arch/riscv/kernel/vdso.c create mode 100644 arch/riscv/mm/init.c
arch/riscv/include/asm/bug.h new file +88 -0
@@ -0,0 +1,88 @@ +/* +* Copyright (C) 2012 Regents of the University of California +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation, version 2. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +*/ + +#ifndef _ASM_RISCV_BUG_H +#define _ASM_RISCV_BUG_H + +#include <linux/compiler.h> +#include <linux/const.h> +#include <linux/types.h> + +#include <asm/asm.h> + +#ifdef CONFIG_GENERIC_BUG +#define __BUG_INSN _AC(0x00100073, UL)/* sbreak */ + +#ifndef __ASSEMBLY__ +typedef u32 bug_insn_t ; + +#ifdef CONFIG_GENERIC_BUG_RELATIVE_POINTERS +#define __BUG_ENTRY_ADDR INT " 1b - 2b" +#define __BUG_ENTRY_FILE INT " %0 - 2b" +#else +#define __BUG_ENTRY_ADDR RISCV_PTR " 1b" +#define __BUG_ENTRY_FILE RISCV_PTR " %0" +#endif + +#ifdef CONFIG_DEBUG_BUGVERBOSE +#define __BUG_ENTRY \ + __BUG_ENTRY_ADDR "\n\t" \ + __BUG_ENTRY_FILE "\n\t" \ + SHORT " %1" +#else +#define __BUG_ENTRY \ + __BUG_ENTRY_ADDR +#endif + +#define BUG () \ +do { \ + __asm__ __volatile__ ( \ + "1:\n\t" \ + "sbreak\n" \ + ".pushsection __bug_table,\"a\"\n\t" \ + "2:\n\t" \ + __BUG_ENTRY "\n\t" \ + ".org 2b + %2\n\t" \ + ".popsection" \ + : \ + : "i" (__FILE__), "i" (__LINE__), \ + "i" (sizeof(struct bug_entry))); \ + unreachable(); \ +} while (0) +#endif /* !__ASSEMBLY__ */ +#else /* CONFIG_GENERIC_BUG */ +#ifndef __ASSEMBLY__ +#define BUG () \ +do { \ + __asm__ __volatile__ ("sbreak\n"); \ + unreachable(); \ +} while (0) +#endif /* !__ASSEMBLY__ */ +#endif /* CONFIG_GENERIC_BUG */ + +#define HAVE_ARCH_BUG + +#include <asm-generic/bug.h> + +#ifndef __ASSEMBLY__ + +struct pt_regs ; +struct task_struct ; + +extern void die (struct pt_regs *regs,const char *str); +extern void do_trap (struct pt_regs *regs,int signo,int code, +unsigned long addr,struct task_struct *tsk); + +#endif /* !__ASSEMBLY__ */ + +#endif /* _ASM_RISCV_BUG_H */
arch/riscv/include/asm/cache.h new file +22 -0
@@ -0,0 +1,22 @@ +/* +* Copyright (C) 2017 Chen Liqin <[email protected]> +* Copyright (C) 2012 Regents of the University of California +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation, version 2. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +*/ + +#ifndef _ASM_RISCV_CACHE_H +#define _ASM_RISCV_CACHE_H + +#define L1_CACHE_SHIFT 6 + +#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT) + +#endif /* _ASM_RISCV_CACHE_H */
arch/riscv/include/asm/smp.h new file +41 -0
41 lines not on this page · raw message
arch/riscv/kernel/cacheinfo.c new file +105 -0
105 lines not on this page · raw message
arch/riscv/kernel/cpu.c new file +89 -0
89 lines not on this page · raw message
arch/riscv/kernel/head.S new file +147 -0
147 lines not on this page · raw message
arch/riscv/kernel/irq.c new file +20 -0
@@ -0,0 +1,20 @@ +/* +* Copyright (C) 2012 Regents of the University of California +* Copyright (C) 2017 SiFive +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation, version 2. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +*/ + +#include <linux/irqchip.h> + +void __init init_IRQ (void ) +{ +irqchip_init (); +}
arch/riscv/kernel/reset.c new file +36 -0
@@ -0,0 +1,36 @@ +/* +* Copyright (C) 2012 Regents of the University of California +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation, version 2. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +*/ + +#include <linux/reboot.h> +#include <linux/export.h> +#include <asm/sbi.h> + +void (*pm_power_off)(void ) = machine_power_off; +EXPORT_SYMBOL (pm_power_off); + +void machine_restart (char *cmd) +{ +do_kernel_restart (cmd); +while (1 ); +} + +void machine_halt (void ) +{ +machine_power_off (); +} + +void machine_power_off (void ) +{ +sbi_shutdown (); +while (1 ); +}
arch/riscv/kernel/setup.c new file +240 -0
240 lines not on this page · raw message
arch/riscv/kernel/smp.c new file +110 -0
110 lines not on this page · raw message
arch/riscv/kernel/smpboot.c new file +103 -0
103 lines not on this page · raw message
arch/riscv/kernel/time.c new file +61 -0
61 lines not on this page · raw message
arch/riscv/kernel/traps.c new file +183 -0
183 lines not on this page · raw message
arch/riscv/kernel/vdso.c new file +125 -0
125 lines not on this page · raw message
arch/riscv/mm/init.c new file +70 -0
70 lines not on this page · raw message
Signature · 1 line
2.13.0
Re: [PATCH 1/9] RISC-V: Init and Halt Code
Hi Palmer,
Quoted 3 lines · Palmer Dabbelt
This contains the various
__initC functions, the initial assembly kernel entry point, and the code to reset the system. When a file was init-related, it contains
...?
Quoted 1 line
Signed-off-by Palmer Dabbelt <[email protected]>
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]
In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds
Palmer Dabbelt
maintainerRe: [PATCH 1/9] RISC-V: Init and Halt Code
Quoted 8 lines · On Thu, 29 Jun 2017 02:44:32 PDT (-0700), [email protected] wrote:
Hi Palmer,
Quoted 3 lines · Palmer Dabbelt
This contains the various
__initC functions, the initial assembly kernel entry point, and the code to reset the system. When a file was init-related, it contains...?
Whoops. I'm not even sure how to make a sentence out of that -- I guess I've been mangling too many patch sets...
I'll try and be coherent next time :).
Quoted 6 lines
Quoted 2 lines
Signed-off-by Palmer Dabbelt <[email protected]>Gr{oetje,eeting}s,
Geert
Palmer Dabbelt
maintainerPATCH 2/9 RISC-V: Atomic and Locking Code
In reply to Palmer DabbeltThis contains all the code that directly interfaces with the RISC-V memory model. While this code corforms to the current RISC-V ISA specifications (user 2.2 and priv 1.10), the memory model is somewhat underspecified in those documents. There is a working group that hopes to produce a formal memory model by the end of the year, but my understanding is that the basic definitions we're relying on here won't change significantly.
--- arch/riscv/include/asm/atomic.h | 330 ++++++++++++++++++++++++++++++++ arch/riscv/include/asm/barrier.h | 139 ++++++++++++++ arch/riscv/include/asm/bitops.h | 228 ++++++++++++++++++++++ arch/riscv/include/asm/cacheflush.h | 39 ++++ arch/riscv/include/asm/cmpxchg.h | 138 +++++++++++++ arch/riscv/include/asm/io.h | 178 +++++++++++++++++ arch/riscv/include/asm/spinlock.h | 167 ++++++++++++++++ arch/riscv/include/asm/spinlock_types.h | 33 ++++ arch/riscv/include/asm/tlb.h | 24 +++ arch/riscv/include/asm/tlbflush.h | 64 +++++++ 10 files changed, 1340 insertions(+) create mode 100644 arch/riscv/include/asm/atomic.h create mode 100644 arch/riscv/include/asm/barrier.h create mode 100644 arch/riscv/include/asm/bitops.h create mode 100644 arch/riscv/include/asm/cacheflush.h create mode 100644 arch/riscv/include/asm/cmpxchg.h create mode 100644 arch/riscv/include/asm/io.h create mode 100644 arch/riscv/include/asm/spinlock.h create mode 100644 arch/riscv/include/asm/spinlock_types.h create mode 100644 arch/riscv/include/asm/tlb.h create mode 100644 arch/riscv/include/asm/tlbflush.h
arch/riscv/include/asm/atomic.h new file +330 -0
@@ -0,0 +1,330 @@ +/* +* Copyright (C) 2007 Red Hat, Inc. All Rights Reserved. +* Copyright (C) 2012 Regents of the University of California +* Copyright (C) 2017 SiFive +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public Licence +* as published by the Free Software Foundation; either version +* 2 of the Licence, or (at your option) any later version. +*/ + +#ifndef _ASM_RISCV_ATOMIC_H +#define _ASM_RISCV_ATOMIC_H + +#ifdef CONFIG_GENERIC_ATOMIC64 +# include <asm-generic/atomic64.h> +#else +# if (__riscv_xlen <64 ) +# error "64-bit atomics require XLEN to be at least 64" +# endif +#endif + +#ifdef CONFIG_ISA_A + +#include <asm/cmpxchg.h> +#include <asm/barrier.h> + +#define ATOMIC_INIT (i) { (i) } +static __always_inline int atomic_read(const atomic_t *v) +{ +return READ_ONCE (v->counter); +} +static __always_inline void atomic_set(atomic_t *v, int i) +{ +WRITE_ONCE (v->counter, i); +} + +#ifndef CONFIG_GENERIC_ATOMIC64 +#define ATOMIC64_INIT (i) { (i) } +static __always_inline int atomic64_read(const atomic64_t *v) +{ +return READ_ONCE (v->counter); +} +static __always_inline void atomic64_set(atomic64_t *v, int i) +{ +WRITE_ONCE (v->counter, i); +} +#endif + +/* First, the atomic ops that have no ordering constraints and therefor don't +* have the AQ or RL bits set. These don't return anything, so there's only +* one version to worry about. +*/ +#define ATOMIC_OP (op, asm_op, c_op,I , asm_type, c_type, prefix) \ +static __always_inline void atomic##prefix##_##op(c_type i, atomic##prefix##_t *v) \ +{ \ + __asm__ __volatile__ ( \ + "amo" #asm_op "." #asm_type " zero, %1, %0" \ + : "+A" (v->counter) \ + : "r" (I)); \ +} + +#ifdef CONFIG_GENERIC_ATOMIC64 +#define ATOMIC_OPS (op, asm_op, c_op,I ) \ + ATOMIC_OP (op, asm_op, c_op, I, w, int, ) +#else +#define ATOMIC_OPS (op, asm_op, c_op,I ) \ + ATOMIC_OP (op, asm_op, c_op, I, w, int, ) \ + ATOMIC_OP (op, asm_op, c_op, I, d, long, 64) +#endif + +ATOMIC_OPS(add, add, +, i) +ATOMIC_OPS(sub, add, +, -i) +/* FIXME: I could only find documentation that atomic_{add,sub,inc,dec} are +* barrier-free. I'm assuming that and/or/xor have the same constraints as the +* others. + */ +ATOMIC_OPS(and, and, &, i) +ATOMIC_OPS( or, or, |, i) +ATOMIC_OPS(xor, xor, ^, i) + +#undef ATOMIC_OP +#undef ATOMIC_OPS + +/* Atomic ops that have ordered, relaxed, acquire, and relese variants. +* There's two flavors of these: the arithmatic ops have both fetch and return +* versions, while the logical ops only have fetch versions. */ +#define ATOMIC_FETCH_OP (op, asm_op, c_op,I , asm_or, c_or, asm_type, c_type, prefix) \ +static __always_inline c_type atomic##prefix##_fetch_##op##c_or(c_type i, atomic##prefix##_t *v) \ +{ \ + register c_type ret; \ + __asm__ __volatile__ ( \ + "amo" #asm_op "." #asm_type #asm_or " %2, %1, %0" \ + : "+A" (v->counter), "=r" (ret) \ + : "r" (I)); \ + return ret; \ +} + +#define ATOMIC_OP_RETURN (op, asm_op, c_op,I , asm_or, c_or, asm_type, c_type, prefix) \ +static __always_inline c_type atomic##prefix##_##op##_return##c_or(int i, atomic##prefix##_t *v) \ +{ \ + return atomic##prefix##_fetch_##op##c_or(i, v) c_op I; \ +} + +#ifdef CONFIG_GENERIC_ATOMIC64 +#define ATOMIC_OPS (op, asm_op, c_op,I , asm_or, c_or) \ + ATOMIC_FETCH_OP (op, asm_op, c_op, I, asm_or, c_or, w, int, ) \ + ATOMIC_OP_RETURN(op, asm_op, c_op, I, asm_or, c_or, w, int, ) +#else +#define ATOMIC_OPS (op, asm_op, c_op,I , asm_or, c_or) \ + ATOMIC_FETCH_OP (op, asm_op, c_op, I, asm_or, c_or, w, int, ) \ + ATOMIC_OP_RETURN(op, asm_op, c_op, I, asm_or, c_or, w, int, ) \ + ATOMIC_FETCH_OP (op, asm_op, c_op, I, asm_or, c_or, d, long, 64) \ + ATOMIC_OP_RETURN(op, asm_op, c_op, I, asm_or, c_or, d, long, 64) +#endif + +ATOMIC_OPS(add, add, +, i, , _relaxed) +ATOMIC_OPS(add, add, +, i, .aq , _acquire) +ATOMIC_OPS(add, add, +, i, .rl , _release) +ATOMIC_OPS(add, add, +, i, .aqrl, ) + +ATOMIC_OPS(sub, add, +, -i, , _relaxed) +ATOMIC_OPS(sub, add, +, -i, .aq , _acquire) +ATOMIC_OPS(sub, add, +, -i, .rl , _release) +ATOMIC_OPS(sub, add, +, -i, .aqrl, ) + +#undef ATOMIC_OPS + +#ifdef CONFIG_GENERIC_ATOMIC64 +#define ATOMIC_OPS(op, asm_op, c_op, I, asm_or, c_or) \ + ATOMIC_FETCH_OP(op, asm_op, c_op, I, asm_or, c_or, w, int, ) +#else +#define ATOMIC_OPS(op, asm_op, c_op, I, asm_or, c_or) \ + ATOMIC_FETCH_OP(op, asm_op, c_op, I, asm_or, c_or, w, int, ) \ + ATOMIC_FETCH_OP(op, asm_op, c_op, I, asm_or, c_or, d, long, 64) +#endif + +ATOMIC_OPS(and, and, &, i, , _relaxed) +ATOMIC_OPS(and, and, &, i, .aq , _acquire) +ATOMIC_OPS(and, and, &, i, .rl , _release) +ATOMIC_OPS(and, and, &, i, .aqrl, ) + +ATOMIC_OPS( or, or, |, i, , _relaxed) +ATOMIC_OPS( or, or, |, i, .aq , _acquire) +ATOMIC_OPS( or, or, |, i, .rl , _release) +ATOMIC_OPS( or, or, |, i, .aqrl, ) + +ATOMIC_OPS(xor, xor, ^, i, , _relaxed) +ATOMIC_OPS(xor, xor, ^, i, .aq , _acquire) +ATOMIC_OPS(xor, xor, ^, i, .rl , _release) +ATOMIC_OPS(xor, xor, ^, i, .aqrl, ) + +#undef ATOMIC_OPS + +#undef ATOMIC_FETCH_OP +#undef ATOMIC_OP_RETURN + +/* The extra atomic operations that are constructed from one of the core + * AMO-based operations above (aside from sub, which is easier to fit above). + * These are required to perform a barrier, but they're OK this way because + * atomic_*_return is also required to perform a barrier. + */ +#define ATOMIC_OP(op, func_op, comp_op, I, c_type, prefix) \ +static __always_inline bool atomic##prefix##_##op(c_type i, atomic##prefix##_t *v) \ +{ \ + return atomic##prefix##_##func_op##_return(i, v) comp_op I; \ +} + +#ifdef CONFIG_GENERIC_ATOMIC64 +#define ATOMIC_OPS(op, func_op, comp_op, I) \ + ATOMIC_OP (op, func_op, comp_op, I, int, ) +#else +#define ATOMIC_OPS(op, func_op, comp_op, I) \ + ATOMIC_OP (op, func_op, comp_op, I, int, ) \ + ATOMIC_OP (op, func_op, comp_op, I, long, 64) +#endif + +ATOMIC_OPS(add_and_test, add, ==, 0) +ATOMIC_OPS(sub_and_test, sub, ==, 0) +ATOMIC_OPS(add_negative, add, <, 0) + +#undef ATOMIC_OP +#undef ATOMIC_OPS + +#define ATOMIC_OP(op, func_op, c_op, I, prefix) \ +static __always_inline void atomic##prefix##_##op(atomic##prefix##_t *v) \ +{ \ + atomic##prefix##_##func_op(I, v); \ +} + +#define ATOMIC_FETCH_OP(op, func_op, c_op, I, prefix) \ +static __always_inline int atomic##prefix##_fetch_##op(atomic##prefix##_t *v) \ +{ \ + return atomic##prefix##_fetch_##func_op(I, v); \ +} + +#define ATOMIC_OP_RETURN (op, asm_op, c_op,I , prefix) \ +static __always_inline int atomic##prefix##_##op##_return(atomic##prefix##_t *v) \ +{ \ + return atomic##prefix##_fetch_##op(v) c_op I; \ +} + +#ifdef CONFIG_GENERIC_ATOMIC64 +#define ATOMIC_OPS (op, asm_op, c_op,I ) \ + ATOMIC_OP (op, asm_op, c_op, I, ) \ + ATOMIC_FETCH_OP (op, asm_op, c_op, I, ) \ + ATOMIC_OP_RETURN(op, asm_op, c_op, I, ) +#else +#define ATOMIC_OPS (op, asm_op, c_op,I ) \ + ATOMIC_OP (op, asm_op, c_op, I, ) \ + ATOMIC_FETCH_OP (op, asm_op, c_op, I, ) \ + ATOMIC_OP_RETURN(op, asm_op, c_op, I, ) \ + ATOMIC_OP (op, asm_op, c_op, I, 64) \ + ATOMIC_FETCH_OP (op, asm_op, c_op, I, 64) \ + ATOMIC_OP_RETURN(op, asm_op, c_op, I, 64) +#endif + +ATOMIC_OPS(inc, add, +, 1) +ATOMIC_OPS(dec, add, +, -1) + +#undef ATOMIC_OPS +#undef ATOMIC_OP +#undef ATOMIC_FETCH_OP +#undef ATOMIC_OP_RETURN + +#define ATOMIC_OP (op, func_op, comp_op,I , prefix) \ +static __always_inline bool atomic##prefix##_##op(atomic##prefix##_t *v) \ +{ \ + return atomic##prefix##_##func_op##_return(v) comp_op I; \ +} + +ATOMIC_OP(inc_and_test, inc, ==, 0, ) +ATOMIC_OP(dec_and_test, dec, ==, 0, ) +#ifndef CONFIG_GENERIC_ATOMIC64 +ATOMIC_OP(inc_and_test, inc, ==, 0, 64) +ATOMIC_OP(dec_and_test, dec, ==, 0, 64) +#endif + +#undef ATOMIC_OP + +/* This is required to provide a barrier on success. */ +static __always_inline int __atomic_add_unless(atomic_t *v, int a, int u) +{ + registerint prev, rc; + + __asm__ __volatile__ ( +"0:\n\t" +"lr.w.aqrl %0, %2\n\t" +"beq %0, %4, 1f\n\t" +"add %1, %0, %3\n\t" +"sc.w.aqrl %1, %1, %2\n\t" +"bnez %1, 0b\n\t" +"1:" + :"=&r" (prev),"=&r" (rc),"+A" (v->counter) + :"r" (a),"r" (u)); +return prev; +} + +#ifndef CONFIG_GENERIC_ATOMIC64 +static __always_inline long atomic64_add_unless(atomic64_t *v, long a, long u) +{ + register long prev, rc; + + __asm__ __volatile__ ( +"0:\n\t" +"lr.d.aqrl %0, %2\n\t" +"beq %0, %4, 1f\n\t" +"add %1, %0, %3\n\t" +"sc.d.aqrl %1, %1, %2\n\t" +"bnez %1, 0b\n\t" +"1:" + :"=&r" (prev),"=&r" (rc),"+A" (v->counter) + :"r" (a),"r" (u)); +return prev; +} +#endif + +/* The extra atomic operations that are constructed from one of the core +* LR/SC-based operations above. +*/ +static __always_inline int atomic_inc_not_zero(atomic_t *v) +{ +return __atomic_add_unless (v,1 ,0 ); +} + +#ifndef CONFIG_GENERIC_ATOMIC64 +static __always_inline int atomic64_inc_not_zero(atomic64_t *v) +{ +return atomic64_add_unless (v,1 ,0 ); +} +#endif + +/* atomic_{cmp,}xchg is required to have exactly the same ordering semantics as +* {cmp,}xchg and the operations that return, so they need a barrier. We just +* use the other implementations directly. +*/ +#define ATOMIC_OP (c_t, prefix, c_or, size, asm_or) \ +static __always_inline c_t atomic##prefix##_cmpxchg##c_or(atomic##prefix##_t *v, c_t o, c_t n) \ +{ \ + return __cmpxchg(&(v->counter), o, n, size, asm_or, asm_or); \ +} \ +static __always_inline c_t atomic##prefix##_xchg##c_or(atomic##prefix##_t *v, c_t n) \ +{ \ + return __xchg(n, &(v->counter), size, asm_or); \ +} + +#ifdef CONFIG_GENERIC_ATOMIC64 +#define ATOMIC_OPS (c_or, asm_or) \ + ATOMIC_OP( int, , c_or, 4, asm_or) +#else +#define ATOMIC_OPS (c_or, asm_or) \ + ATOMIC_OP( int, , c_or, 4, asm_or) \ + ATOMIC_OP(long, 64, c_or, 8, asm_or) +#endif + +ATOMIC_OPS( , .aqrl) +ATOMIC_OPS(_acquire, .aq) +ATOMIC_OPS(_release, .rl) +ATOMIC_OPS(_relaxed, ) + +#undef ATOMIC_OPS +#undef ATOMIC_OP + +#else /* !CONFIG_ISA_A */ + +#include <asm-generic/atomic.h> + +#endif /* CONFIG_ISA_A */ + +#endif /* _ASM_RISCV_ATOMIC_H */
arch/riscv/include/asm/barrier.h new file +139 -0
139 lines not on this page · raw message
arch/riscv/include/asm/bitops.h new file +228 -0
228 lines not on this page · raw message
arch/riscv/include/asm/cacheflush.h new file +39 -0
@@ -0,0 +1,39 @@ +/* +* Copyright (C) 2015 Regents of the University of California +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation, version 2. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +*/ + +#ifndef _ASM_RISCV_CACHEFLUSH_H +#define _ASM_RISCV_CACHEFLUSH_H + +#include <asm-generic/cacheflush.h> + +#undef flush_icache_range +#undef flush_icache_user_range + +static inline void local_flush_icache_all (void ) +{ + asmvolatile ("fence.i" :::"memory" ); +} + +#ifndef CONFIG_SMP + +#define flush_icache_range (start, end) local_flush_icache_all() +#define flush_icache_user_range (vma, pg, addr, len) local_flush_icache_all() + +#else /* CONFIG_SMP */ + +#define flush_icache_range (start, end) sbi_remote_fence_i(0) +#define flush_icache_user_range (vma, pg, addr, len) sbi_remote_fence_i(0) + +#endif /* CONFIG_SMP */ + +#endif /* _ASM_RISCV_CACHEFLUSH_H */
arch/riscv/include/asm/cmpxchg.h new file +138 -0
138 lines not on this page · raw message
arch/riscv/include/asm/io.h new file +178 -0
178 lines not on this page · raw message
arch/riscv/include/asm/spinlock.h new file +167 -0
167 lines not on this page · raw message
arch/riscv/include/asm/spinlock_types.h new file +33 -0
@@ -0,0 +1,33 @@ +/* +* Copyright (C) 2015 Regents of the University of California +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation, version 2. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +*/ + +#ifndef _ASM_RISCV_SPINLOCK_TYPES_H +#define _ASM_RISCV_SPINLOCK_TYPES_H + +#ifndef __LINUX_SPINLOCK_TYPES_H +# error "please don't include this file directly" +#endif + +typedef struct { +volatile unsigned int lock; +}arch_spinlock_t ; + +#define __ARCH_SPIN_LOCK_UNLOCKED { 0 } + +typedef struct { +volatile unsigned int lock; +}arch_rwlock_t ; + +#define __ARCH_RW_LOCK_UNLOCKED { 0 } + +#endif
arch/riscv/include/asm/tlb.h new file +24 -0
@@ -0,0 +1,24 @@ +/* +* Copyright (C) 2012 Regents of the University of California +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation, version 2. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +*/ + +#ifndef _ASM_RISCV_TLB_H +#define _ASM_RISCV_TLB_H + +#include <asm-generic/tlb.h> + +static inline void tlb_flush (struct mmu_gather *tlb) +{ +flush_tlb_mm (tlb->mm); +} + +#endif /* _ASM_RISCV_TLB_H */
arch/riscv/include/asm/tlbflush.h new file +64 -0
64 lines not on this page · raw message
Signature · 1 line
2.13.0
Palmer Dabbelt
maintainerPATCH 3/9 RISC-V: Generic library routines and assembly
In reply to Palmer DabbeltThis patch contains code that is more specific to the RISC-V ISA than it is to Linux. It contains string and math operations, C wrappers for various assembly instructions, stack walking code, and uaccess.
--- arch/riscv/include/asm/asm.h | 76 ++++++ arch/riscv/include/asm/csr.h | 125 +++++++++ arch/riscv/include/asm/linkage.h | 20 ++ arch/riscv/include/asm/string.h | 30 +++ arch/riscv/include/asm/uaccess.h | 440 ++++++++++++++++++++++++++++++++ arch/riscv/include/asm/word-at-a-time.h | 55 ++++ arch/riscv/kernel/stacktrace.c | 177 +++++++++++++ arch/riscv/lib/memcpy.S | 98 +++++++ arch/riscv/lib/memset.S | 118 +++++++++ arch/riscv/lib/uaccess.S | 125 +++++++++ arch/riscv/lib/udivdi3.S | 38 +++ 11 files changed, 1302 insertions(+) create mode 100644 arch/riscv/include/asm/asm.h create mode 100644 arch/riscv/include/asm/csr.h create mode 100644 arch/riscv/include/asm/linkage.h create mode 100644 arch/riscv/include/asm/string.h create mode 100644 arch/riscv/include/asm/uaccess.h create mode 100644 arch/riscv/include/asm/word-at-a-time.h create mode 100644 arch/riscv/kernel/stacktrace.c create mode 100644 arch/riscv/lib/memcpy.S create mode 100644 arch/riscv/lib/memset.S create mode 100644 arch/riscv/lib/uaccess.S create mode 100644 arch/riscv/lib/udivdi3.S
arch/riscv/include/asm/asm.h new file +76 -0
@@ -0,0 +1,76 @@ +/* +* Copyright (C) 2015 Regents of the University of California +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation, version 2. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +*/ + +#ifndef _ASM_RISCV_ASM_H +#define _ASM_RISCV_ASM_H + +#ifdef __ASSEMBLY__ +#define __ASM_STR (x) x +#else +#define __ASM_STR (x) #x +#endif + +#if __riscv_xlen ==64 +#define __REG_SEL (a, b) __ASM_STR(a) +#elif __riscv_xlen ==32 +#define __REG_SEL (a, b) __ASM_STR(b) +#else +#error "Unexpected __riscv_xlen" +#endif + +#define REG_L __REG_SEL(ld, lw) +#define REG_S __REG_SEL(sd, sw) +#define SZREG __REG_SEL(8, 4) +#define LGREG __REG_SEL(3, 2) + +#if __SIZEOF_POINTER__ ==8 +#ifdef __ASSEMBLY__ +#define RISCV_PTR .dword +#define RISCV_SZPTR 8 +#define RISCV_LGPTR 3 +#else +#define RISCV_PTR ".dword" +#define RISCV_SZPTR "8" +#define RISCV_LGPTR "3" +#endif +#elif __SIZEOF_POINTER__ ==4 +#ifdef __ASSEMBLY__ +#define RISCV_PTR .word +#define RISCV_SZPTR 4 +#define RISCV_LGPTR 2 +#else +#define RISCV_PTR ".word" +#define RISCV_SZPTR "4" +#define RISCV_LGPTR "2" +#endif +#else +#error "Unexpected __SIZEOF_POINTER__" +#endif + +#if (__SIZEOF_INT__ ==4 ) +#define INT __ASM_STR(.word) +#define SZINT __ASM_STR(4) +#define LGINT __ASM_STR(2) +#else +#error "Unexpected __SIZEOF_INT__" +#endif + +#if (__SIZEOF_SHORT__ ==2 ) +#define SHORT __ASM_STR(.half) +#define SZSHORT __ASM_STR(2) +#define LGSHORT __ASM_STR(1) +#else +#error "Unexpected __SIZEOF_SHORT__" +#endif + +#endif /* _ASM_RISCV_ASM_H */
arch/riscv/include/asm/csr.h new file +125 -0
125 lines not on this page · raw message
arch/riscv/include/asm/linkage.h new file +20 -0
@@ -0,0 +1,20 @@ +/* +* Copyright (C) 2015 Regents of the University of California +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation, version 2. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +*/ + +#ifndef _ASM_RISCV_LINKAGE_H +#define _ASM_RISCV_LINKAGE_H + +#define __ALIGN .balign 4 +#define __ALIGN_STR ".balign 4" + +#endif /* _ASM_RISCV_LINKAGE_H */
arch/riscv/include/asm/string.h new file +30 -0
@@ -0,0 +1,30 @@ +/* +* Copyright (C) 2013 Regents of the University of California +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation, version 2. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +*/ + +#ifndef _ASM_RISCV_STRING_H +#define _ASM_RISCV_STRING_H + +#ifdef __KERNEL__ + +#include <linux/types.h> +#include <linux/linkage.h> + +#define __HAVE_ARCH_MEMSET +extern asmlinkage void *memset(void *, int, size_t); + +#define __HAVE_ARCH_MEMCPY +extern asmlinkage void *memcpy(void *, const void *, size_t); + +#endif /* __KERNEL__ */ + +#endif /* _ASM_RISCV_STRING_H */
arch/riscv/include/asm/uaccess.h new file +440 -0
440 lines not on this page · raw message
arch/riscv/include/asm/word-at-a-time.h new file +55 -0
55 lines not on this page · raw message
arch/riscv/kernel/stacktrace.c new file +177 -0
177 lines not on this page · raw message
arch/riscv/lib/memcpy.S new file +98 -0
98 lines not on this page · raw message
arch/riscv/lib/memset.S new file +118 -0
118 lines not on this page · raw message
arch/riscv/lib/uaccess.S new file +125 -0
125 lines not on this page · raw message
arch/riscv/lib/udivdi3.S new file +38 -0
@@ -0,0 +1,38 @@ +/* + * Copyright (C) 2016-2017 Free Software Foundation, Inc. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation, version 2. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + + .globl __udivdi3 +__udivdi3: + mv a2, a1 + mv a1, a0 + li a0, -1 + beqz a2, .L5 + li a3, 1 + bgeu a2, a1, .L2 +.L1: + blez a2, .L2 + slli a2, a2, 1 + slli a3, a3, 1 + bgtu a1, a2, .L1 +.L2: + li a0, 0 +.L3: + bltu a1, a2, .L4 + sub a1, a1, a2 + or a0, a0, a3 +.L4: + srli a3, a3, 1 + srli a2, a2, 1 + bnez a3, .L3 +.L5: + ret
Signature · 1 line
2.13.0
Palmer Dabbelt
maintainerPATCH 4/9 RISC-V: ELF and module implementation
In reply to Palmer DabbeltThis patch contains the code that interfaces with ELF objects on RISC-V systems, the vast majority of which is present to load kernel modules.
--- arch/riscv/include/asm/compat.h | 31 +++++++++++++++ arch/riscv/include/asm/elf.h | 85 +++++++++++++++++++++++++++++++++++++++++ arch/riscv/mm/extable.c | 37 ++++++++++++++++++ 3 files changed, 153 insertions(+) create mode 100644 arch/riscv/include/asm/compat.h create mode 100644 arch/riscv/include/asm/elf.h create mode 100644 arch/riscv/mm/extable.c
arch/riscv/include/asm/compat.h new file +31 -0
@@ -0,0 +1,31 @@ +/* +* Copyright (C) 2012 ARM Ltd. +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ +#ifndef __ASM_COMPAT_H +#define __ASM_COMPAT_H +#ifdef __KERNEL__ +#ifdef CONFIG_COMPAT + +#if defined(CONFIG_64BIT ) +#define COMPAT_UTS_MACHINE "riscv64\0\0" +#elif defined(CONFIG_32BIT ) +#define COMPAT_UTS_MACHINE "riscv32\0\0" +#else +#error "Unknown RISC-V base ISA" +#endif + +#endif /*CONFIG_COMPAT*/ +#endif /*__KERNEL__*/ +#endif /*__ASM_COMPAT_H*/
arch/riscv/include/asm/elf.h new file +85 -0
85 lines not on this page · raw message
arch/riscv/mm/extable.c new file +37 -0
@@ -0,0 +1,37 @@ +/* +* Copyright (C) 2009 Sunplus Core Technology Co., Ltd. +* Lennox Wu <[email protected]> +* Chen Liqin <[email protected]> +* Copyright (C) 2013 Regents of the University of California +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, see the file COPYING, or write +* to the Free Software Foundation, Inc., +*/ + + +#include <linux/extable.h> +#include <linux/module.h> +#include <linux/uaccess.h> + +int fixup_exception (struct pt_regs *regs) +{ +const struct exception_table_entry *fixup; + + fixup =search_exception_tables (regs->sepc); +if (fixup) { + regs->sepc = fixup->fixup; +return 1 ; + } +return 0 ; +}
Signature · 1 line
2.13.0
Palmer Dabbelt
maintainerPATCH 4/9 RISC-V: ELF and module implementation
In reply to Palmer DabbeltThis patch contains the code that interfaces with ELF objects on RISC-V systems, the vast majority of which is present to load kernel modules.
--- arch/riscv/include/asm/compat.h | 31 +++++++++++++++ arch/riscv/include/asm/elf.h | 85 +++++++++++++++++++++++++++++++++++++++++ arch/riscv/mm/extable.c | 37 ++++++++++++++++++ 3 files changed, 153 insertions(+) create mode 100644 arch/riscv/include/asm/compat.h create mode 100644 arch/riscv/include/asm/elf.h create mode 100644 arch/riscv/mm/extable.c
arch/riscv/include/asm/compat.h new file +31 -0
@@ -0,0 +1,31 @@ +/* +* Copyright (C) 2012 ARM Ltd. +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ +#ifndef __ASM_COMPAT_H +#define __ASM_COMPAT_H +#ifdef __KERNEL__ +#ifdef CONFIG_COMPAT + +#if defined(CONFIG_64BIT ) +#define COMPAT_UTS_MACHINE "riscv64\0\0" +#elif defined(CONFIG_32BIT ) +#define COMPAT_UTS_MACHINE "riscv32\0\0" +#else +#error "Unknown RISC-V base ISA" +#endif + +#endif /*CONFIG_COMPAT*/ +#endif /*__KERNEL__*/ +#endif /*__ASM_COMPAT_H*/
arch/riscv/include/asm/elf.h new file +85 -0
85 lines not on this page · raw message
arch/riscv/mm/extable.c new file +37 -0
@@ -0,0 +1,37 @@ +/* +* Copyright (C) 2009 Sunplus Core Technology Co., Ltd. +* Lennox Wu <[email protected]> +* Chen Liqin <[email protected]> +* Copyright (C) 2013 Regents of the University of California +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, see the file COPYING, or write +* to the Free Software Foundation, Inc., +*/ + + +#include <linux/extable.h> +#include <linux/module.h> +#include <linux/uaccess.h> + +int fixup_exception (struct pt_regs *regs) +{ +const struct exception_table_entry *fixup; + + fixup =search_exception_tables (regs->sepc); +if (fixup) { + regs->sepc = fixup->fixup; +return 1 ; + } +return 0 ; +}
Signature · 1 line
2.13.0
Palmer Dabbelt
maintainerPATCH 5/9 RISC-V: Task implementation
In reply to Palmer DabbeltThis patch contains the implementation of tasks on RISC-V, most of which is involved in task switching.
--- arch/riscv/include/asm/asm-offsets.h | 1 + arch/riscv/include/asm/current.h | 43 ++++ arch/riscv/include/asm/kprobes.h | 22 ++ arch/riscv/include/asm/processor.h | 102 ++++++++ arch/riscv/include/asm/switch_to.h | 69 ++++++ arch/riscv/include/asm/thread_info.h | 96 ++++++++ arch/riscv/kernel/asm-offsets.c | 316 +++++++++++++++++++++++++ arch/riscv/kernel/entry.S | 436 +++++++++++++++++++++++++++++++++++ arch/riscv/kernel/process.c | 131 +++++++++++ 9 files changed, 1216 insertions(+) create mode 100644 arch/riscv/include/asm/asm-offsets.h create mode 100644 arch/riscv/include/asm/current.h create mode 100644 arch/riscv/include/asm/kprobes.h create mode 100644 arch/riscv/include/asm/processor.h create mode 100644 arch/riscv/include/asm/switch_to.h create mode 100644 arch/riscv/include/asm/thread_info.h create mode 100644 arch/riscv/kernel/asm-offsets.c create mode 100644 arch/riscv/kernel/entry.S create mode 100644 arch/riscv/kernel/process.c
arch/riscv/include/asm/asm-offsets.h new file +1 -0
@@ -0,0 +1 @@ +#include <generated/asm-offsets.h>
arch/riscv/include/asm/current.h new file +43 -0
43 lines not on this page · raw message
arch/riscv/include/asm/kprobes.h new file +22 -0
@@ -0,0 +1,22 @@ +/* +* Copyright (C) 2017 SiFive +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation, version 2. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +*/ + + +#ifndef ASM_RISCV_KPROBES_H +#define ASM_RISCV_KPROBES_H + +#ifdef CONFIG_KPROBES +#error "RISC-V doesn't skpport CONFIG_KPROBES" +#endif + +#endif
arch/riscv/include/asm/processor.h new file +102 -0
102 lines not on this page · raw message
arch/riscv/include/asm/switch_to.h new file +69 -0
69 lines not on this page · raw message
arch/riscv/include/asm/thread_info.h new file +96 -0
96 lines not on this page · raw message
arch/riscv/kernel/asm-offsets.c new file +316 -0
316 lines not on this page · raw message
arch/riscv/kernel/entry.S new file +436 -0
436 lines not on this page · raw message
arch/riscv/kernel/process.c new file +131 -0
131 lines not on this page · raw message
Signature · 1 line
2.13.0
Palmer Dabbelt
maintainerPATCH 5/9 RISC-V: Task implementation
In reply to Palmer DabbeltThis patch contains the implementation of tasks on RISC-V, most of which is involved in task switching.
--- arch/riscv/include/asm/asm-offsets.h | 1 + arch/riscv/include/asm/current.h | 43 ++++ arch/riscv/include/asm/kprobes.h | 22 ++ arch/riscv/include/asm/processor.h | 102 ++++++++ arch/riscv/include/asm/switch_to.h | 69 ++++++ arch/riscv/include/asm/thread_info.h | 96 ++++++++ arch/riscv/kernel/asm-offsets.c | 316 +++++++++++++++++++++++++ arch/riscv/kernel/entry.S | 436 +++++++++++++++++++++++++++++++++++ arch/riscv/kernel/process.c | 131 +++++++++++ 9 files changed, 1216 insertions(+) create mode 100644 arch/riscv/include/asm/asm-offsets.h create mode 100644 arch/riscv/include/asm/current.h create mode 100644 arch/riscv/include/asm/kprobes.h create mode 100644 arch/riscv/include/asm/processor.h create mode 100644 arch/riscv/include/asm/switch_to.h create mode 100644 arch/riscv/include/asm/thread_info.h create mode 100644 arch/riscv/kernel/asm-offsets.c create mode 100644 arch/riscv/kernel/entry.S create mode 100644 arch/riscv/kernel/process.c
arch/riscv/include/asm/asm-offsets.h new file +1 -0
@@ -0,0 +1 @@ +#include <generated/asm-offsets.h>
arch/riscv/include/asm/current.h new file +43 -0
43 lines not on this page · raw message
arch/riscv/include/asm/kprobes.h new file +22 -0
@@ -0,0 +1,22 @@ +/* +* Copyright (C) 2017 SiFive +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation, version 2. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +*/ + + +#ifndef ASM_RISCV_KPROBES_H +#define ASM_RISCV_KPROBES_H + +#ifdef CONFIG_KPROBES +#error "RISC-V doesn't skpport CONFIG_KPROBES" +#endif + +#endif
arch/riscv/include/asm/processor.h new file +102 -0
102 lines not on this page · raw message
arch/riscv/include/asm/switch_to.h new file +69 -0
69 lines not on this page · raw message
arch/riscv/include/asm/thread_info.h new file +96 -0
96 lines not on this page · raw message
arch/riscv/kernel/asm-offsets.c new file +316 -0
316 lines not on this page · raw message
arch/riscv/kernel/entry.S new file +436 -0
436 lines not on this page · raw message
arch/riscv/kernel/process.c new file +131 -0
131 lines not on this page · raw message
Signature · 1 line
2.13.0
Re: [PATCH 5/9] RISC-V: Task implementation
Quoted 6 lines · Palmer Dabbelt
arch/riscv/include/asm/kprobes.h new file +0
-0@@ -0,0 +1,22 @@
...
arch/riscv/include/asm/kprobes.h line 20
Quoted 3 lines
arch/riscv/include/asm/kprobes.h new file +3
-0+#ifdef CONFIG_KPROBES +#error "RISC-V doesn't skpport CONFIG_KPROBES" +#endif
I'm wondering where your fallback definition of e.g. NOKPROBE_SYMBOL comes from then.
Could you just use the asm-generic one?
Quoted 6 lines
arch/riscv/kernel/process.c new file +0
-0@@ -0,0 +1,131 @@
...
arch/riscv/kernel/process.c line 50
Quoted 6 lines
arch/riscv/kernel/process.c new file +6
-0+void show_regs (struct pt_regs *regs) +{ +show_regs_print_info (KERN_DEFAULT ); + +printk (KERN_CONT "sepc: " REG_FMT " ra : " REG_FMT " sp : " REG_FMT "\n" , + regs->sepc, regs->ra, regs->sp);
I've noticed inconsistent use of pr_* and printk(KERN_* in this patchset. Maybe now would be the best time to switch everything to pr_*.
arch/riscv/kernel/process.c line 93
Quoted 4 lines
arch/riscv/kernel/process.c new file +4
-0+/* Reset FPU context +* frm: round to nearest, ties to even (IEEE default) +* fflags: accrued exceptions cleared +*/
Similarly lots of multiline comments which don't follow the standard style in Documentation/process/coding-style.rst. Maybe now is the best time to convert if you're going to.
Cheers
James
Palmer Dabbelt
maintainerRe: [PATCH 5/9] RISC-V: Task implementation
Quoted 8 lines · On Wed, 28 Jun 2017 16:32:55 PDT (-0700), [email protected] wrote:
Quoted 6 lines · Palmer Dabbelt
arch/riscv/include/asm/kprobes.h new file +0
-0@@ -0,0 +1,22 @@...
Quoted 8 lines
arch/riscv/include/asm/kprobes.h line 20
Quoted 3 lines
arch/riscv/include/asm/kprobes.h new file +3
-0+#ifdef CONFIG_KPROBES +#error "RISC-V doesn't skpport CONFIG_KPROBES" +#endif I'm wondering where your fallback definition of e.g.
NOKPROBE_SYMBOLcomes from then.Could you just use the asm-generic one?
I believe so.
Quoted 6 lines
Quoted 4 lines
arch/riscv/kernel/process.c new file +0
-1--- /dev/null...
Quoted 9 lines
arch/riscv/kernel/process.c line 50
Quoted 6 lines
arch/riscv/kernel/process.c new file +6
-0+void show_regs (struct pt_regs *regs) +{ +show_regs_print_info (KERN_DEFAULT ); + +printk (KERN_CONT "sepc: " REG_FMT " ra : " REG_FMT " sp : " REG_FMT "\n" , + regs->sepc, regs->ra, regs->sp);I've noticed inconsistent use of pr_* and printk(KERN_* in this patchset. Maybe now would be the best time to switch everything to pr_*.
I went through and fixed them all.
Quoted 8 lines
arch/riscv/kernel/process.c line 93
Quoted 4 lines
arch/riscv/kernel/process.c new file +4
-0+/* Reset FPU context +* frm: round to nearest, ties to even (IEEE default) +* fflags: accrued exceptions cleared +*/ Similarly lots of multiline comments which don't follow the standard style in
Documentation/process/coding-style.rst. Maybe now is the best time to convert if you're going to.
Someone else found one and suggested this, it's on my TODO list.
Thanks!
Re: [PATCH 5/9] RISC-V: Task implementation
In reply to Palmer DabbeltOn 2017-06-28 at 20:55:34 +0200, Palmer Dabbelt <[email protected]> wrote:
[...]
Quoted 15 lines
arch/riscv/include/asm/kprobes.h new file +9
-0@@ -0,0 +1,22 @@ +/* +* Copyright (C) 2017 SiFive +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation, version 2. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of
arch/riscv/include/asm/kprobes.h line 19
Quoted 10 lines
arch/riscv/include/asm/kprobes.h new file +10
-0+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +*/ + + +#ifndef ASM_RISCV_KPROBES_H +#define ASM_RISCV_KPROBES_H + +#ifdef CONFIG_KPROBES +#error "RISC-V doesn't skpport CONFIG_KPROBES"
Typo: s/skpport/support/
Quoted 59 lines
arch/riscv/include/asm/kprobes.h new file +3
-0+#endif + +#endif arch/riscv/include/asm/processor.h new file +50
-0@@ -0,0 +1,102 @@ +/* +* Copyright (C) 2012 Regents of the University of California +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation, version 2. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +*/ + +#ifndef _ASM_RISCV_PROCESSOR_H +#define _ASM_RISCV_PROCESSOR_H + +#include <linux/const.h> + +#include <asm/ptrace.h> + +/* + * This decides where the kernel will search for a free chunk of vm + * space during mmap's. + */ +#define TASK_UNMAPPED_BASE PAGE_ALIGN(TASK_SIZE >> 1) + +#ifdef __KERNEL__ +#define STACK_TOP TASK_SIZE +#define STACK_TOP_MAX STACK_TOP +#define STACK_ALIGN 16 +#endif /* __KERNEL__ */ + +#ifndef __ASSEMBLY__ + +struct task_struct; +struct pt_regs; + +/* + * Default implementation of macro that returns current + * instruction pointer ("program counter"). + */ +#define current_text_addr() ({ __label__ _l; _l: &&_l; }) + +/* CPU-specific state of a task */ +struct thread_struct { + /* Callee-saved registers */ + unsigned long ra; + unsigned long sp; /* Kernel mode stack */ + unsigned long s[12]; /* s[0]: frame pointer */ + struct __riscv_d_ext_state fstate;
arch/riscv/include/asm/processor.h line 60
Quoted 10 lines
arch/riscv/include/asm/processor.h new file +10
-0+}; + +#define INIT_THREAD { \ + .sp = sizeof(init_stack) + (long)&init_stack, \ +} + +/* Return saved (kernel) PC of a blocked thread. */ +#define thread_saved_pc (t) ((t)->thread.ra) +#define thread_saved_sp (t) ((t)->thread.sp) +#define thread_saved_fp (t) ((t)->thread.s[0])
These aren't needed outside of arch-specific code (anymore) and the riscv port doesn't seem to be using them, so they can be omitted.
Palmer Dabbelt
maintainerRe: [PATCH 5/9] RISC-V: Task implementation
Quoted 21 lines · On Thu, 29 Jun 2017 01:22:23 PDT (-0700), [email protected] wrote:
On 2017-06-28 at 20:55:34 +0200, Palmer Dabbelt <[email protected]> wrote:
[...]Quoted 19 lines
arch/riscv/include/asm/kprobes.h new file +13
-0@@ -0,0 +1,22 @@ +/* +* Copyright (C) 2017 SiFive +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation, version 2. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +*/ +
Quoted 8 lines
arch/riscv/include/asm/kprobes.h line 19
Quoted 6 lines
arch/riscv/include/asm/kprobes.h new file +6
-0+ +#ifndef ASM_RISCV_KPROBES_H +#define ASM_RISCV_KPROBES_H + +#ifdef CONFIG_KPROBES +#error "RISC-V doesn't skpport CONFIG_KPROBES"Typo: s/skpport/support/
Thanks.
Quoted 64 lines
Quoted 64 lines
arch/riscv/include/asm/kprobes.h new file +3
-0+#endif + +#endif arch/riscv/include/asm/processor.h new file +55
-0@@ -0,0 +1,102 @@ +/* +* Copyright (C) 2012 Regents of the University of California +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation, version 2. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +*/ + +#ifndef _ASM_RISCV_PROCESSOR_H +#define _ASM_RISCV_PROCESSOR_H + +#include <linux/const.h> + +#include <asm/ptrace.h> + +/* +* This decides where the kernel will search for a free chunk of vm +* space during mmap's. +*/ +#define TASK_UNMAPPED_BASE PAGE_ALIGN(TASK_SIZE >> 1) + +#ifdef __KERNEL__ +#define STACK_TOP TASK_SIZE +#define STACK_TOP_MAX STACK_TOP +#define STACK_ALIGN 16 +#endif /* __KERNEL__ */ + +#ifndef __ASSEMBLY__ + +struct task_struct ; +struct pt_regs ; + +/* +* Default implementation of macro that returns current +* instruction pointer ("program counter"). +*/ +#define current_text_addr () ({ __label__ _l; _l: &&_l; }) + +/* CPU-specific state of a task */ +struct thread_struct { +/* Callee-saved registers */ +unsigned long ra; +unsigned long sp;/* Kernel mode stack */ +unsigned long s[12 ];/* s[0]: frame pointer */ +struct __riscv_d_ext_state fstate; +}; + +#define INIT_THREAD { \ + .sp = sizeof(init_stack) + (long)&init_stack, \ +}
Quoted 8 lines
arch/riscv/include/asm/processor.h line 60
Quoted 5 lines
arch/riscv/include/asm/processor.h new file +5
-0+ +/* Return saved (kernel) PC of a blocked thread. */ +#define thread_saved_pc (t) ((t)->thread.ra) +#define thread_saved_sp (t) ((t)->thread.sp) +#define thread_saved_fp (t) ((t)->thread.s[0])These aren't needed outside of arch-specific code (anymore) and the riscv port doesn't seem to be using them, so they can be omitted.
Great. I've removed them, I'll include that in the v4
diff --git a/arch/riscv/include/asm/processor.h b/arch/riscv/include/asm/processor.h
index 53768048b9de..b62873633bde 100644
--- a/arch/riscv/include/asm/processor.h
+++ b/arch/riscv/include/asm/processor.h
@@ -52,11 +52,6 @@ struct thread_struct {
.sp = sizeof(init_stack) + (long)&init_stack, \
}-/* Return saved (kernel) PC of a blocked thread. */
-#define thread_saved_pc(t) ((t)->thread.ra) -#define thread_saved_sp(t) ((t)->thread.sp) -#define thread_saved_fp(t) ((t)->thread.s[0])
-
#define task_pt_regs(tsk) \
((struct pt_regs *)(task_stack_page(tsk) + THREAD_SIZE \
- ALIGN(sizeof(struct pt_regs), STACK_ALIGN)))
Thanks!
Palmer Dabbelt
maintainerPATCH 6/9 RISC-V: Device, timer, IRQs, and the SBI
In reply to Palmer DabbeltThis patch contains code that interfaces with devices that are mandated by the RISC-V supervisor specification and that don't have explicit drivers anywhere else in the tree. This includes the staticly defined interrupts, the CSR-mapped timer, and virtualized SBI devices.
--- arch/riscv/include/asm/delay.h | 28 +++++++++ arch/riscv/include/asm/device.h | 27 +++++++++ arch/riscv/include/asm/dma-mapping.h | 41 ++++++++++++++ arch/riscv/include/asm/irq.h | 31 ++++++++++ arch/riscv/include/asm/irqflags.h | 63 +++++++++++++++++++++ arch/riscv/include/asm/pci.h | 50 ++++++++++++++++ arch/riscv/include/asm/sbi.h | 100 ++++++++++++++++++++++++++++++++ arch/riscv/include/asm/timex.h | 63 +++++++++++++++++++++ arch/riscv/lib/delay.c | 107 +++++++++++++++++++++++++++++++++++ arch/riscv/mm/ioremap.c | 92 ++++++++++++++++++++++++++++++ 10 files changed, 602 insertions(+) create mode 100644 arch/riscv/include/asm/delay.h create mode 100644 arch/riscv/include/asm/device.h create mode 100644 arch/riscv/include/asm/dma-mapping.h create mode 100644 arch/riscv/include/asm/irq.h create mode 100644 arch/riscv/include/asm/irqflags.h create mode 100644 arch/riscv/include/asm/pci.h create mode 100644 arch/riscv/include/asm/sbi.h create mode 100644 arch/riscv/include/asm/timex.h create mode 100644 arch/riscv/lib/delay.c create mode 100644 arch/riscv/mm/ioremap.c
arch/riscv/include/asm/delay.h new file +28 -0
@@ -0,0 +1,28 @@ +/* +* Copyright (C) 2009 Chen Liqin <[email protected]> +* Copyright (C) 2016 Regents of the University of California +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation, version 2. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +*/ + +#ifndef _ASM_RISCV_DELAY_H +#define _ASM_RISCV_DELAY_H + +extern unsigned long riscv_timebase; + +#define udelay udelay +extern void udelay (unsigned long usecs); + +#define ndelay ndelay +extern void ndelay (unsigned long nsecs); + +extern void __delay (unsigned long cycles); + +#endif /* _ASM_RISCV_DELAY_H */
arch/riscv/include/asm/device.h new file +27 -0
@@ -0,0 +1,27 @@ +/* +* Copyright (C) 2016 SiFive +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation, version 2. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +*/ + + +#ifndef _ASM_RISCV_DEVICE_H +#define _ASM_RISCV_DEVICE_H + +#include <linux/sysfs.h> + +struct dev_archdata { +struct dma_map_ops *dma_ops; +}; + +struct pdev_archdata { +}; + +#endif /* _ASM_RISCV_DEVICE_H */
arch/riscv/include/asm/dma-mapping.h new file +41 -0
41 lines not on this page · raw message
arch/riscv/include/asm/irq.h new file +31 -0
@@ -0,0 +1,31 @@ +/* +* Copyright (C) 2012 Regents of the University of California +* Copyright (C) 2017 SiFive +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation, version 2. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +*/ + +#ifndef _ASM_RISCV_IRQ_H +#define _ASM_RISCV_IRQ_H + +#define NR_IRQS 0 + +#define INTERRUPT_CAUSE_SOFTWARE 1 +#define INTERRUPT_CAUSE_TIMER 5 +#define INTERRUPT_CAUSE_EXTERNAL 9 + +void riscv_timer_interrupt (void ); + +#include <asm-generic/irq.h> + +/* The value of csr sie before init_traps runs (core is up) */ +DECLARE_PER_CPU (atomic_long_t, riscv_early_sie); + +#endif /* _ASM_RISCV_IRQ_H */
arch/riscv/include/asm/irqflags.h new file +63 -0
63 lines not on this page · raw message
arch/riscv/include/asm/pci.h new file +50 -0
50 lines not on this page · raw message
arch/riscv/include/asm/sbi.h new file +100 -0
100 lines not on this page · raw message
arch/riscv/include/asm/timex.h new file +63 -0
63 lines not on this page · raw message
arch/riscv/lib/delay.c new file +107 -0
107 lines not on this page · raw message
arch/riscv/mm/ioremap.c new file +92 -0
92 lines not on this page · raw message
Signature · 1 line
2.13.0
Re: [PATCH 6/9] RISC-V: Device, timer, IRQs, and the SBI
On 2017-06-28 at 20:55:35 +0200, Palmer Dabbelt <[email protected]> wrote:
[...]
Quoted 18 lines
arch/riscv/include/asm/device.h new file +12
-0@@ -0,0 +1,27 @@ +/* +* Copyright (C) 2016 SiFive +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation, version 2. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +*/
arch/riscv/include/asm/device.h line 22
Quoted 10 lines
arch/riscv/include/asm/device.h new file +10
-0+ + +#ifndef _ASM_RISCV_DEVICE_H +#define _ASM_RISCV_DEVICE_H + +#include <linux/sysfs.h> + +struct dev_archdata { +struct dma_map_ops *dma_ops; +};
The dma_ops member isn't used in any arch code or driver from what I can tell (I checked against your riscv-for-submission-v3 branch). Could device.h from asm-generic be used instead, or did I miss something?
Quoted 5 lines
arch/riscv/include/asm/device.h new file +5
-0+ +struct pdev_archdata { +}; + +#endif /* _ASM_RISCV_DEVICE_H */
Palmer Dabbelt
maintainerRe: [PATCH 6/9] RISC-V: Device, timer, IRQs, and the SBI
Quoted 26 lines · On Thu, 29 Jun 2017 01:39:25 PDT (-0700), [email protected] wrote:
On 2017-06-28 at 20:55:35 +0200, Palmer Dabbelt <[email protected]> wrote:
[...]Quoted 24 lines
arch/riscv/include/asm/device.h new file +18
-0@@ -0,0 +1,27 @@ +/* +* Copyright (C) 2016 SiFive +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation, version 2. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +*/ + + +#ifndef _ASM_RISCV_DEVICE_H +#define _ASM_RISCV_DEVICE_H + +#include <linux/sysfs.h>
Quoted 8 lines
arch/riscv/include/asm/device.h line 22
Quoted 4 lines
arch/riscv/include/asm/device.h new file +4
-0+ +struct dev_archdata { +struct dma_map_ops *dma_ops; +};The
dma_opsmember isn't used in any arch code or driver from what I can tell (I checked against your riscv-for-submission-v3 branch). Coulddevice.hfrom asm-generic be used instead, or did I miss something?
I think you're right. I'll include this
diff --git a/arch/riscv/include/asm/device.h b/arch/riscv/include/asm/device.h index 28975e528d2f..a310c2c26101 100644
--- a/arch/riscv/include/asm/device.h
+++ b/arch/riscv/include/asm/device.h
@@ -11,17 +11,9 @@
* GNU General Public License for more details.
*/
-
#ifndef _ASM_RISCV_DEVICE_H
#define _ASM_RISCV_DEVICE_H
-#include <linux/sysfs.h>
-
-struct dev_archdata {
- struct dma_map_ops *dma_ops;
-};
-
-struct pdev_archdata {
-};
+#include <asm-generic/device.h>#endif /* _ASM_RISCV_DEVICE_H */
in the v4
Quoted 6 lines
arch/riscv/include/asm/device.h line 27
Quoted 6 lines
arch/riscv/include/asm/device.h new file +5
-0+ +struct pdev_archdata { +}; + +#endif /* _ASM_RISCV_DEVICE_H */
Thanks!
Re: [PATCH 6/9] RISC-V: Device, timer, IRQs, and the SBI
Quoted 60 lines · Palmer Dabbelt
Quoted 26 lines · On Thu, 29 Jun 2017 01:39:25 PDT (-0700), [email protected] wrote:
On 2017-06-28 at 20:55:35 +0200, Palmer Dabbelt <[email protected]> wrote:
[...]Quoted 24 lines
arch/riscv/include/asm/device.h new file +18
-0@@ -0,0 +1,27 @@ +/* +* Copyright (C) 2016 SiFive +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation, version 2. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +*/ + + +#ifndef _ASM_RISCV_DEVICE_H +#define _ASM_RISCV_DEVICE_H + +#include <linux/sysfs.h> Quoted 8 lines
arch/riscv/include/asm/device.h line 22
Quoted 4 lines
arch/riscv/include/asm/device.h new file +4
-0+ +struct dev_archdata { +struct dma_map_ops *dma_ops; +};The
dma_opsmember isn't used in any arch code or driver from what I can tell (I checked against your riscv-for-submission-v3 branch). Coulddevice.hfrom asm-generic be used instead, or did I miss something?I think you're right. I'll include this
diff --git
a/arch/riscv/include/asm/device.hb/arch/riscv/include/asm/device.hindex28975e528d2f..a310c2c26101100644
---a/arch/riscv/include/asm/device.h
+++b/arch/riscv/include/asm/device.h
@@ -11,17 +11,9 @@
* GNU General Public License for more details.
*/- #ifndef _ASM_RISCV_DEVICE_H #define _ASM_RISCV_DEVICE_H -#include <linux/sysfs.h> - -struct dev_archdata { - struct dma_map_ops *dma_ops; -}; - -struct pdev_archdata { -}; +#include <asm-generic/device.h>
Quoted 3 lines
#endif /* _ASM_RISCV_DEVICE_H */in the v4
Better yet, remove arch/riscv/include/asm/device.h altogether and add device.h to generic-y in the asm/Kbuild file, as follows:
arch/riscv/include/asm/Kbuild +1 -0
@@ -3,6 +3,7 @@ generic-y += cacheflush.h generic-y += checksum.h generic-y += clkdev.h generic-y += cputime.h +generic-y += device.h generic-y += div64.h generic-y += dma.h generic-y += dma-contiguous.h
arch/riscv/include/asm/device.h deleted +0 -27
@@ -1,27 +0,0 @@ -/* -* Copyright (C) 2016 SiFive -* -* This program is free software; you can redistribute it and/or -* modify it under the terms of the GNU General Public License -* as published by the Free Software Foundation, version 2. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -*/ - - -#ifndef _ASM_RISCV_DEVICE_H -#define _ASM_RISCV_DEVICE_H - -#include <linux/sysfs.h> - -struct dev_archdata { -struct dma_map_ops *dma_ops; -}; - -struct pdev_archdata { -}; - -#endif /* _ASM_RISCV_DEVICE_H */
Quoted 10 lines
Quoted 7 lines
arch/riscv/include/asm/device.h line 27
Quoted 7 lines
arch/riscv/include/asm/device.h new file +5
-0+ +struct pdev_archdata { +}; + +#endif /* _ASM_RISCV_DEVICE_H */ Thanks!
Palmer Dabbelt
maintainerPATCH 7/9 RISC-V: Paging and MMU
In reply to Palmer DabbeltThis patch contains code to manage the RISC-V MMU, including definitions of the page tables and the page walking code.
--- arch/riscv/include/asm/mmu_context.h | 69 ++++++ arch/riscv/include/asm/page.h | 138 +++++++++++ arch/riscv/include/asm/pgalloc.h | 124 ++++++++++ arch/riscv/include/asm/pgtable-32.h | 25 ++ arch/riscv/include/asm/pgtable-64.h | 84 +++++++ arch/riscv/include/asm/pgtable-bits.h | 48 ++++ arch/riscv/include/asm/pgtable.h | 427 ++++++++++++++++++++++++++++++++++ arch/riscv/mm/fault.c | 280 ++++++++++++++++++++++ 8 files changed, 1195 insertions(+) create mode 100644 arch/riscv/include/asm/mmu_context.h create mode 100644 arch/riscv/include/asm/page.h create mode 100644 arch/riscv/include/asm/pgalloc.h create mode 100644 arch/riscv/include/asm/pgtable-32.h create mode 100644 arch/riscv/include/asm/pgtable-64.h create mode 100644 arch/riscv/include/asm/pgtable-bits.h create mode 100644 arch/riscv/include/asm/pgtable.h create mode 100644 arch/riscv/mm/fault.c
arch/riscv/include/asm/mmu_context.h new file +69 -0
@@ -0,0 +1,69 @@ +/* +* Copyright (C) 2012 Regents of the University of California +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation, version 2. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +*/ + +#ifndef _ASM_RISCV_MMU_CONTEXT_H +#define _ASM_RISCV_MMU_CONTEXT_H + +#include <asm-generic/mm_hooks.h> + +#include <linux/mm.h> +#include <linux/sched.h> +#include <asm/tlbflush.h> + +static inline void enter_lazy_tlb (struct mm_struct *mm, +struct task_struct *task) +{ +} + +/* Initialize context-related info for a new mm_struct */ +static inline int init_new_context (struct task_struct *task, +struct mm_struct *mm) +{ +return 0 ; +} + +static inline void destroy_context (struct mm_struct *mm) +{ +} + +static inline pgd_t *current_pgdir (void ) +{ +return pfn_to_virt (csr_read (sptbr) &SPTBR_PPN ); +} + +static inline void set_pgdir (pgd_t *pgd) +{ +csr_write (sptbr,virt_to_pfn (pgd) |SPTBR_MODE ); +} + +static inline void switch_mm (struct mm_struct *prev, +struct mm_struct *next,struct task_struct *task) +{ +if (likely (prev != next)) { +set_pgdir (next->pgd); +local_flush_tlb_all (); + } +} + +static inline void activate_mm (struct mm_struct *prev, +struct mm_struct *next) +{ +switch_mm (prev, next,NULL ); +} + +static inline void deactivate_mm (struct task_struct *task, +struct mm_struct *mm) +{ +} + +#endif /* _ASM_RISCV_MMU_CONTEXT_H */
arch/riscv/include/asm/page.h new file +138 -0
138 lines not on this page · raw message
arch/riscv/include/asm/pgalloc.h new file +124 -0
124 lines not on this page · raw message
arch/riscv/include/asm/pgtable-32.h new file +25 -0
@@ -0,0 +1,25 @@ +/* +* Copyright (C) 2012 Regents of the University of California +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation, version 2. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +*/ + +#ifndef _ASM_RISCV_PGTABLE_32_H +#define _ASM_RISCV_PGTABLE_32_H + +#include <asm-generic/pgtable-nopmd.h> +#include <linux/const.h> + +/* Size of region mapped by a page global directory */ +#define PGDIR_SHIFT 22 +#define PGDIR_SIZE (_AC(1, UL) << PGDIR_SHIFT) +#define PGDIR_MASK (~(PGDIR_SIZE - 1)) + +#endif /* _ASM_RISCV_PGTABLE_32_H */
arch/riscv/include/asm/pgtable-64.h new file +84 -0
84 lines not on this page · raw message
arch/riscv/include/asm/pgtable-bits.h new file +48 -0
48 lines not on this page · raw message
arch/riscv/include/asm/pgtable.h new file +427 -0
427 lines not on this page · raw message
arch/riscv/mm/fault.c new file +280 -0
280 lines not on this page · raw message
Signature · 1 line
2.13.0
Re: [PATCH 7/9] RISC-V: Paging and MMU
Quoted 5 lines · Palmer Dabbelt
arch/riscv/include/asm/page.h new file +0
-0
...
Quoted 1 line
+#ifdef
__KERNEL__
I think thats a given outside of uapi.
Cheers
James
Palmer Dabbelt
maintainerRe: [PATCH 7/9] RISC-V: Paging and MMU
Quoted 10 lines · On Wed, 28 Jun 2017 16:09:59 PDT (-0700), [email protected] wrote:
Quoted 5 lines · Palmer Dabbelt
arch/riscv/include/asm/page.h new file +0
-0...
Quoted 1 line
+#ifdef
__KERNEL__I think thats a given outside of uapi.
Thanks. I've removed those.
Palmer Dabbelt
maintainerPATCH 7/9 RISC-V: Paging and MMU
In reply to Palmer DabbeltThis patch contains code to manage the RISC-V MMU, including definitions of the page tables and the page walking code.
--- arch/riscv/include/asm/mmu_context.h | 69 ++++++ arch/riscv/include/asm/page.h | 138 +++++++++++ arch/riscv/include/asm/pgalloc.h | 124 ++++++++++ arch/riscv/include/asm/pgtable-32.h | 25 ++ arch/riscv/include/asm/pgtable-64.h | 84 +++++++ arch/riscv/include/asm/pgtable-bits.h | 48 ++++ arch/riscv/include/asm/pgtable.h | 427 ++++++++++++++++++++++++++++++++++ arch/riscv/mm/fault.c | 280 ++++++++++++++++++++++ 8 files changed, 1195 insertions(+) create mode 100644 arch/riscv/include/asm/mmu_context.h create mode 100644 arch/riscv/include/asm/page.h create mode 100644 arch/riscv/include/asm/pgalloc.h create mode 100644 arch/riscv/include/asm/pgtable-32.h create mode 100644 arch/riscv/include/asm/pgtable-64.h create mode 100644 arch/riscv/include/asm/pgtable-bits.h create mode 100644 arch/riscv/include/asm/pgtable.h create mode 100644 arch/riscv/mm/fault.c
arch/riscv/include/asm/mmu_context.h new file +69 -0
@@ -0,0 +1,69 @@ +/* +* Copyright (C) 2012 Regents of the University of California +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation, version 2. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +*/ + +#ifndef _ASM_RISCV_MMU_CONTEXT_H +#define _ASM_RISCV_MMU_CONTEXT_H + +#include <asm-generic/mm_hooks.h> + +#include <linux/mm.h> +#include <linux/sched.h> +#include <asm/tlbflush.h> + +static inline void enter_lazy_tlb (struct mm_struct *mm, +struct task_struct *task) +{ +} + +/* Initialize context-related info for a new mm_struct */ +static inline int init_new_context (struct task_struct *task, +struct mm_struct *mm) +{ +return 0 ; +} + +static inline void destroy_context (struct mm_struct *mm) +{ +} + +static inline pgd_t *current_pgdir (void ) +{ +return pfn_to_virt (csr_read (sptbr) &SPTBR_PPN ); +} + +static inline void set_pgdir (pgd_t *pgd) +{ +csr_write (sptbr,virt_to_pfn (pgd) |SPTBR_MODE ); +} + +static inline void switch_mm (struct mm_struct *prev, +struct mm_struct *next,struct task_struct *task) +{ +if (likely (prev != next)) { +set_pgdir (next->pgd); +local_flush_tlb_all (); + } +} + +static inline void activate_mm (struct mm_struct *prev, +struct mm_struct *next) +{ +switch_mm (prev, next,NULL ); +} + +static inline void deactivate_mm (struct task_struct *task, +struct mm_struct *mm) +{ +} + +#endif /* _ASM_RISCV_MMU_CONTEXT_H */
arch/riscv/include/asm/page.h new file +138 -0
138 lines not on this page · raw message
arch/riscv/include/asm/pgalloc.h new file +124 -0
124 lines not on this page · raw message
arch/riscv/include/asm/pgtable-32.h new file +25 -0
@@ -0,0 +1,25 @@ +/* +* Copyright (C) 2012 Regents of the University of California +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation, version 2. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +*/ + +#ifndef _ASM_RISCV_PGTABLE_32_H +#define _ASM_RISCV_PGTABLE_32_H + +#include <asm-generic/pgtable-nopmd.h> +#include <linux/const.h> + +/* Size of region mapped by a page global directory */ +#define PGDIR_SHIFT 22 +#define PGDIR_SIZE (_AC(1, UL) << PGDIR_SHIFT) +#define PGDIR_MASK (~(PGDIR_SIZE - 1)) + +#endif /* _ASM_RISCV_PGTABLE_32_H */
arch/riscv/include/asm/pgtable-64.h new file +84 -0
84 lines not on this page · raw message
arch/riscv/include/asm/pgtable-bits.h new file +48 -0
48 lines not on this page · raw message
arch/riscv/include/asm/pgtable.h new file +427 -0
427 lines not on this page · raw message
arch/riscv/mm/fault.c new file +280 -0
280 lines not on this page · raw message
Signature · 1 line
2.13.0
Palmer Dabbelt
maintainerPATCH 8/9 RISC-V: User-facing API
In reply to Palmer DabbeltThis patch contains code that is in some way visible to the user:
including via system calls, the VDSO, module loading and signal handling. It also contains some generic code that is ABI visible.
--- arch/riscv/include/asm/mmu.h | 26 +++ arch/riscv/include/asm/ptrace.h | 116 ++++++++++++ arch/riscv/include/asm/syscall.h | 90 ++++++++++ arch/riscv/include/asm/syscalls.h | 25 +++ arch/riscv/include/asm/unistd.h | 16 ++ arch/riscv/include/asm/vdso.h | 32 ++++ arch/riscv/include/uapi/asm/auxvec.h | 24 +++ arch/riscv/include/uapi/asm/bitsperlong.h | 25 +++ arch/riscv/include/uapi/asm/byteorder.h | 23 +++ arch/riscv/include/uapi/asm/elf.h | 83 +++++++++ arch/riscv/include/uapi/asm/ptrace.h | 87 +++++++++ arch/riscv/include/uapi/asm/sigcontext.h | 29 +++ arch/riscv/include/uapi/asm/siginfo.h | 24 +++ arch/riscv/include/uapi/asm/ucontext.h | 35 ++++ arch/riscv/include/uapi/asm/unistd.h | 26 +++ arch/riscv/kernel/module.c | 215 ++++++++++++++++++++++ arch/riscv/kernel/ptrace.c | 147 +++++++++++++++ arch/riscv/kernel/riscv_ksyms.c | 15 ++ arch/riscv/kernel/signal.c | 288 ++++++++++++++++++++++++++++++ arch/riscv/kernel/sys_riscv.c | 87 +++++++++ arch/riscv/kernel/syscall_table.c | 25 +++ arch/riscv/kernel/vdso/.gitignore | 1 + arch/riscv/kernel/vdso/cmpxchg32.S | 40 +++++ arch/riscv/kernel/vdso/cmpxchg64.S | 40 +++++ arch/riscv/kernel/vdso/sigreturn.S | 24 +++ arch/riscv/kernel/vdso/vdso.S | 27 +++ 26 files changed, 1570 insertions(+) create mode 100644 arch/riscv/include/asm/mmu.h create mode 100644 arch/riscv/include/asm/ptrace.h create mode 100644 arch/riscv/include/asm/syscall.h create mode 100644 arch/riscv/include/asm/syscalls.h create mode 100644 arch/riscv/include/asm/unistd.h create mode 100644 arch/riscv/include/asm/vdso.h create mode 100644 arch/riscv/include/uapi/asm/auxvec.h create mode 100644 arch/riscv/include/uapi/asm/bitsperlong.h create mode 100644 arch/riscv/include/uapi/asm/byteorder.h create mode 100644 arch/riscv/include/uapi/asm/elf.h create mode 100644 arch/riscv/include/uapi/asm/ptrace.h create mode 100644 arch/riscv/include/uapi/asm/sigcontext.h create mode 100644 arch/riscv/include/uapi/asm/siginfo.h create mode 100644 arch/riscv/include/uapi/asm/ucontext.h create mode 100644 arch/riscv/include/uapi/asm/unistd.h create mode 100644 arch/riscv/kernel/module.c create mode 100644 arch/riscv/kernel/ptrace.c create mode 100644 arch/riscv/kernel/riscv_ksyms.c create mode 100644 arch/riscv/kernel/signal.c create mode 100644 arch/riscv/kernel/sys_riscv.c create mode 100644 arch/riscv/kernel/syscall_table.c create mode 100644 arch/riscv/kernel/vdso/.gitignore create mode 100644 arch/riscv/kernel/vdso/cmpxchg32.S create mode 100644 arch/riscv/kernel/vdso/cmpxchg64.S create mode 100644 arch/riscv/kernel/vdso/sigreturn.S create mode 100644 arch/riscv/kernel/vdso/vdso.S
arch/riscv/include/asm/mmu.h new file +26 -0
@@ -0,0 +1,26 @@ +/* +* Copyright (C) 2012 Regents of the University of California +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation, version 2. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +*/ + + +#ifndef _ASM_RISCV_MMU_H +#define _ASM_RISCV_MMU_H + +#ifndef __ASSEMBLY__ + +typedef struct { +void *vdso; +}mm_context_t ; + +#endif /* __ASSEMBLY__ */ + +#endif /* _ASM_RISCV_MMU_H */
arch/riscv/include/asm/ptrace.h new file +116 -0
116 lines not on this page · raw message
arch/riscv/include/asm/syscall.h new file +90 -0
90 lines not on this page · raw message
arch/riscv/include/asm/syscalls.h new file +25 -0
@@ -0,0 +1,25 @@ +/* +* Copyright (C) 2014 Darius Rad <[email protected]> +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation, version 2. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +*/ + +#ifndef _ASM_RISCV_SYSCALLS_H +#define _ASM_RISCV_SYSCALLS_H + +#include <linux/linkage.h> + +#include <asm-generic/syscalls.h> + +/* kernel/sys_riscv.c */ +asmlinkage long sys_sysriscv (unsigned long ,unsigned long , +unsigned long ,unsigned long ); + +#endif /* _ASM_RISCV_SYSCALLS_H */
arch/riscv/include/asm/unistd.h new file +16 -0
@@ -0,0 +1,16 @@ +/* +* Copyright (C) 2012 Regents of the University of California +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation, version 2. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +*/ + +#define __ARCH_HAVE_MMU +#define __ARCH_WANT_SYS_CLONE +#include <uapi/asm/unistd.h>
arch/riscv/include/asm/vdso.h new file +32 -0
@@ -0,0 +1,32 @@ +/* +* Copyright (C) 2012 ARM Limited +* Copyright (C) 2014 Regents of the University of California +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +#ifndef _ASM_RISCV_VDSO_H +#define _ASM_RISCV_VDSO_H + +#include <linux/types.h> + +struct vdso_data { +}; + +#define VDSO_SYMBOL (base, name) \ +({ \ + extern const char __vdso_##name[]; \ + (void __user *)((unsigned long)(base) + __vdso_##name); \ +}) + +#endif /* _ASM_RISCV_VDSO_H */
arch/riscv/include/uapi/asm/auxvec.h new file +24 -0
@@ -0,0 +1,24 @@ +/* +* Copyright (C) 2012 ARM Ltd. +* Copyright (C) 2015 Regents of the University of California +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +#ifndef _UAPI_ASM_RISCV_AUXVEC_H +#define _UAPI_ASM_RISCV_AUXVEC_H + +/* vDSO location */ +#define AT_SYSINFO_EHDR 33 + +#endif /* _UAPI_ASM_RISCV_AUXVEC_H */
arch/riscv/include/uapi/asm/bitsperlong.h new file +25 -0
@@ -0,0 +1,25 @@ +/* +* Copyright (C) 2012 ARM Ltd. +* Copyright (C) 2015 Regents of the University of California +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +#ifndef _UAPI_ASM_RISCV_BITSPERLONG_H +#define _UAPI_ASM_RISCV_BITSPERLONG_H + +#define __BITS_PER_LONG (__SIZEOF_POINTER__ * 8) + +#include <asm-generic/bitsperlong.h> + +#endif /* _UAPI_ASM_RISCV_BITSPERLONG_H */
arch/riscv/include/uapi/asm/byteorder.h new file +23 -0
@@ -0,0 +1,23 @@ +/* +* Copyright (C) 2012 ARM Ltd. +* Copyright (C) 2015 Regents of the University of California +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +#ifndef _UAPI_ASM_RISCV_BYTEORDER_H +#define _UAPI_ASM_RISCV_BYTEORDER_H + +#include <linux/byteorder/little_endian.h> + +#endif /* _UAPI_ASM_RISCV_BYTEORDER_H */
arch/riscv/include/uapi/asm/elf.h new file +83 -0
83 lines not on this page · raw message
arch/riscv/include/uapi/asm/ptrace.h new file +87 -0
87 lines not on this page · raw message
arch/riscv/include/uapi/asm/sigcontext.h new file +29 -0
@@ -0,0 +1,29 @@ +/* +* Copyright (C) 2012 Regents of the University of California +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation, version 2. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +*/ + +#ifndef _UAPI_ASM_RISCV_SIGCONTEXT_H +#define _UAPI_ASM_RISCV_SIGCONTEXT_H + +#include <asm/ptrace.h> + +/* Signal context structure +* +* This contains the context saved before a signal handler is invoked; +* it is restored by sys_sigreturn / sys_rt_sigreturn. +*/ +struct sigcontext { +struct user_regs_struct sc_regs; +union __riscv_fp_state sc_fpregs; +}; + +#endif /* _UAPI_ASM_RISCV_SIGCONTEXT_H */
arch/riscv/include/uapi/asm/siginfo.h new file +24 -0
@@ -0,0 +1,24 @@ +/* +* Copyright (C) 2012 ARM Ltd. +* Copyright (C) 2016 SiFive, Inc. +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ +#ifndef __ASM_SIGINFO_H +#define __ASM_SIGINFO_H + +#define __ARCH_SI_PREAMBLE_SIZE (__SIZEOF_POINTER__ == 4 ? 12 : 16) + +#include <asm-generic/siginfo.h> + +#endif
arch/riscv/include/uapi/asm/ucontext.h new file +35 -0
@@ -0,0 +1,35 @@ +/* +* Copyright (C) 2012 ARM Ltd. +* Copyright (C) 2017 SiFive, Inc. +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see <http://www.gnu.org/licenses/>. +* +* This file was copied from arch/arm64/include/uapi/asm/ucontext.h +*/ +#ifndef _UAPI__ASM_UCONTEXT_H +#define _UAPI__ASM_UCONTEXT_H + +#include <linux/types.h> + +struct ucontext { +unsigned long uc_flags; +struct ucontext *uc_link; +stack_t uc_stack; +sigset_t uc_sigmask; +/* glibc uses a 1024-bit sigset_t */ +__u8 __unused[1024 /8 -sizeof (sigset_t)]; +/* last for future expansion */ +struct sigcontext uc_mcontext; +}; + +#endif /* _UAPI__ASM_UCONTEXT_H */
arch/riscv/include/uapi/asm/unistd.h new file +26 -0
@@ -0,0 +1,26 @@ +/* +* Copyright (C) 2012 Regents of the University of California +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation, version 2. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +*/ + +/* FIXME: This exists for now in order to maintain compatibility with our +* pre-upstream glibc, and will be removed for our real Linux submission. +*/ +#define __ARCH_WANT_RENAMEAT + +#include <asm-generic/unistd.h> + +/* +* These system calls add support for AMOs on RISC-V systems without support +* for the A extension. +*/ +#define __NR_sysriscv_cmpxchg32 (__NR_arch_specific_syscall + 0) +#define __NR_sysriscv_cmpxchg64 (__NR_arch_specific_syscall + 1)
arch/riscv/kernel/module.c new file +215 -0
215 lines not on this page · raw message
arch/riscv/kernel/ptrace.c new file +147 -0
147 lines not on this page · raw message
arch/riscv/kernel/riscv_ksyms.c new file +15 -0
@@ -0,0 +1,15 @@ +/* +* Copyright (C) 2017 Zihao Yu +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation. +*/ + +#include <linux/export.h> +#include <linux/uaccess.h> + +/* +* Assembly functions that may be used (directly or indirectly) by modules +*/ +EXPORT_SYMBOL (__copy_user);
arch/riscv/kernel/signal.c new file +288 -0
288 lines not on this page · raw message
arch/riscv/kernel/sys_riscv.c new file +87 -0
87 lines not on this page · raw message
arch/riscv/kernel/syscall_table.c new file +25 -0
@@ -0,0 +1,25 @@ +/* +* Copyright (C) 2009 Arnd Bergmann <[email protected]> +* Copyright (C) 2012 Regents of the University of California +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation, version 2. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +*/ + +#include <linux/syscalls.h> + +#include <asm/syscalls.h> + +#undef __SYSCALL +#define __SYSCALL (nr, call) [nr] = (call), + +void *sys_call_table[__NR_syscalls] = { + [0 ... __NR_syscalls -1 ] = sys_ni_syscall, +#include <asm/unistd.h> +};
arch/riscv/kernel/vdso/.gitignore new file +1 -0
@@ -0,0 +1 @@ +vdso.lds
arch/riscv/kernel/vdso/cmpxchg32.S new file +40 -0
@@ -0,0 +1,40 @@ +/* + * Copyright (C) 2017 SiFive + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation, version 2. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#include <linux/linkage.h> +#include <asm/unistd.h> + + .text +ENTRY(__vdso_cmpxchg32) + .cfi_startproc +#ifdef CONFIG_ISA_A +/* + * a0: ptr + * a1: compare value + * a2: exchange value + */ +0: + lr.w.aqrl t0, 0(a0) + bne t0, a1, 1f + sc.w.aqrl t1, a2, 0(a0) + bnez t1, 0b +1: + mv a0, t0 + ret +#else + li a7, __NR_sysriscv_cmpxchg32 + scall + ret +#endif + .cfi_endproc +ENDPROC(__vdso_cmpxchg32)
arch/riscv/kernel/vdso/cmpxchg64.S new file +40 -0
@@ -0,0 +1,40 @@ +/* + * Copyright (C) 2017 SiFive + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation, version 2. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#include <linux/linkage.h> +#include <asm/unistd.h> + + .text +ENTRY(__vdso_cmpxchg64) + .cfi_startproc +#ifdef CONFIG_ISA_A +/* + * a0: ptr + * a1: compare value + * a2: exchange value + */ +0: + lr.d.aqrl t0, 0(a0) + bne t0, a1, 1f + sc.d.aqrl t1, a2, 0(a0) + bnez t1, 0b +1: + mv a0, t0 + ret +#else + li a7, __NR_sysriscv_cmpxchg64 + scall + ret +#endif + .cfi_endproc +ENDPROC(__vdso_cmpxchg64)
arch/riscv/kernel/vdso/sigreturn.S new file +24 -0
@@ -0,0 +1,24 @@ +/* + * Copyright (C) 2014 Regents of the University of California + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation, version 2. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#include <linux/linkage.h> +#include <asm/unistd.h> + + .text +ENTRY(__vdso_rt_sigreturn) + .cfi_startproc + .cfi_signal_frame + li a7, __NR_rt_sigreturn + scall + .cfi_endproc +ENDPROC(__vdso_rt_sigreturn)
arch/riscv/kernel/vdso/vdso.S new file +27 -0
@@ -0,0 +1,27 @@ +/* + * Copyright (C) 2014 Regents of the University of California + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation, version 2. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#include <linux/init.h> +#include <linux/linkage.h> +#include <asm/page.h> + + __PAGE_ALIGNED_DATA + + .globl vdso_start, vdso_end + .balign PAGE_SIZE +vdso_start: + .incbin "arch/riscv/kernel/vdso/vdso.so" + .balign PAGE_SIZE +vdso_end: + + .previous
Signature · 1 line
2.13.0
Re: [PATCH 8/9] RISC-V: User-facing API
arch/riscv/kernel/sys_riscv.c line 51
Quoted 10 lines · Palmer Dabbelt
arch/riscv/kernel/sys_riscv.c new file +10
-0+ +SYSCALL_DEFINE3(sysriscv_cmpxchg32, unsigned long, arg1, unsigned long, arg2, + unsigned long, arg3) +{ +unsigned long flags; +unsigned long prev; +unsigned int *ptr; +unsigned int err; + + ptr = (unsigned int *)arg1;
Errm. Why isn't arg1 a proper pointer type and the arguments arg2/3 u32?
And please give the arguments a proper name, so it's obvious what is what.
SYSCALL_DEFINE3(sysriscv_cmpxchg32, u32 __user *, ptr, u32 new, u32 old)
Hmm?
arch/riscv/kernel/sys_riscv.c line 56
Quoted 5 lines
arch/riscv/kernel/sys_riscv.c new file +5
-0+if (!access_ok (VERIFY_WRITE , ptr,sizeof (unsigned int ))) +return -EFAULT ; + +preempt_disable (); +raw_local_irq_save (flags);
Why do you want to disable interrupts here? This is thread context and accessing user space memory, so the only protection this needs is against preemption.
arch/riscv/kernel/sys_riscv.c line 67
Quoted 11 lines
arch/riscv/kernel/sys_riscv.c new file +11
-0+ err =__get_user (prev, ptr); +if (likely (!err && prev == arg2)) + err =__put_user (arg3, ptr); +raw_local_irq_restore (flags); +preempt_enable (); + +return unlikely (err) ? err : prev; +} + +SYSCALL_DEFINE3(sysriscv_cmpxchg64, unsigned long, arg1, unsigned long, arg2, + unsigned long, arg3)
This one is even worse. How does this implement cmpxchg64 on a 32bit machine?
Answer: Not at all, because arg2 and 3 are 32bit ....
arch/riscv/kernel/sys_riscv.c line 51
Quoted 7 lines
arch/riscv/kernel/sys_riscv.c new file +7
-0+{ +unsigned long flags; +unsigned long prev; +unsigned int *ptr; +unsigned int err; + + ptr = (unsigned int *)arg1;
Type casting to random pointer types makes the code more obvious and safe, right? What the heck has a int pointer to do with u64?
arch/riscv/kernel/sys_riscv.c line 79
Quoted 5 lines
arch/riscv/kernel/sys_riscv.c new file +5
-0+if (!access_ok (VERIFY_WRITE , ptr,sizeof (unsigned long ))) +return -EFAULT ; + +preempt_disable (); +raw_local_irq_save (flags);
Same as above.
Review
Quoted 1 line
(quoted diff) +1
-0+ err = __get_user(prev, ptr);
Sigh. Type safety is overrated, right?
Thanks,
tglx
Re: [PATCH 8/9] RISC-V: User-facing API
Quoted 4 lines · Thomas Gleixner
Review
Quoted 1 line · Palmer Dabbelt
(quoted diff) +1
-0+ err = __get_user(prev, ptr);Sigh. Type safety is overrated, right?
But the comment above your __get_user() implementation says:
+ * @ptr must have pointer-to-simple-variable type, and the result of
+ * dereferencing @ptr must be assignable to @x without a cast.
Palmer Dabbelt
maintainerRe: [PATCH 8/9] RISC-V: User-facing API
In reply to Thomas GleixnerQuoted 14 lines · On Wed, 28 Jun 2017 14:49:44 PDT (-0700), [email protected] wrote:
arch/riscv/kernel/sys_riscv.c line 51
Quoted 10 lines · Palmer Dabbelt
arch/riscv/kernel/sys_riscv.c new file +10
-0+ +SYSCALL_DEFINE3(sysriscv_cmpxchg32, unsigned long, arg1, unsigned long, arg2, + unsigned long, arg3) +{ +unsigned long flags; +unsigned long prev; +unsigned int *ptr; +unsigned int err; + + ptr = (unsigned int *)arg1;Errm. Why isn't arg1 a proper pointer type and the arguments arg2/3 u32?
Quoted 5 lines
And please give the arguments a proper name, so it's obvious what is what.
SYSCALL_DEFINE3(sysriscv_cmpxchg32, u32 __user *, ptr, u32 new, u32 old)Hmm?
Sorry about that -- this used to be a multiplexed system call, and I guess I was just being stupid when demultiplexing it. That's much better, I've converted these over.
Quoted 9 lines
arch/riscv/kernel/sys_riscv.c line 56
Quoted 5 lines
arch/riscv/kernel/sys_riscv.c new file +5
-0+if (!access_ok (VERIFY_WRITE , ptr,sizeof (unsigned int ))) +return -EFAULT ; + +preempt_disable (); +raw_local_irq_save (flags);Why do you want to disable interrupts here? This is thread context and accessing user space memory, so the only protection this needs is against preemption.
OK, that makes sense.
Quoted 14 lines
arch/riscv/kernel/sys_riscv.c line 67
Quoted 11 lines
arch/riscv/kernel/sys_riscv.c new file +11
-0+ err =__get_user (prev, ptr); +if (likely (!err && prev == arg2)) + err =__put_user (arg3, ptr); +raw_local_irq_restore (flags); +preempt_enable (); + +return unlikely (err) ? err : prev; +} + +SYSCALL_DEFINE3(sysriscv_cmpxchg64, unsigned long, arg1, unsigned long, arg2, + unsigned long, arg3)This one is even worse. How does this implement cmpxchg64 on a 32bit machine?
Quoted 1 line
Answer: Not at all, because arg2 and 3 are 32bit ....
Thanks for catching that -- this was just a bit of copy-and-paste gone wrong.
Quoted 19 lines
arch/riscv/kernel/sys_riscv.c line 51
Quoted 7 lines
arch/riscv/kernel/sys_riscv.c new file +7
-0+{ +unsigned long flags; +unsigned long prev; +unsigned int *ptr; +unsigned int err; + + ptr = (unsigned int *)arg1;Type casting to random pointer types makes the code more obvious and safe, right? What the heck has a int pointer to do with u64?
arch/riscv/kernel/sys_riscv.c line 79
Quoted 5 lines
arch/riscv/kernel/sys_riscv.c new file +5
-0+if (!access_ok (VERIFY_WRITE , ptr,sizeof (unsigned long ))) +return -EFAULT ; + +preempt_disable (); +raw_local_irq_save (flags);Same as above.
Quoted 3 lines
Review
Quoted 1 line
(quoted diff) +1
-0+ err = __get_user(prev, ptr);Sigh. Type safety is overrated, right?
Again, this was due to the multiplexing that has been removed. I've gone ahead and cleaned up this system call here
https://github.com/riscv/riscv-linux/commit/1af46852b968db5af044ec3a0329a73116b3e6ec
We'll include this in our v4 patch set.
Thanks!
Re: [PATCH 8/9] RISC-V: User-facing API
In reply to Palmer DabbeltHi Palmer,
Quoted 6 lines · Palmer Dabbelt
arch/riscv/include/asm/syscalls.h new file +0
-0@@ -0,0 +1,25 @@
...
arch/riscv/include/asm/syscalls.h line 23
Quoted 3 lines
arch/riscv/include/asm/syscalls.h new file +3
-0+/* kernel/sys_riscv.c */ +asmlinkage long sys_sysriscv (unsigned long ,unsigned long , +unsigned long ,unsigned long );
You suggested in the cover letter this wasn't muxed any longer, maybe you should have a prototype for each of the cmpxchg syscalls instead?
Quoted 5 lines
arch/riscv/include/uapi/asm/ptrace.h new file +0
-0
...
Quoted 13 lines
arch/riscv/include/uapi/asm/ptrace.h new file +13
-0+struct __riscv_f_ext_state { +__u32 f[32 ]; +__u32 fcsr; +}; + +struct __riscv_d_ext_state { +__u64 f[32 ]; +__u32 fcsr; +}; + +struct __riscv_q_ext_state { +__u64 f[64 ] __attribute__((aligned (16 ))); +__u32 fcsr;
arch/riscv/include/uapi/asm/ptrace.h line 83
Quoted 10 lines
arch/riscv/include/uapi/asm/ptrace.h new file +10
-0+/* Reserved for expansion of sigcontext structure. Currently zeroed +* upon signal, and must be zero upon sigreturn. */ +__u32 reserved[3 ]; +}; + +union __riscv_fp_state { +struct __riscv_f_ext_state f; +struct __riscv_d_ext_state d; +struct __riscv_q_ext_state q; +};
Out of interest, how does one tell which fp format is in use?
Quoted 5 lines
arch/riscv/include/uapi/asm/ucontext.h new file +0
-0
...
arch/riscv/include/uapi/asm/ucontext.h line 33
Quoted 10 lines
arch/riscv/include/uapi/asm/ucontext.h new file +10
-0+struct ucontext { +unsigned long uc_flags; +struct ucontext *uc_link; +stack_t uc_stack; +sigset_t uc_sigmask; +/* glibc uses a 1024-bit sigset_t */ +__u8 __unused[1024 /8 -sizeof (sigset_t)]; +/* last for future expansion */ +struct sigcontext uc_mcontext; +};
Any particular reason not to use the asm-generic ucontext?
Quoted 5 lines
arch/riscv/include/uapi/asm/unistd.h new file +0
-0
...
arch/riscv/include/uapi/asm/unistd.h line 18
Quoted 5 lines
arch/riscv/include/uapi/asm/unistd.h new file +5
-0+/* FIXME: This exists for now in order to maintain compatibility with our +* pre-upstream glibc, and will be removed for our real Linux submission. +*/ +#define __ARCH_WANT_RENAMEAT +
Don't forget ;-)
Have you seen the patches floating around for dropping getrlimit/setrlimit (in favour of prlimit64) and fstatat64/fstat64 (in favour of statx)? I guess its no big deal.
arch/riscv/include/uapi/asm/unistd.h line 26
Quoted 8 lines
arch/riscv/include/uapi/asm/unistd.h new file +8
-0+#include <asm-generic/unistd.h> + +/* +* These system calls add support for AMOs on RISC-V systems without support +* for the A extension. +*/ +#define __NR_sysriscv_cmpxchg32 (__NR_arch_specific_syscall + 0) +#define __NR_sysriscv_cmpxchg64 (__NR_arch_specific_syscall + 1)
I think you need the magic __SYSCALL invocations here like in include/uapi/asm/unistd.h, otherwise they won't get included in your syscall table.
Quoted 5 lines
arch/riscv/kernel/ptrace.c new file +0
-0
...
Quoted 21 lines
arch/riscv/kernel/ptrace.c new file +21
-0+enum riscv_regset { +REGSET_X , +}; + +/* +* Get registers from task and ready the result for userspace. +*/ +static char *getregs (struct task_struct *child,struct pt_regs *uregs) +{ + *uregs = *task_pt_regs (child); +return (char *)uregs; +} + +/* Put registers back to task. */ +static void putregs (struct task_struct *child,struct pt_regs *uregs) +{ +struct pt_regs *regs =task_pt_regs (child); + *regs = *uregs; +} + +static int riscv_gpr_get(struct task_struct *target,
arch/riscv/kernel/ptrace.c line 59
Quoted 10 lines
arch/riscv/kernel/ptrace.c new file +10
-0+const struct user_regset *regset, + unsigned int pos, unsigned int count, + void *kbuf, void __user *ubuf) +{ + struct pt_regs regs; + +getregs (target, ®s); + +return user_regset_copyout (&pos, &count, &kbuf, &ubuf, ®s,0 , +sizeof (regs));
Shouldn't this be limited to sizeof(struct user_regs_struct)?
Why not copy straight out of task_pt_regs(target) instead of bouncing via the stack?
arch/riscv/kernel/ptrace.c line 71
Quoted 12 lines
arch/riscv/kernel/ptrace.c new file +12
-0+} + +static int riscv_gpr_set (struct task_struct *target, +const struct user_regset *regset, +unsigned int pos,unsigned int count, +const void *kbuf,const void __user *ubuf) +{ +int ret; +struct pt_regs regs; + + ret =user_regset_copyin (&pos, &count, &kbuf, &ubuf, ®s,0 , +sizeof (regs));
likewise.
In fact if userland supplies insufficient data then this looks vulnerable to a kernel stack data leak, since regs will remain partially uninitialised and then get written to the target regs where it can be read back again.
If you're going to bounce via the stack I think you need to fully initialise before using user_regset_copyin, or you could just copy directly into task_pt_regs(target) for now since, at least for the current internal struct pt_regs, the begining of pt_regs appears to match user_regs_struct.
arch/riscv/kernel/ptrace.c line 75
Quoted 4 lines
arch/riscv/kernel/ptrace.c new file +4
-0+if (ret) +return ret; + +putregs (target, ®s);
Similarly this needs to be careful not to overwrite the supervisor registers with whatever was on kernel stack (assuming only partially copied as suggested above)?
Quoted 4 lines
arch/riscv/kernel/ptrace.c new file +4
-0+ +return 0 ; +} +
arch/riscv/kernel/ptrace.c line 89
Quoted 10 lines
arch/riscv/kernel/ptrace.c new file +10
-0+ +static const struct user_regset riscv_user_regset[] = { + [REGSET_X ] = { + .core_note_type =NT_PRSTATUS , + .n =ELF_NGREG , + .size =sizeof (elf_greg_t), + .align =sizeof (elf_greg_t), + .get = &riscv_gpr_get, + .set = &riscv_gpr_set, + },
Will the FP registers get exposed at some point as well?
Quoted 5 lines
arch/riscv/kernel/sys_riscv.c new file +0
-0
...
arch/riscv/kernel/sys_riscv.c line 47
Quoted 5 lines
arch/riscv/kernel/sys_riscv.c new file +5
-0+SYSCALL_DEFINE3(sysriscv_cmpxchg32, unsigned long, arg1, unsigned long, arg2, + unsigned long, arg3) +{ +unsigned long flags; +unsigned long prev;
should that be unsigned int? Else on 64-bit half of it could be left uninitialised.
arch/riscv/kernel/sys_riscv.c
Quoted 1 line
arch/riscv/kernel/sys_riscv.c new file +1
-0+unsigned int *ptr;
should that be tagged with __user?
arch/riscv/kernel/sys_riscv.c line 51
Quoted 3 lines
arch/riscv/kernel/sys_riscv.c new file +3
-0+unsigned int err; + + ptr = (unsigned int *)arg1;
I presume you'll need to cast to __user __force to keep sparse happy here.
arch/riscv/kernel/sys_riscv.c line 61
Quoted 10 lines
arch/riscv/kernel/sys_riscv.c new file +10
-0+if (!access_ok (VERIFY_WRITE , ptr,sizeof (unsigned int ))) +return -EFAULT ; + +preempt_disable (); +raw_local_irq_save (flags); + err =__get_user (prev, ptr); +if (likely (!err && prev == arg2)) + err =__put_user (arg3, ptr); +raw_local_irq_restore (flags); +preempt_enable ();
Are user accesses safe from atomic context? What if it needs paging in?
You could disable page faults but then I think you'd have to handle the EFAULT again outside of atomic context to try getting it paged in, and then retry in atomic context. Or perhaps there's a cleaner way that doesn't come to mind late at night.
I'm not sure OTOH whether copy on write (i.e. affecting the __put_user() but not the __get_user() would be problematic. I suppose as long as it can safely allocate a page it should be fine... Should be possible to test using madvise(MADV_DONTNEED) (which I think makes pages use the zero page with copy-on-write).
Also if this is going to be included on SMP kernels (where I gather proper atomics are available), does it need an SMP safe version too which uses proper atomics?
arch/riscv/kernel/sys_riscv.c line 71
Quoted 10 lines
arch/riscv/kernel/sys_riscv.c new file +10
-0+ +return unlikely (err) ? err : prev; +} + +SYSCALL_DEFINE3(sysriscv_cmpxchg64, unsigned long, arg1, unsigned long, arg2, + unsigned long, arg3) +{ +unsigned long flags; +unsigned long prev; +unsigned int *ptr;
should that be unsigned long __user *?
arch/riscv/kernel/sys_riscv.c line 84
Quoted 13 lines
arch/riscv/kernel/sys_riscv.c new file +13
-0+unsigned int err; + + ptr = (unsigned int *)arg1; +if (!access_ok (VERIFY_WRITE , ptr,sizeof (unsigned long ))) +return -EFAULT ; + +preempt_disable (); +raw_local_irq_save (flags); + err =__get_user (prev, ptr); +if (likely (!err && prev == arg2)) + err =__put_user (arg3, ptr); +raw_local_irq_restore (flags); +preempt_enable ();
Likewise to other comments above.
This doesn't look much different to sysriscv_cmpxchg32 on 32-bit. Is it meant to be excluded from 32-bit kernels? If so definition of the __NR_ constant and the __SYSCALL magic in uapi/asm/unistd.h should I presume be conditional on the ABI.
arch/riscv/kernel/sys_riscv.c line 64
Quoted 3 lines
arch/riscv/kernel/sys_riscv.c new file +3
-0+ +return unlikely (err) ? err : prev; +}
Cheers
James
Palmer Dabbelt
maintainerRe: [PATCH 8/9] RISC-V: User-facing API
Quoted 10 lines · On Wed, 28 Jun 2017 15:42:37 PDT (-0700), [email protected] wrote:
Hi Palmer,
Quoted 6 lines · Palmer Dabbelt
arch/riscv/include/asm/syscalls.h new file +0
-0@@ -0,0 +1,25 @@...
Quoted 6 lines
arch/riscv/include/asm/syscalls.h line 23
Quoted 3 lines
arch/riscv/include/asm/syscalls.h new file +3
-0+/* kernel/sys_riscv.c */ +asmlinkage long sys_sysriscv (unsigned long ,unsigned long , +unsigned long ,unsigned long );You suggested in the cover letter this wasn't muxed any longer, maybe you should have a prototype for each of the cmpxchg syscalls instead?
Sorry, I just missed that. I'll fix it for the v4
diff --git a/arch/riscv/include/asm/syscalls.h b/arch/riscv/include/asm/syscalls.h index d85267c4f7ea..6490274fbb76 100644 --- a/arch/riscv/include/asm/syscalls.h +++ b/arch/riscv/include/asm/syscalls.h @@ -19,7 +19,7 @@ #include <asm-generic/syscalls.h>
/* kernel/sys_riscv.c */
-asmlinkage long sys_sysriscv(unsigned long, unsigned long,
- unsigned long, unsigned long);
+asmlinkage long sys_sysriscv_cmpxchg32(u32 __user * ptr, u32 new, u32 old); +asmlinkage long sys_sysriscv_cmpxchg64(u64 __user * ptr, u64 new, u64 old);
#endif /* _ASM_RISCV_SYSCALLS_H */
Quoted 23 lines
Quoted 5 lines
arch/riscv/include/uapi/asm/ptrace.h new file +0
-0...
Quoted 17 lines
arch/riscv/include/uapi/asm/ptrace.h new file +17
-0+struct __riscv_f_ext_state { +__u32 f[32 ]; +__u32 fcsr; +}; + +struct __riscv_d_ext_state { +__u64 f[32 ]; +__u32 fcsr; +}; + +struct __riscv_q_ext_state { +__u64 f[64 ] __attribute__((aligned (16 ))); +__u32 fcsr; +/* Reserved for expansion of sigcontext structure. Currently zeroed +* upon signal, and must be zero upon sigreturn. */ +__u32 reserved[3 ]; +};
Quoted 8 lines
arch/riscv/include/uapi/asm/ptrace.h line 83
Quoted 6 lines
arch/riscv/include/uapi/asm/ptrace.h new file +6
-0+ +union __riscv_fp_state { +struct __riscv_f_ext_state f; +struct __riscv_d_ext_state d; +struct __riscv_q_ext_state q; +};Out of interest, how does one tell which fp format is in use?
We might need another tag here -- I'll talk to Andrew (who did the glibc side of this) and make sure we can handle something like running F user code on a D kernel.
Quoted 6 lines
Quoted 5 lines
arch/riscv/include/uapi/asm/ucontext.h new file +0
-0...
Quoted 12 lines
arch/riscv/include/uapi/asm/ucontext.h line 33
Quoted 10 lines
arch/riscv/include/uapi/asm/ucontext.h new file +10
-0+struct ucontext { +unsigned long uc_flags; +struct ucontext *uc_link; +stack_t uc_stack; +sigset_t uc_sigmask; +/* glibc uses a 1024-bit sigset_t */ +__u8 __unused[1024 /8 -sizeof (sigset_t)]; +/* last for future expansion */ +struct sigcontext uc_mcontext; +};Any particular reason not to use the asm-generic ucontext?
In the generic ucontext, 'uc_sigmask' is at the end of the structure so it can be expanded. Since we want our mcontext to be expandable as well, we pre-allocate some expandable space for sigmask and then put mcontext at the end.
We stole this idea from arm64.
Quoted 14 lines
Quoted 5 lines
arch/riscv/include/uapi/asm/unistd.h new file +0
-0...
arch/riscv/include/uapi/asm/unistd.h line 18
Quoted 5 lines
arch/riscv/include/uapi/asm/unistd.h new file +5
-0+/* FIXME: This exists for now in order to maintain compatibility with our +* pre-upstream glibc, and will be removed for our real Linux submission. +*/ +#define __ARCH_WANT_RENAMEAT +Don't forget ;-)
Quoted 3 lines
Have you seen the patches floating around for dropping getrlimit/setrlimit (in favour of prlimit64) and fstatat64/fstat64 (in favour of statx)? I guess its no big deal.
Yes, but we're trying to make this glibc release so we decided to hold off on them. If we can't make it then we might reconsider, but they seem like fairly small issues.
Quoted 4 lines
Quoted 4 lines
arch/riscv/include/uapi/asm/unistd.h new file +4
-0+#include <asm-generic/unistd.h> + +/* +* These system calls add support for AMOs on RISC-V systems without support
Quoted 8 lines
arch/riscv/include/uapi/asm/unistd.h line 26
Quoted 4 lines
+ * for the A extension.
+ */arch/riscv/include/uapi/asm/unistd.h new file +2
-0+#define __NR_sysriscv_cmpxchg32 (__NR_arch_specific_syscall + 0) +#define __NR_sysriscv_cmpxchg64 (__NR_arch_specific_syscall + 1)I think you need the magic
__SYSCALLinvocations here like ininclude/uapi/asm/unistd.h, otherwise they won't get included in your syscall table.
OK, I've added those.
diff --git a/arch/riscv/include/uapi/asm/unistd.h b/arch/riscv/include/uapi/asm/unistd.h
index 7e3909ac3c18..3cdb32912ac7 100644
--- a/arch/riscv/include/uapi/asm/unistd.h
+++ b/arch/riscv/include/uapi/asm/unistd.h
@@ -23,4 +23,6 @@
* for the A extension.
*/
#define __NR_sysriscv_cmpxchg32 (__NR_arch_specific_syscall + 0)
+__SYSCALL(__NR_sysriscv_cmpxchg32, sys_sysriscv_cmpxchg32)
#define __NR_sysriscv_cmpxchg64 (__NR_arch_specific_syscall + 1)
+__SYSCALL(__NR_sysriscv_cmpxchg64, sys_sysriscv_cmpxchg64)Quoted 40 lines
Quoted 5 lines
arch/riscv/kernel/ptrace.c new file +0
-0...
Quoted 21 lines
arch/riscv/kernel/ptrace.c new file +21
-0+enum riscv_regset { +REGSET_X , +}; + +/* +* Get registers from task and ready the result for userspace. +*/ +static char *getregs (struct task_struct *child,struct pt_regs *uregs) +{ + *uregs = *task_pt_regs (child); +return (char *)uregs; +} + +/* Put registers back to task. */ +static void putregs (struct task_struct *child,struct pt_regs *uregs) +{ +struct pt_regs *regs =task_pt_regs (child); + *regs = *uregs; +} + +static int riscv_gpr_get(struct task_struct *target,arch/riscv/kernel/ptrace.c line 59
Quoted 10 lines
arch/riscv/kernel/ptrace.c new file +10
-0+const struct user_regset *regset, + unsigned int pos, unsigned int count, + void *kbuf, void __user *ubuf) +{ + struct pt_regs regs; + +getregs (target, ®s); + +return user_regset_copyout (&pos, &count, &kbuf, &ubuf, ®s,0 , +sizeof (regs));Shouldn't this be limited to
sizeof(struct user_regs_struct)?
Quoted 2 lines
Why not copy straight out of
task_pt_regs(target)instead of bouncing via the stack?
IIRC this code used to be more complicated as it supported the two different ptrace register APIs. There's no reason to have this function now, so I've just pulled into the only caller.
Quoted 71 lines
arch/riscv/kernel/ptrace.c line 71
Quoted 12 lines
arch/riscv/kernel/ptrace.c new file +12
-0+} + +static int riscv_gpr_set (struct task_struct *target, +const struct user_regset *regset, +unsigned int pos,unsigned int count, +const void *kbuf,const void __user *ubuf) +{ +int ret; +struct pt_regs regs; + + ret =user_regset_copyin (&pos, &count, &kbuf, &ubuf, ®s,0 , +sizeof (regs));likewise.
In fact if userland supplies insufficient data then this looks vulnerable to a kernel stack data leak, since regs will remain partially uninitialised and then get written to the target regs where it can be read back again.
If you're going to bounce via the stack I think you need to fully initialise before using
user_regset_copyin, or you could just copy directly intotask_pt_regs(target)for now since, at least for the current internal structpt_regs, the begining ofpt_regsappears to matchuser_regs_struct.arch/riscv/kernel/ptrace.c line 75
Quoted 4 lines
arch/riscv/kernel/ptrace.c new file +4
-0+if (ret) +return ret; + +putregs (target, ®s);Similarly this needs to be careful not to overwrite the supervisor registers with whatever was on kernel stack (assuming only partially copied as suggested above)?
Quoted 4 lines
arch/riscv/kernel/ptrace.c new file +4
-0+ +return 0 ; +} +arch/riscv/kernel/ptrace.c line 89
Quoted 10 lines
arch/riscv/kernel/ptrace.c new file +10
-0+ +static const struct user_regset riscv_user_regset[] = { + [REGSET_X ] = { + .core_note_type =NT_PRSTATUS , + .n =ELF_NGREG , + .size =sizeof (elf_greg_t), + .align =sizeof (elf_greg_t), + .get = &riscv_gpr_get, + .set = &riscv_gpr_set, + },Will the FP registers get exposed at some point as well?
Quoted 5 lines
arch/riscv/kernel/sys_riscv.c new file +0
-0...
arch/riscv/kernel/sys_riscv.c line 47
Quoted 5 lines
arch/riscv/kernel/sys_riscv.c new file +5
-0+SYSCALL_DEFINE3(sysriscv_cmpxchg32, unsigned long, arg1, unsigned long, arg2, + unsigned long, arg3) +{ +unsigned long flags; +unsigned long prev;should that be unsigned int? Else on 64-bit half of it could be left uninitialised.
arch/riscv/kernel/sys_riscv.c
Quoted 1 line
arch/riscv/kernel/sys_riscv.c new file +1
-0+unsigned int *ptr;should that be tagged with
__user?
Quoted 6 lines
arch/riscv/kernel/sys_riscv.c line 51
Quoted 3 lines
arch/riscv/kernel/sys_riscv.c new file +3
-0+unsigned int err; + + ptr = (unsigned int *)arg1;I presume you'll need to cast to
__user__forceto keep sparse happy here.
This should be fixed, I was just lazy when converting from the multiplexed syscall version.
Quoted 25 lines
arch/riscv/kernel/sys_riscv.c line 61
Quoted 11 lines
arch/riscv/kernel/sys_riscv.c new file +10
-0+if (!access_ok (VERIFY_WRITE , ptr,sizeof (unsigned int ))) +return -EFAULT ; + +preempt_disable (); +raw_local_irq_save (flags); + err =__get_user (prev, ptr); +if (likely (!err && prev == arg2)) + err =__put_user (arg3, ptr); +raw_local_irq_restore (flags); +preempt_enable ();Are user accesses safe from atomic context? What if it needs paging in?
You could disable page faults but then I think you'd have to handle the EFAULT again outside of atomic context to try getting it paged in, and then retry in atomic context. Or perhaps there's a cleaner way that doesn't come to mind late at night.
I'm not sure OTOH whether copy on write (i.e. affecting the
__put_user()but not the__get_user()would be problematic. I suppose as long as it can safely allocate a page it should be fine... Should be possible to test usingmadvise(MADV_DONTNEED)(which I think makes pages use the zero page with copy-on-write).
Quoted 3 lines
Also if this is going to be included on SMP kernels (where I gather proper atomics are available), does it need an SMP safe version too which uses proper atomics?
On 64-bit machines with the A extension (which is required for SMP) then that's the right thing to do -- we're actually doing it in the VDSO right now, but there's no reason not to do it in the syscall as well.
On 32-bit machines, I think it's still not safe as we don't have a 64-bit CAS even with the A extension. I think the best thing to do is actually to disallow the 64-bit CAS on 32-bit machines -- we could disallow this on just SMP machines, but I think it's saner do disallow it everywhere so we don't end up with binaries that won't run on SMP kernels.
I'll try to figure out if userspace can work without it, but I think it should be OK as we don't have double-word CAS on 64-bit.
Quoted 29 lines
arch/riscv/kernel/sys_riscv.c line 71
Quoted 10 lines
arch/riscv/kernel/sys_riscv.c new file +10
-0+ +return unlikely (err) ? err : prev; +} + +SYSCALL_DEFINE3(sysriscv_cmpxchg64, unsigned long, arg1, unsigned long, arg2, + unsigned long, arg3) +{ +unsigned long flags; +unsigned long prev; +unsigned int *ptr;should that be unsigned long
__user*?arch/riscv/kernel/sys_riscv.c line 84
Quoted 13 lines
arch/riscv/kernel/sys_riscv.c new file +13
-0+unsigned int err; + + ptr = (unsigned int *)arg1; +if (!access_ok (VERIFY_WRITE , ptr,sizeof (unsigned long ))) +return -EFAULT ; + +preempt_disable (); +raw_local_irq_save (flags); + err =__get_user (prev, ptr); +if (likely (!err && prev == arg2)) + err =__put_user (arg3, ptr); +raw_local_irq_restore (flags); +preempt_enable ();Likewise to other comments above.
Quoted 4 lines
This doesn't look much different to
sysriscv_cmpxchg32on 32-bit. Is it meant to be excluded from 32-bit kernels? If so definition of the__NR_constant and the__SYSCALLmagic inuapi/asm/unistd.hshould I presume be conditional on the ABI.
Sorry, that was just a copy-and-paste error. This is intended to actually be a 64-bit CAS on 32-bit machines -- though maybe that was a bad idea.
Re: [PATCH 8/9] RISC-V: User-facing API
Quoted 21 lines · Palmer Dabbelt
Quoted 7 lines · On Wed, 28 Jun 2017 15:42:37 PDT (-0700), [email protected] wrote:
Quoted 5 lines · Palmer Dabbelt
arch/riscv/include/uapi/asm/ucontext.h new file +0
-0...
Quoted 12 lines
arch/riscv/include/uapi/asm/ucontext.h line 33
Quoted 10 lines
arch/riscv/include/uapi/asm/ucontext.h new file +10
-0+struct ucontext { +unsigned long uc_flags; +struct ucontext *uc_link; +stack_t uc_stack; +sigset_t uc_sigmask; +/* glibc uses a 1024-bit sigset_t */ +__u8 __unused[1024 /8 -sizeof (sigset_t)]; +/* last for future expansion */ +struct sigcontext uc_mcontext; +};Any particular reason not to use the asm-generic ucontext?
Quoted 6 lines
In the generic ucontext, '
uc_sigmask' is at the end of the structure so it can be expanded. Since we want our mcontext to be expandable as well, we pre-allocate some expandable space for sigmask and then put mcontext at the end.We stole this idea from arm64.
Curious. __unused seems like overkill to be honest given that expanding the number of signals up to 128 causes other issues (as discovered on MIPS e.g. the waitpid() status, with stopsig not fitting below the exit code (shift 8) and core dump flag (bit 7)), but perhaps it could be carefully expanded by splitting the stopsig field.
Looks harmless here I suppose so I defer to others. If it is the preferred approach does it make sense to make it the "default" for new architectures at some point?
Cheers
James
Palmer Dabbelt
maintainerRe: [PATCH 8/9] RISC-V: User-facing API
Quoted 27 lines · On Mon, 03 Jul 2017 16:06:39 PDT (-0700), [email protected] wrote:
Quoted 26 lines · Palmer Dabbelt
Quoted 7 lines · On Wed, 28 Jun 2017 15:42:37 PDT (-0700), [email protected] wrote:
Quoted 5 lines · Palmer Dabbelt
arch/riscv/include/uapi/asm/ucontext.h new file +0
-0...
Quoted 12 lines
arch/riscv/include/uapi/asm/ucontext.h line 33
Quoted 10 lines
arch/riscv/include/uapi/asm/ucontext.h new file +10
-0+struct ucontext { +unsigned long uc_flags; +struct ucontext *uc_link; +stack_t uc_stack; +sigset_t uc_sigmask; +/* glibc uses a 1024-bit sigset_t */ +__u8 __unused[1024 /8 -sizeof (sigset_t)]; +/* last for future expansion */ +struct sigcontext uc_mcontext; +};Any particular reason not to use the asm-generic ucontext?
In the generic ucontext, '
uc_sigmask' is at the end of the structure so it can be expanded. Since we want our mcontext to be expandable as well, we pre-allocate some expandable space for sigmask and then put mcontext at the end.
Quoted 7 lines
Quoted 1 line
We stole this idea from arm64.
Curious.
__unusedseems like overkill to be honest given that expanding the number of signals up to 128 causes other issues (as discovered on MIPS e.g. thewaitpid()status, with stopsig not fitting below the exit code (shift 8) and core dump flag (bit 7)), but perhaps it could be carefully expanded by splitting the stopsig field.
Sorry, I don't understand the intricacies of this in the slightest. In general we try to avoid surprises in software land in RISC-V, so whenever we do something we go look at the most popular architectures (Intel and ARM) and try to ensure we don't paint ourselves into any corners that they didn't.
Quoted 3 lines
Looks harmless here I suppose so I defer to others. If it is the preferred approach does it make sense to make it the "default" for new architectures at some point?
Again, this isn't really my thing, but we chose this because we thought it was the sane way to do it. Unless we're doing something silly, I don't see why it wouldn't be a reasonable default. This is predicated on having expandable architectural state, otherwise putting sigmask at the end seems sane.
Palmer Dabbelt
maintainerPATCH 9/9 RISC-V: Build Infastructure
In reply to Palmer DabbeltThis patch contains all the build infastructure that actually enables the RISC-V port. This includes Makefiles, linker scripts, and Kconfig files. It also contains the only top-level change, which adds RISC-V to the list of architectures that need a sed run to produce the ARCH variable when building locally.
--- Makefile | 3 +- arch/riscv/Kconfig | 318 ++++++++++++++++++++++++++++++ arch/riscv/Makefile | 64 ++++++ arch/riscv/configs/freedom-u500_defconfig | 53 +++++ arch/riscv/configs/spike32_defconfig | 50 +++++ arch/riscv/configs/spike64_defconfig | 46 +++++ arch/riscv/include/asm/Kbuild | 60 ++++++ arch/riscv/include/uapi/asm/Kbuild | 4 + arch/riscv/kernel/.gitignore | 1 + arch/riscv/kernel/Makefile | 16 ++ arch/riscv/kernel/vdso/Makefile | 61 ++++++ arch/riscv/kernel/vdso/vdso.lds.S | 77 ++++++++ arch/riscv/kernel/vmlinux.lds.S | 92 +++++++++ arch/riscv/lib/Makefile | 5 + arch/riscv/mm/Makefile | 1 + 15 files changed, 850 insertions(+), 1 deletion(-) create mode 100644 arch/riscv/Kconfig create mode 100644 arch/riscv/Makefile create mode 100644 arch/riscv/configs/freedom-u500_defconfig create mode 100644 arch/riscv/configs/spike32_defconfig create mode 100644 arch/riscv/configs/spike64_defconfig create mode 100644 arch/riscv/include/asm/Kbuild create mode 100644 arch/riscv/include/uapi/asm/Kbuild create mode 100644 arch/riscv/kernel/.gitignore create mode 100644 arch/riscv/kernel/Makefile create mode 100644 arch/riscv/kernel/vdso/Makefile create mode 100644 arch/riscv/kernel/vdso/vdso.lds.S create mode 100644 arch/riscv/kernel/vmlinux.lds.S create mode 100644 arch/riscv/lib/Makefile create mode 100644 arch/riscv/mm/Makefile
Makefile +2 -1
@@ -232,7 +232,8 @@ SUBARCH := $(shell uname -m | sed -e s/i.86/x86/ -e s/x86_64/x86/ \ -e s/arm.*/arm/ -e s/sa110/arm/ \ -e s/s390x/s390/ -e s/parisc64/parisc/ \ -e s/ppc.*/powerpc/ -e s/mips.*/mips/ \ - -e s/sh[234].*/sh/ -e s/aarch64.*/arm64/ ) + -e s/sh[234].*/sh/ -e s/aarch64.*/arm64/ \ + -e s/riscv.*/riscv/) # Cross compiling and selecting different set of gcc/bin-utils # ---------------------------------------------------------------------------
arch/riscv/Kconfig new file +318 -0
318 lines not on this page · raw message
arch/riscv/Makefile new file +64 -0
64 lines not on this page · raw message
arch/riscv/configs/freedom-u500_defconfig new file +53 -0
53 lines not on this page · raw message
arch/riscv/configs/spike32_defconfig new file +50 -0
50 lines not on this page · raw message
arch/riscv/configs/spike64_defconfig new file +46 -0
46 lines not on this page · raw message
arch/riscv/include/asm/Kbuild new file +60 -0
60 lines not on this page · raw message
arch/riscv/include/uapi/asm/Kbuild new file +4 -0
@@ -0,0 +1,4 @@ +# UAPI Header export list +include include/uapi/asm-generic/Kbuild.asm + +generic-y += setup.h
arch/riscv/kernel/.gitignore new file +1 -0
@@ -0,0 +1 @@ +/vmlinux.lds
arch/riscv/kernel/Makefile new file +16 -0
@@ -0,0 +1,16 @@ +# +# Makefile for the RISC-V Linux kernel +# + +extra-y := head.o vmlinux.lds + +obj-y := cpu.o entry.o irq.o process.o ptrace.o reset.o setup.o \ + signal.o syscall_table.o sys_riscv.o time.o traps.o \ + riscv_ksyms.o stacktrace.o vdso.o cacheinfo.o vdso/ + +CFLAGS_setup.o := -mcmodel=medany + +obj-$(CONFIG_SMP) += smpboot.o smp.o +obj-$(CONFIG_MODULES) += module.o + +clean:
arch/riscv/kernel/vdso/Makefile new file +61 -0
61 lines not on this page · raw message
arch/riscv/kernel/vdso/vdso.lds.S new file +77 -0
77 lines not on this page · raw message
arch/riscv/kernel/vmlinux.lds.S new file +92 -0
92 lines not on this page · raw message
arch/riscv/lib/Makefile new file +5 -0
@@ -0,0 +1,5 @@ +lib-y := delay.o memcpy.o memset.o uaccess.o + +ifeq ($(CONFIG_64BIT),) +lib-y += udivdi3.o +endif
arch/riscv/mm/Makefile new file +1 -0
@@ -0,0 +1 @@ +obj-y := init.o fault.o extable.o ioremap.o
Signature · 1 line
2.13.0
Re: [PATCH 9/9] RISC-V: Build Infastructure
Quoted 8 lines · Palmer Dabbelt
This patch contains all the build infastructure that actually enables the RISC-V port. This includes Makefiles, linker scripts, and
Kconfigfiles. It also contains the only top-level change, which adds RISC-V to the list of architectures that need a sed run to produce the ARCH variable when building locally.Signed-off-by Palmer Dabbelt <[email protected]>---
[...]
arch/riscv/configs/freedom-u500_defconfig line 1
Quoted 7 lines
arch/riscv/configs/freedom-u500_defconfig new file +1
-0@@ -0,0 +1,53 @@ +CONFIG_CROSS_COMPILE="riscv64-unknown-linux-gnu-"
Hello Palmer,
just a tiny nitpick: defconfigs shouldn't predefine a crosscompiler prefix. That has already been fixed in the other defconfigs at some earlier point in time, but IIRC the freedom-u500_defconfig got added later on and it was probably overlooked then.
Regards,
Karsten
Signature · 3 lines
Gem. Par. 28 Abs. 4 Bundesdatenschutzgesetz widerspreche ich der Nutzung sowie der Weitergabe meiner personenbezogenen Daten für Zwecke der Werbung sowie der Markt- oder Meinungsforschung.
Palmer Dabbelt
maintainerRe: [PATCH 9/9] RISC-V: Build Infastructure
Quoted 10 lines · On Wed, 28 Jun 2017 14:05:14 PDT (-0700), [email protected] wrote:
Quoted 8 lines · Palmer Dabbelt
This patch contains all the build infastructure that actually enables the RISC-V port. This includes Makefiles, linker scripts, and
Kconfigfiles. It also contains the only top-level change, which adds RISC-V to the list of architectures that need a sed run to produce the ARCH variable when building locally.Signed-off-by Palmer Dabbelt <[email protected]>---
[...]
Quoted 12 lines
arch/riscv/configs/freedom-u500_defconfig line 1
Quoted 7 lines
arch/riscv/configs/freedom-u500_defconfig new file +1
-0@@ -0,0 +1,53 @@ +CONFIG_CROSS_COMPILE="riscv64-unknown-linux-gnu-"just a tiny nitpick: defconfigs shouldn't predefine a crosscompiler prefix. That has already been fixed in the other defconfigs at some earlier point in time, but IIRC the freedom-u500_defconfig got added later on and it was probably overlooked then.
Oh, sorry about that -- you're right, I just missed that one as it wasn't in the original patch set.
I'll squash this in when we do a v4.
commit 1a262894827be647d55016da09f61eb49962dd7d
Author: Palmer Dabbelt <[email protected]> Date: Wed Jun 28 14:11:17 2017 -0700
Don't define CROSS_COMPILE in the u500 defconfig
arch/riscv/configs/freedom-u500_defconfig +0 -1
@@ -1,4 +1,3 @@ -CONFIG_CROSS_COMPILE="riscv64-unknown-linux-gnu-" CONFIG_DEFAULT_HOSTNAME="ucbvax" # CONFIG_CROSS_MEMORY_ATTACH is not set # CONFIG_FHANDLE is not set
Re: [PATCH 9/9] RISC-V: Build Infastructure
In reply to Palmer DabbeltHi Palmer,
Quoted 1 line · Palmer Dabbelt
arch/riscv/Kconfig new file +1
-0+ select SYSRISCV_ATOMIC if !ISA_A
...
arch/riscv/Kconfig line 170
Quoted 13 lines
arch/riscv/Kconfig new file +13
-0+config SYSRISCV_ATOMIC + bool "Include support for atomic operation syscalls" + default !ISA_A + help + If atomic memory instructions are present, i.e., + CONFIG_ISA_A, this includes support for the syscall that + provides atomic accesses. This is only useful to run + binaries that require atomic access but were compiled with + -mno-atomic. + + If CONFIG_ISA_A is unset, this option is mandatory. + + If you don't know what to do here, say N.
Can this be removed now that you mentioned the atomics syscall being mandatory? I can't find any other references to it.
Cheers
James
Palmer Dabbelt
maintainerRe: [PATCH 9/9] RISC-V: Build Infastructure
Quoted 5 lines · On Wed, 28 Jun 2017 14:25:00 PDT (-0700), [email protected] wrote:
Hi Palmer,
Quoted 1 line · Palmer Dabbelt
arch/riscv/Kconfig new file +1
-0+ select SYSRISCV_ATOMIC if !ISA_A...
Quoted 16 lines
arch/riscv/Kconfig line 170
Quoted 13 lines
arch/riscv/Kconfig new file +13
-0+config SYSRISCV_ATOMIC + bool "Include support for atomic operation syscalls" + default !ISA_A + help + If atomic memory instructions are present, i.e., + CONFIG_ISA_A, this includes support for the syscall that + provides atomic accesses. This is only useful to run + binaries that require atomic access but were compiled with + -mno-atomic. + + If CONFIG_ISA_A is unset, this option is mandatory. + + If you don't know what to do here, say N.Can this be removed now that you mentioned the atomics syscall being mandatory? I can't find any other references to it.
Oh, sorry, I must have just missed it when swizzling that around. I'll remove it as part of our v4.
diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig index 38c8112861fd..9f587af28910 100644 --- a/arch/riscv/Kconfig +++ b/arch/riscv/Kconfig @@ -155,20 +155,6 @@ config ISA_A
If you don't know what to do here, say Y.
-config SYSRISCV_ATOMIC
- bool "Include support for atomic operation syscalls" - default !ISA_A - help - If atomic memory instructions are present, i.e., - CONFIG_ISA_A, this includes support for the syscall that - provides atomic accesses. This is only useful to run - binaries that require atomic access but were compiled with - -mno-atomic.
-
- If CONFIG_ISA_A is unset, this option is mandatory.
-
- If you don't know what to do here, say N.
-
config RV_PUM
def_bool y
prompt "Protect User Memory" if EXPERT
Thanks for catching this!
Re: [PATCH 9/9] RISC-V: Build Infastructure
In reply to Palmer DabbeltQuoted 6 lines · Palmer Dabbelt
arch/riscv/kernel/Makefile new file +0
-0
arch/riscv/kernel/Makefile line 9
Quoted 9 lines
arch/riscv/kernel/Makefile new file +9
-0@@ -0,0 +1,16 @@ +# +# Makefile for the RISC-V Linux kernel +# + +extra-y := head.o vmlinux.lds + +obj-y := cpu.o entry.o irq.o process.o ptrace.o reset.o setup.o \ + signal.o syscall_table.o sys_riscv.o time.o traps.o \ + riscv_ksyms.o stacktrace.o vdso.o cacheinfo.o vdso/
I would suggest splitting these sort of things onto separate lines. It'll make later changes much more readable (especially when you're escaping newlines) as well as avoiding conflicts.
arch/riscv/kernel/Makefile line 13
Quoted 4 lines
arch/riscv/kernel/Makefile new file +4
-0+ +CFLAGS_setup.o := -mcmodel=medany + +obj-$(CONFIG_SMP) += smpboot.o smp.o
same here
arch/riscv/lib/Makefile line 1
Quoted 11 lines
arch/riscv/kernel/Makefile new file +3
-0+obj-$(CONFIG_MODULES) += module.o + +clean:arch/riscv/lib/Makefile new file +1
-0@@ -0,0 +1,5 @@ +lib-y := delay.o memcpy.o memset.o uaccess.o
and here
arch/riscv/lib/Makefile line 5
Quoted 4 lines
arch/riscv/lib/Makefile new file +4
-0+ +ifeq ($(CONFIG_64BIT),) +lib-y += udivdi3.o +endif
Would this work?
lib-$(CONFIG_32BIT) += udivdi3.o
arch/riscv/mm/Makefile line 1
Quoted 7 lines
arch/riscv/mm/Makefile new file +1
-0@@ -0,0 +1 @@ +obj-y := init.o fault.o extable.o ioremap.o
and here
Cheers
James
Palmer Dabbelt
maintainerRe: [PATCH 9/9] RISC-V: Build Infastructure
Quoted 51 lines · On Wed, 28 Jun 2017 15:54:42 PDT (-0700), [email protected] wrote:
Quoted 6 lines · Palmer Dabbelt
arch/riscv/kernel/Makefile new file +0
-0arch/riscv/kernel/Makefile line 9
Quoted 9 lines
arch/riscv/kernel/Makefile new file +9
-0@@ -0,0 +1,16 @@ +# +# Makefile for the RISC-V Linux kernel +# + +extra-y := head.o vmlinux.lds + +obj-y := cpu.o entry.o irq.o process.o ptrace.o reset.o setup.o \ + signal.o syscall_table.o sys_riscv.o time.o traps.o \ + riscv_ksyms.o stacktrace.o vdso.o cacheinfo.o vdso/I would suggest splitting these sort of things onto separate lines. It'll make later changes much more readable (especially when you're escaping newlines) as well as avoiding conflicts.
arch/riscv/kernel/Makefile line 13
Quoted 4 lines
arch/riscv/kernel/Makefile new file +4
-0+ +CFLAGS_setup.o := -mcmodel=medany + +obj-$(CONFIG_SMP) += smpboot.o smp.osame here
arch/riscv/lib/Makefile line 1
Quoted 11 lines
arch/riscv/kernel/Makefile new file +3
-0+obj-$(CONFIG_MODULES) += module.o + +clean:arch/riscv/lib/Makefile new file +1
-0@@ -0,0 +1,5 @@ +lib-y := delay.o memcpy.o memset.o uaccess.oand here
arch/riscv/lib/Makefile line 5
Quoted 4 lines
arch/riscv/lib/Makefile new file +4
-0+ +ifeq ($(CONFIG_64BIT),) +lib-y += udivdi3.o +endifWould this work?
lib-$(CONFIG_32BIT) += udivdi3.o
Quoted 9 lines
arch/riscv/mm/Makefile line 1
Quoted 7 lines
arch/riscv/mm/Makefile new file +1
-0@@ -0,0 +1 @@ +obj-y := init.o fault.o extable.o ioremap.oand here
Sounds good. I'll include this in the v4
https://github.com/riscv/riscv-linux/commit/e5a3eee8cd3e493dcd9b81509b1aa9e0302b72da