openBMC source code

Posted soul.stone

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了openBMC source code相关的知识,希望对你有一定的参考价值。

1、fand

1)main函数

read_sysfs_int("/sys/bus/i2c/drivers/cmmcpld/13-003e/slotid", &sysfs_value)

write_fan_speed(fan + fan_offset, fan_speed)

write_fan_led(fan + fan_offset, FAN_LED_BLUE)

start_watchdog(0)

while(1){

critical_temp = read_critical_max_temp();
alarm_temp = read_alarm_max_temp();

raising_pwm = calculate_raising_fan_pwm(critical_temp);
falling_pwm = calculate_falling_fan_pwm(critical_temp);

write_fan_led(fan + fan_offset, FAN_LED_RED);

}

 

2)write_fan_speed

int write_fan_speed(const int fan, const int value) {
int unit = value * PWM_UNIT_MAX / 100;

if (unit == PWM_UNIT_MAX)
unit--;

return galaxy100_set_fan_sysfs(fan, unit);
}

 

3)galaxy100_set_fan_sysfs

info = &galaxy100_fantray_info[fan];
channel = &info->channel_info;

snprintf(fullpath, PATH_CACHE_SIZE, "%s/%s", channel->prefix, "fantray1_pwm");
ret = write_sysfs_int(fullpath, value);

snprintf(fullpath, PATH_CACHE_SIZE, "%s/%s", channel->prefix, "fantray2_pwm");
ret = write_sysfs_int(fullpath, value);

snprintf(fullpath, PATH_CACHE_SIZE, "%s/%s", channel->prefix, "fantray3_pwm");
ret = write_sysfs_int(fullpath, value);

 

4) write_sysfs_int

int write_sysfs_int(char *sysfs_path, int buffer)
{
int rc = 0;
char writeBuf[PATH_CACHE_SIZE];
snprintf(writeBuf, PATH_CACHE_SIZE, "%d", buffer);
return write_sysfs_raw(sysfs_path, writeBuf);
}

 

int write_sysfs_raw_internal(const char *device, char *value, int log)

fp = fopen(device, "w");

rc = fputs(value, fp);
fclose(fp);

 

5)  fancpld_attr_table

typedef struct i2c_dev_attr_st_ {
  const char *ida_name;
  const char *ida_help;
  i2c_dev_attr_show_fn ida_show;
  i2c_dev_attr_store_fn ida_store;
  int ida_reg;
  int ida_bit_offset;
  int ida_n_bits;
} i2c_dev_attr_st;

const i2c_dev_attr_st fancpld_attr_table[] = {
  {
    "fantray1_pwm",
    FANTRAY_PWM_HELP,
    I2C_DEV_ATTR_SHOW_DEFAULT,
    I2C_DEV_ATTR_STORE_DEFAULT,
    0x20, 0, 5,
  },
}

static int fancpld_probe(struct i2c_client *client,
const struct i2c_device_id *id)
{
int n_attrs = sizeof(fancpld_attr_table) / sizeof(fancpld_attr_table[0]);
return i2c_dev_sysfs_data_init(client, &fancpld_data,
fancpld_attr_table, n_attrs);
}

 

static struct i2c_driver fancpld_driver = {
.class = I2C_CLASS_HWMON,
.driver = {
.name = "fancpld",
},
.probe = fancpld_probe,
.remove = fancpld_remove,
.id_table = fancpld_id,
.detect = fancpld_detect,
.address_list = normal_i2c,
};

static int __init fancpld_mod_init(void)
{
return i2c_add_driver(&fancpld_driver);
}

 

 

6) i2c_dev_sysfs_store

static ssize_t i2c_dev_sysfs_store(struct device *dev,
                                   struct device_attribute *attr,
                                   const char *buf, size_t count)

if (dev_attr->ida_store != I2C_DEV_ATTR_STORE_DEFAULT) {
return dev_attr->ida_store(dev, attr, buf, count);
}

/* default handling, first read back the current value */
val = i2c_smbus_read_byte_data(client, dev_attr->ida_reg);

 

/* mask out all bits for the value requested */
val &= ~(req_val_mask << dev_attr->ida_bit_offset);
val |= req_val << dev_attr->ida_bit_offset;

val = i2c_smbus_write_byte_data(client, dev_attr->ida_reg, val);

 

7)module_init

Cmmcpld.c (meta-facebook\meta-cmm\recipes-kernel\cpld-mod\files):module_init(cmmcpld_mod_init);
Com_e_driver.c (meta-facebook\meta-wedge100\recipes-kernel\com-e-mod\files):module_init(com_e_mod_init);
Fancpld.c (meta-facebook\meta-cmm\recipes-kernel\cpld-mod\files):module_init(fancpld_mod_init);
Fancpld.c (meta-facebook\meta-wedge100\recipes-kernel\cpld-mod\files):module_init(fancpld_mod_init);
Fb_panther_plus.c (meta-facebook\meta-wedge\recipes-kernel\fb-panther-mod\files):module_init(sensors_panther_plus_init);
Galaxy100_ec.c (meta-facebook\meta-galaxy100\recipes-kernel\i2c-mode\files):module_init(ec_mod_init);
Ir358x.c (meta-facebook\meta-galaxy100\recipes-kernel\i2c-mode\files):module_init(ir358x_mod_init);
Pwr1014a.c (meta-facebook\meta-galaxy100\recipes-kernel\i2c-mode\files):module_init(pwr1014a_mod_init);
Scmcpld.c (meta-facebook\meta-galaxy100\recipes-kernel\cpld-mod\files):module_init(scmcpld_mod_init);
Syscpld.c (meta-facebook\meta-galaxy100\recipes-kernel\cpld-mod\files):module_init(syscpld_mod_init);
Syscpld.c (meta-facebook\meta-wedge100\recipes-kernel\cpld-mod\files):module_init(syscpld_mod_init);

每个文件对应某个单板的一个设备驱动,每个设备驱动定义一个i2c_dev_attr_st数组,支持用户态通过文件方式进行读写访问。

 

2、lib_ipmb_handle

1)int pal_read_cpu_temp(uint8_t snr_num, float *value)

req->cmd = CMD_NM_SEND_RAW_PECI;

lib_ipmb_handle(bus_id, tbuf, tlen+1, rbuf1, &rlen);

 

2) bic_set_gpio(uint8_t slot_id, uint8_t gpio, uint8_t value)

bic_ipmb_wrapper(slot_id, NETFN_OEM_1S_REQ, CMD_OEM_1S_SET_GPIO, tbuf, 11, rbuf, &rlen)

get_ipmb_bus_id(slot_id)

lib_ipmb_handle(bus_id, tbuf, tlen, &rbuf, &rlen)

// copy the received data back to caller
*rxlen = rlen - IPMB_HDR_SIZE - IPMI_RESP_HDR_SIZE;
memcpy(rxbuf, res->data, *rxlen);

 

3) void lib_ipmb_handle(unsigned char bus_id,

unsigned char *request, unsigned char req_len,
unsigned char *response, unsigned char *res_len) 

sprintf(sock_path, "%s_%d", SOCK_PATH_IPMB, bus_id);  //#define SOCK_PATH_IPMB "/tmp/ipmb_socket"

s = socket(AF_UNIX, SOCK_STREAM, 0)

connect(s, (struct sockaddr *)&remote, len)

send(s, request, req_len, 0)

recv(s, response, MAX_IPMB_RES_LEN, 0)

 

以上是关于openBMC source code的主要内容,如果未能解决你的问题,请参考以下文章

Sublime Text自定制代码片段(Code Snippets)

sublime text 3 添加代码片段

vs code 自定义代码片段

VS Code配置markdown代码片段

VS Code配置markdown代码片段

vs code 用户代码片段 html.json