]> asedeno.scripts.mit.edu Git - linux.git/commitdiff
drm/amd/display: refactor gpio to allocate hw_container in constructor
authorSu Sung Chung <Su.Chung@amd.com>
Mon, 8 Jul 2019 15:31:39 +0000 (11:31 -0400)
committerAlex Deucher <alexander.deucher@amd.com>
Thu, 15 Aug 2019 15:53:55 +0000 (10:53 -0500)
[why]
if dynamic allocation fails during gpio_open, it will cause crash due to
page fault.

[how]
handle allocation when gpio object gets created and prevent from calling
gpio_open if allocation failed

Signed-off-by: Su Sung Chung <Su.Chung@amd.com>
Reviewed-by: Jun Lei <Jun.Lei@amd.com>
Acked-by: Leo Li <sunpeng.li@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
18 files changed:
drivers/gpu/drm/amd/display/dc/gpio/dce110/hw_factory_dce110.c
drivers/gpu/drm/amd/display/dc/gpio/dce120/hw_factory_dce120.c
drivers/gpu/drm/amd/display/dc/gpio/dce80/hw_factory_dce80.c
drivers/gpu/drm/amd/display/dc/gpio/dcn10/hw_factory_dcn10.c
drivers/gpu/drm/amd/display/dc/gpio/dcn20/hw_factory_dcn20.c
drivers/gpu/drm/amd/display/dc/gpio/diagnostics/hw_factory_diag.c
drivers/gpu/drm/amd/display/dc/gpio/gpio_base.c
drivers/gpu/drm/amd/display/dc/gpio/gpio_service.c
drivers/gpu/drm/amd/display/dc/gpio/gpio_service.h
drivers/gpu/drm/amd/display/dc/gpio/hw_ddc.c
drivers/gpu/drm/amd/display/dc/gpio/hw_ddc.h
drivers/gpu/drm/amd/display/dc/gpio/hw_factory.h
drivers/gpu/drm/amd/display/dc/gpio/hw_generic.c
drivers/gpu/drm/amd/display/dc/gpio/hw_generic.h
drivers/gpu/drm/amd/display/dc/gpio/hw_hpd.c
drivers/gpu/drm/amd/display/dc/gpio/hw_hpd.h
drivers/gpu/drm/amd/display/dc/inc/hw/gpio.h
drivers/gpu/drm/amd/display/include/gpio_interface.h

index 20d81bca119ce8e3d0fc7724fd1799c7f3f4c3eb..66e4841f41e4e2021e7b456e457b143e1f033998 100644 (file)
  */
 
 #include "dm_services.h"
+
 #include "include/gpio_types.h"
 #include "../hw_factory.h"
 
+#include "../hw_gpio.h"
+#include "../hw_ddc.h"
+#include "../hw_hpd.h"
+#include "../hw_generic.h"
+
 #include "hw_factory_dce110.h"
 
 #include "dce/dce_11_0_d.h"
@@ -143,12 +149,12 @@ static void define_hpd_registers(struct hw_gpio_pin *pin, uint32_t en)
 }
 
 static const struct hw_factory_funcs funcs = {
-       .create_ddc_data = dal_hw_ddc_create,
-       .create_ddc_clock = dal_hw_ddc_create,
-       .create_generic = NULL,
-       .create_hpd = dal_hw_hpd_create,
-       .create_sync = NULL,
-       .create_gsl = NULL,
+       .init_ddc_data = dal_hw_ddc_init,
+       .init_generic = NULL,
+       .init_hpd = dal_hw_hpd_init,
+       .get_ddc_pin = dal_hw_ddc_get_pin,
+       .get_hpd_pin = dal_hw_hpd_get_pin,
+       .get_generic_pin = NULL,
        .define_hpd_registers = define_hpd_registers,
        .define_ddc_registers = define_ddc_registers
 };
index ea3f888e5c65971ee2fb721e927a5502c0f6759e..cf98aa827a9a0a10833cfe4b470407a2558f48c3 100644 (file)
 #include "include/gpio_types.h"
 #include "../hw_factory.h"
 
-
 #include "../hw_gpio.h"
 #include "../hw_ddc.h"
 #include "../hw_hpd.h"
+#include "../hw_generic.h"
 
 #include "hw_factory_dce120.h"
 
@@ -164,12 +164,12 @@ static void define_hpd_registers(struct hw_gpio_pin *pin, uint32_t en)
 
 /* fucntion table */
 static const struct hw_factory_funcs funcs = {
-       .create_ddc_data = dal_hw_ddc_create,
-       .create_ddc_clock = dal_hw_ddc_create,
-       .create_generic = NULL,
-       .create_hpd = dal_hw_hpd_create,
-       .create_sync = NULL,
-       .create_gsl = NULL,
+       .init_ddc_data = dal_hw_ddc_init,
+       .init_generic = NULL,
+       .init_hpd = dal_hw_hpd_init,
+       .get_ddc_pin = dal_hw_ddc_get_pin,
+       .get_hpd_pin = dal_hw_hpd_get_pin,
+       .get_generic_pin = NULL,
        .define_hpd_registers = define_hpd_registers,
        .define_ddc_registers = define_ddc_registers
 };
index 48b67866377e1253614b1f0e2076206067e7f72b..496d3ffb74bbb2c7cc4f254d36efae43950a2b3e 100644 (file)
 #include "../hw_gpio.h"
 #include "../hw_ddc.h"
 #include "../hw_hpd.h"
+#include "../hw_generic.h"
 
 #include "dce/dce_8_0_d.h"
 #include "dce/dce_8_0_sh_mask.h"
 
+
 #define REG(reg_name)\
                mm ## reg_name
 
@@ -147,12 +149,12 @@ static void define_hpd_registers(struct hw_gpio_pin *pin, uint32_t en)
 }
 
 static const struct hw_factory_funcs funcs = {
-       .create_ddc_data = dal_hw_ddc_create,
-       .create_ddc_clock = dal_hw_ddc_create,
-       .create_generic = NULL,
-       .create_hpd = dal_hw_hpd_create,
-       .create_sync = NULL,
-       .create_gsl = NULL,
+       .init_ddc_data = dal_hw_ddc_init,
+       .init_generic = NULL,
+       .init_hpd = dal_hw_hpd_init,
+       .get_ddc_pin = dal_hw_ddc_get_pin,
+       .get_hpd_pin = dal_hw_hpd_get_pin,
+       .get_generic_pin = NULL,
        .define_hpd_registers = define_hpd_registers,
        .define_ddc_registers = define_ddc_registers
 };
index 5711f30cf848474730371c199203119b10d8ab02..b38c96c9fed3aa2d022c498aa28c81adc4b1336b 100644 (file)
@@ -196,12 +196,12 @@ static void define_hpd_registers(struct hw_gpio_pin *pin, uint32_t en)
 
 /* fucntion table */
 static const struct hw_factory_funcs funcs = {
-       .create_ddc_data = dal_hw_ddc_create,
-       .create_ddc_clock = dal_hw_ddc_create,
-       .create_generic = dal_hw_generic_create,
-       .create_hpd = dal_hw_hpd_create,
-       .create_sync = NULL,
-       .create_gsl = NULL,
+       .init_ddc_data = dal_hw_ddc_init,
+       .init_generic = dal_hw_generic_init,
+       .init_hpd = dal_hw_hpd_init,
+       .get_ddc_pin = dal_hw_ddc_get_pin,
+       .get_hpd_pin = dal_hw_hpd_get_pin,
+       .get_generic_pin = dal_hw_generic_get_pin,
        .define_hpd_registers = define_hpd_registers,
        .define_ddc_registers = define_ddc_registers,
        .define_generic_registers = define_generic_registers
index afb7c0f111bf2d975d816df695ca92c1273dc965..43a440385b43cb1d72d2441d6849c1095609cb7a 100644 (file)
@@ -212,12 +212,12 @@ static void define_generic_registers(struct hw_gpio_pin *pin, uint32_t en)
 
 /* fucntion table */
 static const struct hw_factory_funcs funcs = {
-       .create_ddc_data = dal_hw_ddc_create,
-       .create_ddc_clock = dal_hw_ddc_create,
-       .create_generic = dal_hw_generic_create,
-       .create_hpd = dal_hw_hpd_create,
-       .create_sync = NULL,
-       .create_gsl = NULL,
+       .init_ddc_data = dal_hw_ddc_init,
+       .init_generic = dal_hw_generic_init,
+       .init_hpd = dal_hw_hpd_init,
+       .get_ddc_pin = dal_hw_ddc_get_pin,
+       .get_hpd_pin = dal_hw_hpd_get_pin,
+       .get_generic_pin = dal_hw_generic_get_pin,
        .define_hpd_registers = define_hpd_registers,
        .define_ddc_registers = define_ddc_registers,
        .define_generic_registers = define_generic_registers,
index f15288c3986e270496aedaebb1a842441177e90e..df68430aeb0c2e08ce2e05daa63ddff6838d18c3 100644 (file)
 
 /* function table */
 static const struct hw_factory_funcs funcs = {
-       .create_ddc_data = NULL,
-       .create_ddc_clock = NULL,
-       .create_generic = NULL,
-       .create_hpd = NULL,
-       .create_sync = NULL,
-       .create_gsl = NULL,
+       .init_ddc_data = NULL,
+       .init_generic = NULL,
+       .init_hpd = NULL,
 };
 
 void dal_hw_factory_diag_fpga_init(struct hw_factory *factory)
index d03b38e80d9b3e71d041a7bf340340f0faafb4cd..f8f85490e77e20d8494e9356a6e4133cbaedf7ca 100644 (file)
@@ -67,10 +67,14 @@ enum gpio_result dal_gpio_open_ex(
                return GPIO_RESULT_ALREADY_OPENED;
        }
 
+       // No action if allocation failed during gpio construct
+       if (!gpio->hw_container.ddc) {
+               ASSERT_CRITICAL(false);
+               return GPIO_RESULT_NON_SPECIFIC_ERROR;
+       }
        gpio->mode = mode;
 
-       return dal_gpio_service_open(
-               gpio->service, gpio->id, gpio->en, mode, &gpio->pin);
+       return dal_gpio_service_open(gpio);
 }
 
 enum gpio_result dal_gpio_get_value(
@@ -231,6 +235,21 @@ enum gpio_pin_output_state dal_gpio_get_output_state(
        return gpio->output_state;
 }
 
+struct hw_ddc *dal_gpio_get_ddc(struct gpio *gpio)
+{
+       return gpio->hw_container.ddc;
+}
+
+struct hw_hpd *dal_gpio_get_hpd(struct gpio *gpio)
+{
+       return gpio->hw_container.hpd;
+}
+
+struct hw_generic *dal_gpio_get_generic(struct gpio *gpio)
+{
+       return gpio->hw_container.generic;
+}
+
 void dal_gpio_close(
        struct gpio *gpio)
 {
@@ -267,6 +286,30 @@ struct gpio *dal_gpio_create(
        gpio->mode = GPIO_MODE_UNKNOWN;
        gpio->output_state = output_state;
 
+       //initialize hw_container union based on id
+       switch (gpio->id) {
+       case GPIO_ID_DDC_DATA:
+               gpio->service->factory.funcs->init_ddc_data(&gpio->hw_container.ddc, service->ctx, id, en);
+               break;
+       case GPIO_ID_DDC_CLOCK:
+               gpio->service->factory.funcs->init_ddc_data(&gpio->hw_container.ddc, service->ctx, id, en);
+               break;
+       case GPIO_ID_GENERIC:
+               gpio->service->factory.funcs->init_generic(&gpio->hw_container.generic, service->ctx, id, en);
+               break;
+       case GPIO_ID_HPD:
+               gpio->service->factory.funcs->init_hpd(&gpio->hw_container.hpd, service->ctx, id, en);
+               break;
+       // TODO: currently gpio for sync and gsl does not get created, might need it later
+       case GPIO_ID_SYNC:
+               break;
+       case GPIO_ID_GSL:
+               break;
+       default:
+               ASSERT_CRITICAL(false);
+               gpio->pin = NULL;
+       }
+
        return gpio;
 }
 
@@ -280,6 +323,33 @@ void dal_gpio_destroy(
 
        dal_gpio_close(*gpio);
 
+       switch ((*gpio)->id) {
+       case GPIO_ID_DDC_DATA:
+               kfree((*gpio)->hw_container.ddc);
+               (*gpio)->hw_container.ddc = NULL;
+               break;
+       case GPIO_ID_DDC_CLOCK:
+               //TODO: might want to change it to init_ddc_clock
+               kfree((*gpio)->hw_container.ddc);
+               (*gpio)->hw_container.ddc = NULL;
+               break;
+       case GPIO_ID_GENERIC:
+               kfree((*gpio)->hw_container.generic);
+               (*gpio)->hw_container.generic = NULL;
+               break;
+       case GPIO_ID_HPD:
+               kfree((*gpio)->hw_container.hpd);
+               (*gpio)->hw_container.hpd = NULL;
+               break;
+       // TODO: currently gpio for sync and gsl does not get created, might need it later
+       case GPIO_ID_SYNC:
+               break;
+       case GPIO_ID_GSL:
+               break;
+       default:
+               break;
+       }
+
        kfree(*gpio);
 
        *gpio = NULL;
index a7bc3ee5dfec3b318ca9d82a0e5d0c1e7f66407f..d03165e71dc651764e37ff1dcfbef441bda33670 100644 (file)
@@ -290,13 +290,15 @@ enum gpio_result dal_gpio_service_unlock(
 }
 
 enum gpio_result dal_gpio_service_open(
-       struct gpio_service *service,
-       enum gpio_id id,
-       uint32_t en,
-       enum gpio_mode mode,
-       struct hw_gpio_pin **ptr)
+       struct gpio *gpio)
 {
-       struct hw_gpio_pin *pin;
+       struct gpio_service *service = gpio->service;
+       enum gpio_id id = gpio->id;
+       uint32_t en = gpio->en;
+       enum gpio_mode mode = gpio->mode;
+
+       struct hw_gpio_pin **pin = &gpio->pin;
+
 
        if (!service->busyness[id]) {
                ASSERT_CRITICAL(false);
@@ -310,51 +312,43 @@ enum gpio_result dal_gpio_service_open(
 
        switch (id) {
        case GPIO_ID_DDC_DATA:
-               pin = service->factory.funcs->create_ddc_data(
-                       service->ctx, id, en);
-               service->factory.funcs->define_ddc_registers(pin, en);
+               *pin = service->factory.funcs->get_ddc_pin(gpio);
+               service->factory.funcs->define_ddc_registers(*pin, en);
        break;
        case GPIO_ID_DDC_CLOCK:
-               pin = service->factory.funcs->create_ddc_clock(
-                       service->ctx, id, en);
-               service->factory.funcs->define_ddc_registers(pin, en);
+               *pin = service->factory.funcs->get_ddc_pin(gpio);
+               service->factory.funcs->define_ddc_registers(*pin, en);
        break;
        case GPIO_ID_GENERIC:
-               pin = service->factory.funcs->create_generic(
-                       service->ctx, id, en);
-               service->factory.funcs->define_generic_registers(pin, en);
+               *pin = service->factory.funcs->get_generic_pin(gpio);
+               service->factory.funcs->define_generic_registers(*pin, en);
        break;
        case GPIO_ID_HPD:
-               pin = service->factory.funcs->create_hpd(
-                       service->ctx, id, en);
-               service->factory.funcs->define_hpd_registers(pin, en);
+               *pin = service->factory.funcs->get_hpd_pin(gpio);
+               service->factory.funcs->define_hpd_registers(*pin, en);
        break;
+
+       //TODO: gsl and sync support? create_sync and create_gsl are NULL
        case GPIO_ID_SYNC:
-               pin = service->factory.funcs->create_sync(
-                       service->ctx, id, en);
-       break;
        case GPIO_ID_GSL:
-               pin = service->factory.funcs->create_gsl(
-                       service->ctx, id, en);
        break;
        default:
                ASSERT_CRITICAL(false);
                return GPIO_RESULT_NON_SPECIFIC_ERROR;
        }
 
-       if (!pin) {
+       if (!*pin) {
                ASSERT_CRITICAL(false);
                return GPIO_RESULT_NON_SPECIFIC_ERROR;
        }
 
-       if (!pin->funcs->open(pin, mode)) {
+       if (!(*pin)->funcs->open(*pin, mode)) {
                ASSERT_CRITICAL(false);
-               dal_gpio_service_close(service, &pin);
+               dal_gpio_service_close(service, pin);
                return GPIO_RESULT_OPEN_FAILED;
        }
 
        set_pin_busy(service, id, en);
-       *ptr = pin;
        return GPIO_RESULT_OK;
 }
 
@@ -376,11 +370,10 @@ void dal_gpio_service_close(
 
                pin->funcs->close(pin);
 
-               pin->funcs->destroy(ptr);
+               *ptr = NULL;
        }
 }
 
-
 enum dc_irq_source dal_irq_get_source(
        const struct gpio *irq)
 {
index 0c678af75331b757fc5b8a5384d6f4ee31e653a8..b9775a131ecd0ae5d38835731eb8c7d36030a318 100644 (file)
@@ -42,11 +42,7 @@ struct gpio_service {
 };
 
 enum gpio_result dal_gpio_service_open(
-       struct gpio_service *service,
-       enum gpio_id id,
-       uint32_t en,
-       enum gpio_mode mode,
-       struct hw_gpio_pin **ptr);
+       struct gpio *gpio);
 
 void dal_gpio_service_close(
        struct gpio_service *service,
index 408857d19c84f174e48eaca3e5075126b299a023..1c12961f6472f3041185676e54fc07bc489ef078 100644 (file)
@@ -28,6 +28,7 @@
 
 #include "dm_services.h"
 
+#include "include/gpio_interface.h"
 #include "include/gpio_types.h"
 #include "hw_gpio.h"
 #include "hw_ddc.h"
@@ -45,6 +46,8 @@
 #define REG(reg)\
        (ddc->regs->reg)
 
+struct gpio;
+
 static void destruct(
        struct hw_ddc *pin)
 {
@@ -227,24 +230,29 @@ static void construct(
        ddc->base.base.funcs = &funcs;
 }
 
-struct hw_gpio_pin *dal_hw_ddc_create(
+void dal_hw_ddc_init(
+       struct hw_ddc **hw_ddc,
        struct dc_context *ctx,
        enum gpio_id id,
        uint32_t en)
 {
-       struct hw_ddc *pin;
-
        if ((en < GPIO_DDC_LINE_MIN) || (en > GPIO_DDC_LINE_MAX)) {
                ASSERT_CRITICAL(false);
-               return NULL;
+               *hw_ddc = NULL;
        }
 
-       pin = kzalloc(sizeof(struct hw_ddc), GFP_KERNEL);
-       if (!pin) {
+       *hw_ddc = kzalloc(sizeof(struct hw_ddc), GFP_KERNEL);
+       if (!*hw_ddc) {
                ASSERT_CRITICAL(false);
-               return NULL;
+               return;
        }
 
-       construct(pin, id, en, ctx);
-       return &pin->base.base;
+       construct(*hw_ddc, id, en, ctx);
+}
+
+struct hw_gpio_pin *dal_hw_ddc_get_pin(struct gpio *gpio)
+{
+       struct hw_ddc *hw_ddc = dal_gpio_get_ddc(gpio);
+
+       return &hw_ddc->base.base;
 }
index 9690e2a885d7b6175563392743fd8c0390f41026..cc30e65df43189e6f0898e5c59717072d4cd638d 100644 (file)
@@ -38,9 +38,12 @@ struct hw_ddc {
 #define HW_DDC_FROM_BASE(hw_gpio) \
        container_of((HW_GPIO_FROM_BASE(hw_gpio)), struct hw_ddc, base)
 
-struct hw_gpio_pin *dal_hw_ddc_create(
+void dal_hw_ddc_init(
+       struct hw_ddc **hw_ddc,
        struct dc_context *ctx,
        enum gpio_id id,
        uint32_t en);
 
+struct hw_gpio_pin *dal_hw_ddc_get_pin(struct gpio *gpio);
+
 #endif
index 7017c933734820383ff3432edce800ea427703eb..e15b037f3bcd0444fd2ea94886cea63e09f53b00 100644 (file)
 
 struct hw_gpio_pin;
 struct hw_hpd;
+struct hw_ddc;
+struct hw_generic;
+struct gpio;
 
 struct hw_factory {
        uint32_t number_of_pins[GPIO_ID_COUNT];
 
        const struct hw_factory_funcs {
-               struct hw_gpio_pin *(*create_ddc_data)(
-                       struct dc_context *ctx,
-                       enum gpio_id id,
-                       uint32_t en);
-               struct hw_gpio_pin *(*create_ddc_clock)(
-                       struct dc_context *ctx,
-                       enum gpio_id id,
-                       uint32_t en);
-               struct hw_gpio_pin *(*create_generic)(
-                       struct dc_context *ctx,
-                       enum gpio_id id,
-                       uint32_t en);
-               struct hw_gpio_pin *(*create_hpd)(
-                       struct dc_context *ctx,
-                       enum gpio_id id,
-                       uint32_t en);
-               struct hw_gpio_pin *(*create_sync)(
-                       struct dc_context *ctx,
-                       enum gpio_id id,
-                       uint32_t en);
-               struct hw_gpio_pin *(*create_gsl)(
-                       struct dc_context *ctx,
-                       enum gpio_id id,
-                       uint32_t en);
+               void (*init_ddc_data)(
+                               struct hw_ddc **hw_ddc,
+                               struct dc_context *ctx,
+                               enum gpio_id id,
+                               uint32_t en);
+               void (*init_generic)(
+                               struct hw_generic **hw_generic,
+                               struct dc_context *ctx,
+                               enum gpio_id id,
+                               uint32_t en);
+               void (*init_hpd)(
+                               struct hw_hpd **hw_hpd,
+                               struct dc_context *ctx,
+                               enum gpio_id id,
+                               uint32_t en);
+               struct hw_gpio_pin *(*get_hpd_pin)(
+                               struct gpio *gpio);
+               struct hw_gpio_pin *(*get_ddc_pin)(
+                               struct gpio *gpio);
+               struct hw_gpio_pin *(*get_generic_pin)(
+                               struct gpio *gpio);
                void (*define_hpd_registers)(
                                struct hw_gpio_pin *pin,
                                uint32_t en);
index 8b7a8ffe3cd7dde53cf3ec44c6dfbc9487181140..69b899741f6d612a49d1f06198585e3bcbfaa101 100644 (file)
@@ -27,6 +27,7 @@
 
 #include "dm_services.h"
 
+#include "include/gpio_interface.h"
 #include "include/gpio_types.h"
 #include "hw_gpio.h"
 #include "hw_generic.h"
@@ -43,6 +44,8 @@
 #define REG(reg)\
        (generic->regs->reg)
 
+struct gpio;
+
 static void dal_hw_generic_construct(
        struct hw_generic *pin,
        enum gpio_id id,
@@ -106,29 +109,30 @@ static void construct(
        generic->base.base.funcs = &funcs;
 }
 
-struct hw_gpio_pin *dal_hw_generic_create(
+void dal_hw_generic_init(
+       struct hw_generic **hw_generic,
        struct dc_context *ctx,
        enum gpio_id id,
        uint32_t en)
 {
-       struct hw_generic *generic;
-
-       if (id != GPIO_ID_GENERIC) {
+       if ((en < GPIO_DDC_LINE_MIN) || (en > GPIO_DDC_LINE_MAX)) {
                ASSERT_CRITICAL(false);
-               return NULL;
+               *hw_generic = NULL;
        }
 
-       if ((en < GPIO_GENERIC_MIN) || (en > GPIO_GENERIC_MAX)) {
+       *hw_generic = kzalloc(sizeof(struct hw_generic), GFP_KERNEL);
+       if (!*hw_generic) {
                ASSERT_CRITICAL(false);
-               return NULL;
+               return;
        }
 
-       generic = kzalloc(sizeof(struct hw_generic), GFP_KERNEL);
-       if (!generic) {
-               ASSERT_CRITICAL(false);
-               return NULL;
-       }
+       construct(*hw_generic, id, en, ctx);
+}
+
+
+struct hw_gpio_pin *dal_hw_generic_get_pin(struct gpio *gpio)
+{
+       struct hw_generic *hw_generic = dal_gpio_get_generic(gpio);
 
-       construct(generic, id, en, ctx);
-       return &generic->base.base;
+       return &hw_generic->base.base;
 }
index 3ea1c13e3ea6ce38c88b31528155f8612dbdb0bd..bd6ffeb5e9df6ba0f81b3c7523533d5a3437ffba 100644 (file)
@@ -27,6 +27,7 @@
 #define __DAL_HW_generic_H__
 
 #include "generic_regs.h"
+#include "hw_gpio.h"
 
 struct hw_generic {
        struct hw_gpio base;
@@ -38,9 +39,12 @@ struct hw_generic {
 #define HW_GENERIC_FROM_BASE(hw_gpio) \
        container_of((HW_GPIO_FROM_BASE(hw_gpio)), struct hw_generic, base)
 
-struct hw_gpio_pin *dal_hw_generic_create(
+void dal_hw_generic_init(
+       struct hw_generic **hw_generic,
        struct dc_context *ctx,
        enum gpio_id id,
        uint32_t en);
 
+struct hw_gpio_pin *dal_hw_generic_get_pin(struct gpio *gpio);
+
 #endif
index 5e11d748e6f32995fd7423e20dd8ce1be2a3c4e4..00c9bcf660a3646b6575b7ff216b5661fa3d787e 100644 (file)
@@ -27,6 +27,7 @@
 
 #include "dm_services.h"
 
+#include "include/gpio_interface.h"
 #include "include/gpio_types.h"
 #include "hw_gpio.h"
 #include "hw_hpd.h"
@@ -43,6 +44,8 @@
 #define REG(reg)\
        (hpd->regs->reg)
 
+struct gpio;
+
 static void dal_hw_hpd_construct(
        struct hw_hpd *pin,
        enum gpio_id id,
@@ -136,29 +139,29 @@ static void construct(
        hpd->base.base.funcs = &funcs;
 }
 
-struct hw_gpio_pin *dal_hw_hpd_create(
+void dal_hw_hpd_init(
+       struct hw_hpd **hw_hpd,
        struct dc_context *ctx,
        enum gpio_id id,
        uint32_t en)
 {
-       struct hw_hpd *hpd;
-
-       if (id != GPIO_ID_HPD) {
+       if ((en < GPIO_DDC_LINE_MIN) || (en > GPIO_DDC_LINE_MAX)) {
                ASSERT_CRITICAL(false);
-               return NULL;
+               *hw_hpd = NULL;
        }
 
-       if ((en < GPIO_HPD_MIN) || (en > GPIO_HPD_MAX)) {
+       *hw_hpd = kzalloc(sizeof(struct hw_hpd), GFP_KERNEL);
+       if (!*hw_hpd) {
                ASSERT_CRITICAL(false);
-               return NULL;
+               return;
        }
 
-       hpd = kzalloc(sizeof(struct hw_hpd), GFP_KERNEL);
-       if (!hpd) {
-               ASSERT_CRITICAL(false);
-               return NULL;
-       }
+       construct(*hw_hpd, id, en, ctx);
+}
+
+struct hw_gpio_pin *dal_hw_hpd_get_pin(struct gpio *gpio)
+{
+       struct hw_hpd *hw_hpd = dal_gpio_get_hpd(gpio);
 
-       construct(hpd, id, en, ctx);
-       return &hpd->base.base;
+       return &hw_hpd->base.base;
 }
index 4ab7a208f781c13bd71d6d9020d925e35d60d70a..e7d8b3bb016c04be4c96f6cb51040ccb85f42229 100644 (file)
@@ -38,9 +38,12 @@ struct hw_hpd {
 #define HW_HPD_FROM_BASE(hw_gpio) \
        container_of((HW_GPIO_FROM_BASE(hw_gpio)), struct hw_hpd, base)
 
-struct hw_gpio_pin *dal_hw_hpd_create(
+void dal_hw_hpd_init(
+       struct hw_hpd **hw_hpd,
        struct dc_context *ctx,
        enum gpio_id id,
        uint32_t en);
 
+struct hw_gpio_pin *dal_hw_hpd_get_pin(struct gpio *gpio);
+
 #endif
index 90d0148430fb5bd39a98e0746e7fc160db5dd72a..5253dc8b15f8c9d2461c658b3adfadbe88ada6cc 100644 (file)
 
 #include "gpio_types.h"
 
+
+union gpio_hw_container {
+       struct hw_ddc *ddc;
+       struct hw_generic *generic;
+       struct hw_hpd *hpd;
+};
+
 struct gpio {
        struct gpio_service *service;
        struct hw_gpio_pin *pin;
        enum gpio_id id;
        uint32_t en;
+
+       union gpio_hw_container hw_container;
        enum gpio_mode mode;
+
        /* when GPIO comes from VBIOS, it has defined output state */
        enum gpio_pin_output_state output_state;
 };
index 7de64195dc33dd387321e03a151b846f7506c61d..5e888a093c1633b3cd1a0484dbabbca1727a5b94 100644 (file)
@@ -93,8 +93,17 @@ enum sync_source dal_gpio_get_sync_source(
 enum gpio_pin_output_state dal_gpio_get_output_state(
        const struct gpio *gpio);
 
+struct hw_ddc *dal_gpio_get_ddc(struct gpio *gpio);
+
+struct hw_hpd *dal_gpio_get_hpd(struct gpio *gpio);
+
+struct hw_generic *dal_gpio_get_generic(struct gpio *gpio);
+
 /* Close the handle */
 void dal_gpio_close(
        struct gpio *gpio);
 
+
+
+
 #endif