From: kettenis Date: Sat, 23 Dec 2023 14:18:27 +0000 (+0000) Subject: Provide more complete implementations of some of the Linux compat X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=9342ba5ef4c4b12756101b82e6ca8eeee7d77133;p=openbsd Provide more complete implementations of some of the Linux compat interfaces that are needed for the upcoming apple kms driver. ok jsg@ --- diff --git a/sys/dev/pci/drm/drm_linux.c b/sys/dev/pci/drm/drm_linux.c index 1cfd4bf9fdb..d2a071d43d9 100644 --- a/sys/dev/pci/drm/drm_linux.c +++ b/sys/dev/pci/drm/drm_linux.c @@ -1,4 +1,4 @@ -/* $OpenBSD: drm_linux.c,v 1.104 2023/10/20 03:38:58 jsg Exp $ */ +/* $OpenBSD: drm_linux.c,v 1.105 2023/12/23 14:18:27 kettenis Exp $ */ /* * Copyright (c) 2013 Jonathan Gray * Copyright (c) 2015, 2016 Mark Kettenis @@ -1501,6 +1501,9 @@ acpi_format_exception(acpi_status status) #endif +SLIST_HEAD(,backlight_device) backlight_device_list = + SLIST_HEAD_INITIALIZER(backlight_device_list); + void backlight_do_update_status(void *arg) { @@ -1509,7 +1512,7 @@ backlight_do_update_status(void *arg) struct backlight_device * backlight_device_register(const char *name, void *kdev, void *data, - const struct backlight_ops *ops, struct backlight_properties *props) + const struct backlight_ops *ops, const struct backlight_properties *props) { struct backlight_device *bd; @@ -1519,6 +1522,9 @@ backlight_device_register(const char *name, void *kdev, void *data, bd->data = data; task_set(&bd->task, backlight_do_update_status, bd); + + SLIST_INSERT_HEAD(&backlight_device_list, bd, next); + bd->name = name; return bd; } @@ -1526,25 +1532,17 @@ backlight_device_register(const char *name, void *kdev, void *data, void backlight_device_unregister(struct backlight_device *bd) { + SLIST_REMOVE(&backlight_device_list, bd, backlight_device, next); free(bd, M_DRM, sizeof(*bd)); } -struct backlight_device * -devm_backlight_device_register(void *dev, const char *name, void *parent, - void *data, const struct backlight_ops *bo, - const struct backlight_properties *bp) -{ - STUB(); - return NULL; -} - void backlight_schedule_update_status(struct backlight_device *bd) { task_add(systq, &bd->task); } -inline int +int backlight_enable(struct backlight_device *bd) { if (bd == NULL) @@ -1555,7 +1553,7 @@ backlight_enable(struct backlight_device *bd) return bd->ops->update_status(bd); } -inline int +int backlight_disable(struct backlight_device *bd) { if (bd == NULL) @@ -1566,6 +1564,62 @@ backlight_disable(struct backlight_device *bd) return bd->ops->update_status(bd); } +struct backlight_device * +backlight_device_get_by_name(const char *name) +{ + struct backlight_device *bd; + + SLIST_FOREACH(bd, &backlight_device_list, next) { + if (strcmp(name, bd->name) == 0) + return bd; + } + + return NULL; +} + +struct drvdata { + struct device *dev; + void *data; + SLIST_ENTRY(drvdata) next; +}; + +SLIST_HEAD(,drvdata) drvdata_list = SLIST_HEAD_INITIALIZER(drvdata_list); + +void +dev_set_drvdata(struct device *dev, void *data) +{ + struct drvdata *drvdata; + + SLIST_FOREACH(drvdata, &drvdata_list, next) { + if (drvdata->dev == dev) { + drvdata->data = data; + return; + } + } + + if (data == NULL) + return; + + drvdata = malloc(sizeof(*drvdata), M_DRM, M_WAITOK); + drvdata->dev = dev; + drvdata->data = data; + + SLIST_INSERT_HEAD(&drvdata_list, drvdata, next); +} + +void * +dev_get_drvdata(struct device *dev) +{ + struct drvdata *drvdata; + + SLIST_FOREACH(drvdata, &drvdata_list, next) { + if (drvdata->dev == dev) + return drvdata->data; + } + + return NULL; +} + void drm_sysfs_hotplug_event(struct drm_device *dev) { diff --git a/sys/dev/pci/drm/include/drm/drm_file.h b/sys/dev/pci/drm/include/drm/drm_file.h index 3adb34af4af..1eaa4db6fbc 100644 --- a/sys/dev/pci/drm/include/drm/drm_file.h +++ b/sys/dev/pci/drm/include/drm/drm_file.h @@ -73,9 +73,7 @@ struct drm_minor { /* private: */ int index; /* Minor device number */ int type; /* Control or render */ -#ifdef __linux__ struct device *kdev; /* Linux device */ -#endif struct drm_device *dev; struct dentry *debugfs_root; diff --git a/sys/dev/pci/drm/include/linux/backlight.h b/sys/dev/pci/drm/include/linux/backlight.h index a6951c70bf6..1420c9df091 100644 --- a/sys/dev/pci/drm/include/linux/backlight.h +++ b/sys/dev/pci/drm/include/linux/backlight.h @@ -11,24 +11,32 @@ struct device; struct backlight_properties { int type; +#define BACKLIGHT_RAW 0 +#define BACKLIGHT_FIRMWARE 1 +#define BACKLIGHT_PLATFORM 2 int max_brightness; int brightness; int power; + int scale; +#define BACKLIGHT_SCALE_LINEAR 0 + int state; +#define BL_CORE_SUSPENDED 0x00000001 }; struct backlight_ops { int options; +#define BL_CORE_SUSPENDRESUME 0x00000001 int (*update_status)(struct backlight_device *); int (*get_brightness)(struct backlight_device *); }; -#define BL_CORE_SUSPENDRESUME 1 - struct backlight_device { const struct backlight_ops *ops; struct backlight_properties props; struct task task; void *data; + SLIST_ENTRY(backlight_device) next; + const char *name; }; static inline void * @@ -37,18 +45,25 @@ bl_get_data(struct backlight_device *bd) return bd->data; } -#define BACKLIGHT_RAW 0 -#define BACKLIGHT_FIRMWARE 1 +static inline int +backlight_get_brightness(struct backlight_device *bd) +{ + return bd->props.brightness; +} #define BACKLIGHT_UPDATE_HOTKEY 0 struct backlight_device *backlight_device_register(const char *, void *, - void *, const struct backlight_ops *, struct backlight_properties *); + void *, const struct backlight_ops *, const struct backlight_properties *); void backlight_device_unregister(struct backlight_device *); -struct backlight_device *devm_backlight_device_register(void *, const char *, - void *, void *, const struct backlight_ops *, - const struct backlight_properties *); +static inline struct backlight_device * +devm_backlight_device_register(void *dev, const char *name, void *parent, + void *data, const struct backlight_ops *bo, + const struct backlight_properties *bp) +{ + return backlight_device_register(name, dev, data, bo, bp); +} static inline void backlight_update_status(struct backlight_device *bd) @@ -82,10 +97,6 @@ devm_of_find_backlight(struct device *dev) return NULL; } -static inline struct backlight_device * -backlight_device_get_by_name(const char *name) -{ - return NULL; -} +struct backlight_device *backlight_device_get_by_name(const char *); #endif diff --git a/sys/dev/pci/drm/include/linux/device.h b/sys/dev/pci/drm/include/linux/device.h index ba1e269a74d..c72b33b3335 100644 --- a/sys/dev/pci/drm/include/linux/device.h +++ b/sys/dev/pci/drm/include/linux/device.h @@ -16,6 +16,9 @@ struct device_node; +struct bus_type { +}; + struct device_driver { struct device *dev; }; @@ -33,12 +36,13 @@ struct device_attribute { #define device_create_file(a, b) 0 #define device_remove_file(a, b) -#define dev_get_drvdata(x) NULL -#define dev_set_drvdata(x, y) +void *dev_get_drvdata(struct device *); +void dev_set_drvdata(struct device *, void *); #define dev_pm_set_driver_flags(x, y) #define devm_kzalloc(x, y, z) kzalloc(y, z) +#define devm_kfree(x, y) kfree(y) #define dev_warn(dev, fmt, arg...) \ printf("drm:pid%d:%s *WARNING* " fmt, curproc->p_p->ps_pid, \ @@ -78,6 +82,10 @@ struct device_attribute { #define dev_err_once(dev, fmt, arg...) \ printf("drm:pid%d:%s *ERROR* " fmt, curproc->p_p->ps_pid, \ __func__ , ## arg) + +#define dev_err_probe(dev, err, fmt, arg...) \ + printf("drm:pid%d:%s *ERROR* " fmt, curproc->p_p->ps_pid, \ + __func__ , ## arg), err #ifdef DRMDEBUG #define dev_info(dev, fmt, arg...) \ diff --git a/sys/dev/pci/drm/include/linux/io.h b/sys/dev/pci/drm/include/linux/io.h index 08e20aa0cd2..19bf59c9740 100644 --- a/sys/dev/pci/drm/include/linux/io.h +++ b/sys/dev/pci/drm/include/linux/io.h @@ -169,6 +169,9 @@ iowrite64(u64 val, volatile void __iomem *addr) #define readq(p) ioread64(p) #define writeq(v, p) iowrite64(v, p) +#define readl_relaxed(p) readl(p) +#define writel_relaxed(v, p) writel(v, p) + int drm_mtrr_add(unsigned long, size_t, int); int drm_mtrr_del(int, unsigned long, size_t, int); diff --git a/sys/dev/pci/drm/include/linux/ioport.h b/sys/dev/pci/drm/include/linux/ioport.h index 6176300c533..912fa001724 100644 --- a/sys/dev/pci/drm/include/linux/ioport.h +++ b/sys/dev/pci/drm/include/linux/ioport.h @@ -5,6 +5,8 @@ #include +#define IORESOURCE_MEM 0x0001 + struct resource { u_long start; u_long end; diff --git a/sys/dev/pci/drm/include/linux/jiffies.h b/sys/dev/pci/drm/include/linux/jiffies.h index 8278b761a7e..09dc53cb60a 100644 --- a/sys/dev/pci/drm/include/linux/jiffies.h +++ b/sys/dev/pci/drm/include/linux/jiffies.h @@ -40,7 +40,12 @@ jiffies_to_nsecs(const unsigned long x) #define usecs_to_jiffies(x) (((uint64_t)(x)) * hz / 1000000) #define nsecs_to_jiffies(x) (((uint64_t)(x)) * hz / 1000000000) #define nsecs_to_jiffies64(x) (((uint64_t)(x)) * hz / 1000000000) -#define get_jiffies_64() jiffies + +static inline uint64_t +get_jiffies_64(void) +{ + return jiffies; +} static inline int time_after(const unsigned long a, const unsigned long b) @@ -55,6 +60,12 @@ time_after_eq(const unsigned long a, const unsigned long b) return((long)(b - a) <= 0); } +static inline int +time_after_eq64(const unsigned long long a, const unsigned long long b) +{ + return((long long)(b - a) <= 0); +} + #define time_after32(a,b) ((int32_t)((uint32_t)(b) - (uint32_t)(a)) < 0) #endif diff --git a/sys/dev/pci/drm/include/linux/kernel.h b/sys/dev/pci/drm/include/linux/kernel.h index 66aaa8dc8fe..3f385be1613 100644 --- a/sys/dev/pci/drm/include/linux/kernel.h +++ b/sys/dev/pci/drm/include/linux/kernel.h @@ -149,4 +149,6 @@ _in_dbg_master(void) #define STUB() do { printf("%s: stub\n", __func__); } while(0) +#define CONCATENATE(x, y) __CONCAT(x, y) + #endif diff --git a/sys/dev/pci/drm/include/linux/pci.h b/sys/dev/pci/drm/include/linux/pci.h index b5b51337f9d..5ff734df281 100644 --- a/sys/dev/pci/drm/include/linux/pci.h +++ b/sys/dev/pci/drm/include/linux/pci.h @@ -1,4 +1,4 @@ -/* $OpenBSD: pci.h,v 1.14 2023/09/13 12:31:49 jsg Exp $ */ +/* $OpenBSD: pci.h,v 1.15 2023/12/23 14:18:27 kettenis Exp $ */ /* * Copyright (c) 2015 Mark Kettenis * @@ -482,6 +482,14 @@ pci_set_power_state(struct pci_dev *dev, int state) return 0; } +struct pci_driver; + +static inline int +pci_register_driver(struct pci_driver *pci_drv) +{ + return 0; +} + static inline void pci_unregister_driver(void *d) {